Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
13524 มุมมอง

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 :



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
ผู้เขียน

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

คำตอบที่ดีที่สุด

Hi,

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 19
6604
0
ธ.ค. 23
1732
1
ก.ค. 22
2669
1
เม.ย. 24
1752
Why this computed field doest not work? แก้ไขแล้ว
1
ธ.ค. 21
6472