Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2537 Lượt xem
@api.model
def create(self, vals):
********def****** res = super(ResPartner, self).create(vals)
I am trying to overwrite the create function in the inherited model, 
once I save it
 raise TypeError(f"unsupported operand types in: {self} + {arg!r}")
TypeError: unsupported operand types in: res.partner() + None
Can someone help me to resolve this please?



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thanks for your reply, 

here is my  original code,  which is same as your but no result. Thank you

@api.model
def create(self, vals):
if self.customer_code:
rec_count = self.env['res.partner'].search_count([('customer_code', '=', self.customer_code)])
if rec_count > 0:
raise ValidationError(_("Customer code already exists"))
super(ResPartner, self).create(vals)



Ảnh đại diện
Huỷ bỏ

Try like this
if vals['customer_code']:
rec_count = self.env['res.partner'].search_count([('customer_code', '=', vals['customer_code'])])

Câu trả lời hay nhất

Hi 

Try this code 

@api.model
def create(self, vals):
if vals.get('code'):
vals['code'] = vals['code'].upper()
return super(ResPartner, self).create(vals)

where code is a field in your model res.partner

https://youtu.be/ZRx3Ll8L7Mo


Hope this Helps

Regards

Ảnh đại diện
Huỷ bỏ