You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
961 B

  1. # -*- coding: utf-8 -*-
  2. # © 2018 Alberto Martín Cortada - Guadaltech <alberto.martin@guadaltech.es>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class AccountAnalyticAccount(models.Model):
  6. _inherit = 'account.analytic.account'
  7. @api.multi
  8. def _compute_total_invoiced(self):
  9. invoice_line_model = self.env['account.invoice.line']
  10. for analytic in self:
  11. fetch_data = invoice_line_model.read_group(
  12. [('account_analytic_id', '=', analytic.id),
  13. ('invoice_id.state', 'in', ['open', 'paid']),
  14. ('invoice_id.type', 'in', ['out_invoice', 'out_refund'])],
  15. ['price_subtotal_signed'], [],
  16. )
  17. analytic.total_invoiced = fetch_data[0]['price_subtotal_signed']
  18. total_invoiced = fields.Float(string="Total Invoiced",
  19. compute='_compute_total_invoiced')