Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
13542 Näkymät

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
Hylkää
Paras vastaus

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

Avatar
Hylkää
Tekijä

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

Paras vastaus

Hi,

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

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
jouluk. 19
6611
0
jouluk. 23
1735
1
heinäk. 22
2674
1
huhtik. 24
1755
1
jouluk. 21
6475