Reputation: 611
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. 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.
Upvotes: 1
Views: 2351
Reputation: 159
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)
Upvotes: 1