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

Hello guys. Thanks a lot for your help. I'm new at Odoo and I need your support :)

There's a better way to code this?


class AccountMove(models.Model):
_inherit = 'account.move'


business_unit_id = fields.Many2one('business.unit', compute='get_sale_order', string='Business Unit')
order_type_id = fields.Many2one('order.type', compute='get_sale_order')
client_order_ref = fields.Char(compute='get_sale_order', readonly=True)

@api.depends('invoice_origin')
def get_sale_order(self):
for move in self:
sale_order = self.env['sale.order'].search([
('name', '=', move.invoice_origin)
])

move.client_order_ref = sale_order.client_order_ref
move.business_unit_id = sale_order.business_unit_id.id

As you can see, there are 3 computes. Theres is a better way to write this code?

Thanks in advance :)




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

You should not do that, the "invoice_origin" is a Char that can have multiple SO names.
sale.order < - > account.move is a many2many relation, for example:
From 5 sales you can generate only one invoice, and from 1 sale you can generate 5 invoices

In my opinion you should override the "_prepare_invoice" from sale.order and "_prepare_invoice_values" from sale.advance.payment.inv

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

In other option, You can use onchange of 'invoice_origin' and set value of all three fields but without compute it will not be read only. So, you have to set readonly for those fields if you want.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 23
2505
0
thg 11 18
2897
1
thg 1 17
5112
1
thg 9 22
2748
1
thg 12 19
7973