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

Here is two functions which are write and create. The write method is working fine. but create method is not triggering.

Can anybody help on this??

#v13.0

class AssetAllocation(models.Model):
_name = 'asset.allocation'

def create(self, values):
for rec in self.asset_id:
if self.state == 'active':
rec.current_employee = self.name
rec.current_branch = self.branch
else:
rec.current_employee = False
rec.current_branch = False
res = super(AssetAllocation, self).create(values)
return res

def write(self, vals):
res = super(AssetAllocation, self).write(vals)
for rec in self.asset_id:
if self.state == 'active':
rec.current_employee = self.name
rec.current_branch = self.branch
else:
rec.current_employee = False
rec.current_branch = False
return res


อวตาร
ละทิ้ง

i have same issue, i think its you already have been create method, i think create method just can call once

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

Hi,

Please try this.

@api.model
def create(self, values):
res = super(AssetAllocation, self).create(values)
for record in res:
for asset in record.asset_id:
if record.state == 'active':
asset.current_employee = record.name
asset.current_branch = record.branch
else:
asset.current_employee = False
asset.current_branch = False
return res

Also please check whether you have define the create method for multiple times in the same py file or not. If yes, then you have to remove one of it.

Hope it will help you.

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

In the create function, you can only access values from values dict or after the record is created. So here either you need to compare the values from dict or access record after create.

def create(self, values):

res = super(AssetAllocation, self).create(values)
........
        code here, access values from res
        ........
return res
อวตาร
ละทิ้ง
ผู้เขียน

Dear Hilar,

I tried that also already. Not working..

Correct your logic. Make sure u a loop, super object will be the record going to update in db. Try to access values from the same.

Related Posts ตอบกลับ มุมมอง กิจกรรม
ODOO COMMUNITY V13 - BARCODE แก้ไขแล้ว
1
ส.ค. 24
14554
Elearning app not displaying PDF files แก้ไขแล้ว
4
ก.ย. 21
7140
2
ธ.ค. 20
6044
1
ก.ค. 20
3278
2
ก.ค. 20
4674