Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3517 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ago 25
3079
3
feb 25
4485
0
may 24
46
1
abr 24
3935
4
sept 23
5761