diff --git a/contract_show_invoice/README.rst b/contract_show_invoice/README.rst index 7f9dc808..262321f2 100644 --- a/contract_show_invoice/README.rst +++ b/contract_show_invoice/README.rst @@ -20,11 +20,6 @@ For further information, please visit: * https://www.odoo.com/forum/help-1 -Known issues / Roadmap -====================== - -* Add field with the total amount invoiced to the invoices button. - Bug Tracker =========== @@ -42,6 +37,7 @@ Contributors * Ángel Moya * Carlos Dauden * Dave Burkholder +* Alberto Martín - Guadaltech Maintainer diff --git a/contract_show_invoice/models/__init__.py b/contract_show_invoice/models/__init__.py index 78d96a03..df222af3 100644 --- a/contract_show_invoice/models/__init__.py +++ b/contract_show_invoice/models/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- from . import invoice +from . import account_analytic_account diff --git a/contract_show_invoice/models/account_analytic_account.py b/contract_show_invoice/models/account_analytic_account.py new file mode 100644 index 00000000..2ec2bad6 --- /dev/null +++ b/contract_show_invoice/models/account_analytic_account.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2018 Alberto Martín Cortada - Guadaltech +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountAnalyticAccount(models.Model): + _inherit = 'account.analytic.account' + + @api.multi + def _compute_total_invoiced(self): + invoice_model = self.env['account.invoice'] + for analytic in self: + fetch_data = invoice_model.read_group( + [('invoice_line_ids.account_analytic_id', '=', analytic.id)], + ['amount_total'], [], + ) + analytic.total_invoiced = fetch_data[0]['amount_total'] + + total_invoiced = fields.Float(string="Total Invoiced", + compute='_compute_total_invoiced') diff --git a/contract_show_invoice/test/test_contract_show_invoice.py b/contract_show_invoice/test/test_contract_show_invoice.py index 86921539..d46295a5 100644 --- a/contract_show_invoice/test/test_contract_show_invoice.py +++ b/contract_show_invoice/test/test_contract_show_invoice.py @@ -26,3 +26,7 @@ class TestContractShowInvoice(TransactionCase): def test_contract_show_invoice(self): self.assertEqual(len(self.analytic_account.analytic_account_ids), 1) + + def test_contract_total_invoiced(self): + self.assertEqual(self.invoice.amount_total, + self.analytic_account.total_invoiced) diff --git a/contract_show_invoice/views/contract_view.xml b/contract_show_invoice/views/contract_view.xml index c20391ee..590e068e 100644 --- a/contract_show_invoice/views/contract_view.xml +++ b/contract_show_invoice/views/contract_view.xml @@ -32,8 +32,15 @@