[英]How to set default values to fields in Odoo 14
I added a filed company(It's a char field), when creating a payment,I want to set default value.我添加了一个归档公司(这是一个字符字段),在创建付款时,我想设置默认值。 When creating new payment, the value wasn't displayed in the form view.
创建新付款时,该值未显示在表单视图中。 But, when printing 'my_company', I got the correct result.
但是,在打印“my_company”时,我得到了正确的结果。 What's wrong please?
请问怎么了?
class AccountPayment(models.Model):
_inherit = "account.payment"
@api.model
def get_company(self):
if self.move_type == 'in_invoice':
my_company = self.env.user.company_id.name
self.company = my_company
else:
self.company = ''
company = fields.Char(string='Company ', default=get_company)
Thanks.谢谢。
You need to return the value.您需要返回该值。 Here is the correct code
这是正确的代码
class AccountPayment(models.Model):
_inherit = "account.payment"
def get_company(self):
if self.move_type == 'in_invoice':
my_company = self.env.user.company_id.name
return my_company
else:
return None
company = fields.Char(string='Company Name', default=get_company)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.