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

I am trying to add an attribute that has several totals from other tables and that influences the type of account it is in. For example in an account called "Bank" I have totals 5, 10, 15 and the sum of all those totals is 30. To do this I have two tables that are "document_ detail" and "account". In the table "document_detail" I have the total_debt attribute which in this attribute the totals of other products are added and the account of where "bank" is added in this case is added.

I have used this method to add but it does not:

@ api.multi

  @ api.depends ("account_id")

  def _sum_of_credit (self):

    self.sum_total_credit = sum (line.total_credit for line in self) if self.account_id.title == "Cash" or self.account_id.title == "Bank" else 0

I attached an image to see what I want to reach:  \photoexample  https://ibb.co/1rZv0TV


Avatar
Discard
Best Answer

Hi!

Here is an example how to compute the total line, you can adapt it as you need :

class AccountMove(models.Model):
_inherit = "account.move"

sum_of_credit = fields.Float(compute='_compute_sum_of_credit', string='Total Credit')

@api.depends('move_line')
def _compute_sum_of_credit(self):
self.sum_of_credit = sum(line.credit for line in self.move_line_ids.filtered(lambda x: x.account_id.user_type_id.type in ['cash', 'bank']))

Best regards!

Avatar
Discard
Related Posts Replies Views Activity
3
Apr 24
1019
0
May 24
46
1
Apr 24
1826
4
Sep 23
3085
2
Sep 23
5592