This question has been flagged
3 Replies
11014 Views

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 :



Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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

Best Answer

Hi,

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

Avatar
Discard