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

Hello all,

We have a new field customer_of_division_id in the picking model/form. It is computed each time the partner_id of the picking changes.

So I edit the picking, I change only the partner and automatically, I see the value changes in the customer_of_division_id field. See image below. Good.

If I edit the picking, that I change/force only the customer_of_division_id, it works well too. The new forced value for customer_of_division_id field is saved correctly.

If I edit the picking and I change the partner_id AND the customer_of_division_id, when I save, the customer_of_division_id is recomputed according to the partner_id. The forced value for customer_of_division_id is not saved... So I have to edit again and reforce the value of customer_of_division_id before to save. And then, it is well saved.


How could I edit a picking and change both values in the same time?


The code :

class Picking(models.Model):
    _inherit = "stock.picking"
    _order = "id desc"

    @api.depends('sale_id','partner_id')
    def _get_division_id(self):
        if self.sale_id:
             self.customer_of_division_id = self.sale_id.customer_of_division_id.id
        else: 
             if self.partner_id.parent_id:
                self.customer_of_division_id = self.partner_id.parent_id.customer_of_division_id.id
             else:
                self.customer_of_division_id = self.partner_id.customer_of_division_id.id

 
    customer_of_division_id = fields.Many2one(compute='_get_division_id', comodel_name='res.partner', string='Customer of the division', store=True)


The image :



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

If it is possible you replace api@depends('partner_id')  by api@onchange('partner_id')

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

It seems to work very well! It is like magic! Big thanks my dear!

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

Hi,

Also please try by removing partner_id from @api.depends and keep like this @api.depends('sale_id')

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 19
6620
0
thg 12 23
1741
1
thg 7 22
2679
1
thg 4 24
1767
1
thg 12 21
6482