Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2292 Lượt xem

Hi,


In Odoo online, how can I set the purchase order lines to default to the analytic account in purchase order header (custom field already created)? I have tried to set the context on the order lines in the form view but it is not working. Thanks!

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Hi,

Thanks for response. Is it possible to do it in Odoo online, e.g. via automated action which triggers on UI change?

Ảnh đại diện
Huỷ bỏ

I am not sure about that. We encountered a similar requirement and developed a custom module, which we then deployed to Odoo.sh

Câu trả lời hay nhất
Model

# -*- coding: utf-8 -*-

from odoo import api, fields, models, _

class PurchaseOrderAnalyticAccount(models.Model):
    _name = 'purchase.order'
    _inherit = ['purchase.order','analytic.mixin']


class PurchaseOrderLineAnalyticAccount(models.Model):
    _inherit = 'purchase.order.line'
   
   
    @api.depends('product_id', 'order_id.partner_id','order_id.picking_type_id.warehouse_id','order_id.analytic_distribution')
    def _compute_analytic_distribution(self):
        res = super(PurchaseOrderLineAnalyticAccount, self)._compute_analytic_distribution()
        for line in self:
            distribution = False
            if not line.display_type:
                if line.order_id.analytic_distribution:
                    distribution = line.order_id.analytic_distribution
                line.analytic_distribution = distribution or line.analytic_distribution
        return res

View


Output




Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 22
5716
1
thg 3 15
4840
0
thg 3 15
4403
0
thg 5 25
932
1
thg 4 25
984