Skip to Content
Menu
This question has been flagged
1 Reply
1369 Views

I have a method which makes me add up depending on the type of account, for example: I have the "effective" account where you have a computed field where you add everything you have and have made. Likewise, another account called "Bank" also adds the debit and credit. But I use the same method for both, however, I have them separated but I only add one and not both.  edit:  I realized that when creating another type of account the entire total is deleted and begins to add to the account that was reada lately, how can I solve that problem?

As shown in the image, only the sum appears in the "bank" account and not in the "cash" account Link image efective : \photo\ link\ efective\\.\\ Link\\ image\\ bank\\ \\:\\\photo view bank

class Account(models.Model):
      _name = 'project_rc.account'
      _rec_name = 'title'

      title = fields.Char(string="Name")
      total_account_debit = fields.Float(string="Total account must", compute="_ total_account_debit")
      total_account_credit = fields.Float(string="Total account have", compute="_ total_account_credit"

      @api.multi
      @api.depends("detail_document_ids")
      def _total_cuenta_debe(self):
         self.total_account_debit = sum(line.total_debe for line in self.detail_document_ids) if self.titulo == "Cash" else 0)

      @api.multi
      @api.depends("detail_document_ids")
      def _total_account_credit(self):
         self.total_account_credit = sum(line.total_credit for line in self.detail_document_ids) if self.title == "Cash" else 0)

      @api.multi
      @api.depends("detail_document_ids")
      def _total_account_debit(self):
         self.total_account_debit = sum(line.total_debe for line in self.detail_document_ids) if self.title == "Bank" else 0)

      @api.multi
      @api.depends("detail_document_ids")
      def _total_account_credit(self):
         self.total_account_credit = sum(line.total_credit for line in self.detail_document_ids) if self.title == "Bank" else 0)


Avatar
Discard
Best Answer
here 'total_account_debit` and `total_account_credit` are not stored compute field 
so it will always compute on reading so I think you have to change compute method `_total_account_debit`

@api.multi
def _total_account_debit(self)
for record in self:
if record.title == "Cash"
record.total_account_debit = sum(line.total_debe for line in record.detail_document_ids)
record.total_account_credit = sum(line.total_credit for line in record.detail_document_ids)
if record.title == "Bank"
record.total_account_debit = sum(line.total_debe for line in record.detail_document_ids)
record.total_account_credit = sum(line.total_credit for line in record.detail_document_ids)
Avatar
Discard
Related Posts Replies Views Activity
3
Apr 24
1024
0
May 24
46
1
Apr 24
1829
4
Sep 23
3085
2
Sep 23
5593