I am carrying out a method which has to be added only when it is in the "Cash" account, but when performing in the way below it does not work for me. Anyone know how to add a conditional and add it.
class Account (models.Model):
_name = 'project_rc.account'
name = fields.Char (string = "Name")
total_account_must = fields.Float (string = "Total account must", compute = "_total_account_must")
total_account_credit = fields.Float (string = "Total account credit", compute = "_total_account_credit")
detail_document_ids = fields.One2many (comodel_name = 'project_rc.detail_document', inverse_name = 'account_id', string = 'Document detail',required = True)
@ api.one
@ api.depends (detail_document_ids)
def _total_account_must(self):
sum = 0
if self.title == "Cash":
for detail_document in self.detail_document_ids:
sum + = detail_document.total_must
self.total_account_must = sum
class Document_Detail (models.Model):
_name = 'project_rc.detail_document'
total_must = fields.Float (string = "Input value")
total_credit = fields.Float (string = "Output value")
account_id = fields.Many2one (comodel_name = 'project_rc.account', string = 'Account')
But i bit confused in this field called document_document_ids You have used detail_document_ids in Compute.
Try to give as
@ api.one
@ api.depends (detail_document_ids.total_must)
def _total_account_must(self):
self.total_account_must = sum(line.total_must for line in self.detail_document_ids) if self.title == "Cash" else 0