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

When I try to override my res.partner write method it executes multiple time 

How can I make sure it just does once or that I can only increment my field after it runs 

 @api.multi

    def write(self, vals):

        next_custnum = self.getnextcustno()

        vals['cust_no'] = next_custnum

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

        print("Execute Write")

        print("Execute Write after")

        self.addNextCustNo()

        return res

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

Write and create both executes 2x on inheritance of red.partner ? How come ? Want to add changed items to a custom model but insert twice .. please help ?

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

This is normal that write method calling multiple times.

You should add a condition in your code so that it does not execute each time.

Try the following code:

if not vals.get('cust_no'):
vals['cust_no'] = self.getnextcustno()


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

Thanks!

Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ก.พ. 25
3369
1
ส.ค. 24
2534
2
พ.ย. 24
3815
3
ต.ค. 23
15289
2
ก.พ. 23
2761