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

Hello,

Here is my problem

In sale.order view, i've added an onchange function on field partner.id to fill an other field (ie : field1)

If i create a new sale.order from general sale.order list and select a partner, my field1 is correctly filled. No problem here, the onchange function works well.


But if i create a new sale.order from the partner view, the partner is already selected in the sale.order view also the onchange function is not called and field1 is not filled.


What is the way to call the onchange function when opening the view?

Or maybe i need an other type of function!


Vincent

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

you can try to override the write function instead it will be run on create or any time you edit the record it will compute the field like:

def write(self, vals): 

if condition:

    vals['field1']=somevalue 

res = super(classname, self).write(vals)  

return res
or 

you can use an onchange compute method
like:
field1=fields.Integer(compute="get_value")

@api.onchange('partner_id')
def get_value(self):
field1=somevalue


Ảnh đại diện
Huỷ bỏ
Tác giả

I tried the second option but it seems not to work
I will explain my specific problem instead of a generic case
In sale order, fiscal position is linked with partner or shipping address.
But i need to link fiscal_position_id with partner_invoice_id
That's why i created a function with onchange on partner_invoice_id field to retrieve its fiscal position id. It works well except when i open sale order from partner view because partner_id, partner_shipping_id and partner_invoice_id are already selected

Hope it is clear enough otherwise tell me

Tác giả Câu trả lời hay nhất

Thank you for this answer.

I thinked about it but the problem is that the field stay empty until i click on save button

I prefer that the field is filled  before, otherwise user will think that something is wrong.


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

i edited it as what you mentioned here