跳至內容
選單
此問題已被標幟
1 回覆
3536 瀏覽次數

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


頭像
捨棄
最佳答案

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!

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
8月 25
3203
3
2月 25
4599
0
5月 24
46
1
4月 24
4041
4
9月 23
5905