From 71b886866f3bb43819608e53e33a67c16f8767ad Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Fri, 5 Apr 2019 17:54:00 +0200 Subject: [PATCH 1/4] [IMP] add sequence in search default journal --- contract/models/account_analytic_contract.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contract/models/account_analytic_contract.py b/contract/models/account_analytic_contract.py index 6f04a9e5..3a1f9060 100644 --- a/contract/models/account_analytic_contract.py +++ b/contract/models/account_analytic_contract.py @@ -80,4 +80,5 @@ class AccountAnalyticContract(models.Model): domain = [ ('type', '=', 'sale'), ('company_id', '=', company_id)] - return self.env['account.journal'].search(domain, limit=1) + return self.env['account.journal'].search( + domain, order='sequence asc', limit=1) From e1cfee911e3140c1f6c01985418fcb7bbb324863 Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Fri, 19 Apr 2019 11:19:35 +0200 Subject: [PATCH 2/4] [IMP] get account journal default by sequence --- contract/__manifest__.py | 2 +- contract/models/account_analytic_contract.py | 3 ++- contract_show_invoice/__manifest__.py | 2 +- .../models/account_analytic_account.py | 12 +++++++----- contract_show_invoice/views/contract_view.xml | 13 ++++++++++++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/contract/__manifest__.py b/contract/__manifest__.py index 70ff7890..ff9e4260 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -9,7 +9,7 @@ { 'name': 'Contracts Management - Recurring', - 'version': '10.0.4.3.0', + 'version': '10.0.4.3.2', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA, " diff --git a/contract/models/account_analytic_contract.py b/contract/models/account_analytic_contract.py index 6f04a9e5..3a1f9060 100644 --- a/contract/models/account_analytic_contract.py +++ b/contract/models/account_analytic_contract.py @@ -80,4 +80,5 @@ class AccountAnalyticContract(models.Model): domain = [ ('type', '=', 'sale'), ('company_id', '=', company_id)] - return self.env['account.journal'].search(domain, limit=1) + return self.env['account.journal'].search( + domain, order='sequence asc', limit=1) diff --git a/contract_show_invoice/__manifest__.py b/contract_show_invoice/__manifest__.py index e83890a0..77322f00 100644 --- a/contract_show_invoice/__manifest__.py +++ b/contract_show_invoice/__manifest__.py @@ -6,7 +6,7 @@ { 'name': 'Contract Show Invoice', 'summary': 'Button in contracts to show their invoices', - 'version': '10.0.1.0.1', + 'version': '10.0.1.0.2', 'license': 'AGPL-3', 'author': 'Domatix,' 'Tecnativa,' diff --git a/contract_show_invoice/models/account_analytic_account.py b/contract_show_invoice/models/account_analytic_account.py index 2ec2bad6..699e61e0 100644 --- a/contract_show_invoice/models/account_analytic_account.py +++ b/contract_show_invoice/models/account_analytic_account.py @@ -10,13 +10,15 @@ class AccountAnalyticAccount(models.Model): @api.multi def _compute_total_invoiced(self): - invoice_model = self.env['account.invoice'] + invoice_line_model = self.env['account.invoice.line'] for analytic in self: - fetch_data = invoice_model.read_group( - [('invoice_line_ids.account_analytic_id', '=', analytic.id)], - ['amount_total'], [], + fetch_data = invoice_line_model.read_group( + [('account_analytic_id', '=', analytic.id), + ('invoice_id.state', 'in', ['open', 'paid']), + ('invoice_id.type', 'in', ['out_invoice', 'out_refund'])], + ['price_subtotal_signed'], [], ) - analytic.total_invoiced = fetch_data[0]['amount_total'] + analytic.total_invoiced = fetch_data[0]['price_subtotal_signed'] total_invoiced = fields.Float(string="Total Invoiced", compute='_compute_total_invoiced') diff --git a/contract_show_invoice/views/contract_view.xml b/contract_show_invoice/views/contract_view.xml index 590e068e..5f26972d 100644 --- a/contract_show_invoice/views/contract_view.xml +++ b/contract_show_invoice/views/contract_view.xml @@ -6,7 +6,7 @@ [active_id], 'default_analytic_account_ids': [active_id]} Invoices account.invoice - [('analytic_account_ids','=',active_id)] + [('analytic_account_ids','=',active_id), ('type','in', ['out_invoice', 'out_refund']), ('state', 'not in', ['draft', 'cancel'])] @@ -24,6 +24,17 @@ + + account.invoice.tree.show.total.untaxed + account.invoice + + + + + + + + account.analytic.account.button.invoice From 7006eb0b92919d27d5ad86c6c88d5533a9157f35 Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Tue, 13 Aug 2019 15:18:23 +0200 Subject: [PATCH 3/4] [FIX] remove bump version --- contract/__manifest__.py | 2 +- contract_show_invoice/__manifest__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contract/__manifest__.py b/contract/__manifest__.py index ff9e4260..70ff7890 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -9,7 +9,7 @@ { 'name': 'Contracts Management - Recurring', - 'version': '10.0.4.3.2', + 'version': '10.0.4.3.0', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA, " diff --git a/contract_show_invoice/__manifest__.py b/contract_show_invoice/__manifest__.py index 77322f00..e83890a0 100644 --- a/contract_show_invoice/__manifest__.py +++ b/contract_show_invoice/__manifest__.py @@ -6,7 +6,7 @@ { 'name': 'Contract Show Invoice', 'summary': 'Button in contracts to show their invoices', - 'version': '10.0.1.0.2', + 'version': '10.0.1.0.1', 'license': 'AGPL-3', 'author': 'Domatix,' 'Tecnativa,' From 02d165a08240178451688d95f8b0851e4fd4e47a Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Wed, 14 Aug 2019 12:45:53 +0200 Subject: [PATCH 4/4] [10.0][FIX] tests not working [FIX] test [IMP] test [FIX] pep8 --- .../test/test_contract_show_invoice.py | 32 --------- .../{test => tests}/__init__.py | 0 .../tests/test_contract_show_invoice.py | 68 +++++++++++++++++++ 3 files changed, 68 insertions(+), 32 deletions(-) delete mode 100644 contract_show_invoice/test/test_contract_show_invoice.py rename contract_show_invoice/{test => tests}/__init__.py (100%) create mode 100644 contract_show_invoice/tests/test_contract_show_invoice.py diff --git a/contract_show_invoice/test/test_contract_show_invoice.py b/contract_show_invoice/test/test_contract_show_invoice.py deleted file mode 100644 index d46295a5..00000000 --- a/contract_show_invoice/test/test_contract_show_invoice.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Carlos Dauden -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html - -from odoo.tests.common import TransactionCase - - -class TestContractShowInvoice(TransactionCase): - def setUp(self): - super(TestContractShowInvoice, self).setUp() - self.analytic_account = self.env['account.analytic.account'].create({ - 'name': 'Test contract show invoice', - }) - self.invoice = self.env['account.invoice'].create( - {'partner_id': self.env.ref('base.res_partner_2').id, - 'type': 'out_invoice', - }) - self.invoice._onchange_partner_id() - self.invoice_line = self.env['account.invoice.line'].create( - {'product_id': self.env.ref('product.product_product_2').id, - 'quantity': 1.0, - 'invoice_id': self.invoice.id, - 'account_analytic_id': self.analytic_account.id, - }) - self.invoice_line._onchange_product_id() - - 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/test/__init__.py b/contract_show_invoice/tests/__init__.py similarity index 100% rename from contract_show_invoice/test/__init__.py rename to contract_show_invoice/tests/__init__.py diff --git a/contract_show_invoice/tests/test_contract_show_invoice.py b/contract_show_invoice/tests/test_contract_show_invoice.py new file mode 100644 index 00000000..e2519b60 --- /dev/null +++ b/contract_show_invoice/tests/test_contract_show_invoice.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# © 2016 Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo.tests.common import TransactionCase + + +class TestContractShowInvoice(TransactionCase): + def setUp(self): + super(TestContractShowInvoice, self).setUp() + self.analytic_account = self.env['account.analytic.account'].create({ + 'name': 'Test contract show invoice', + }) + self.invoice = self.env['account.invoice'].create( + {'partner_id': self.env.ref('base.res_partner_2').id, + 'type': 'out_invoice', + }) + self.invoice.journal_id.update_posted = True + self.invoice._onchange_partner_id() + self.a_sale = self.env['account.account'].search([ + ('user_type_id', '=', + self.env.ref('account.data_account_type_revenue').id) + ], limit=1) + self.invoice_line = self.env['account.invoice.line'].create( + {'product_id': self.env.ref('product.product_product_2').id, + 'quantity': 1.0, + 'invoice_id': self.invoice.id, + 'account_analytic_id': self.analytic_account.id, + 'account_id': self.a_sale.id, + 'price_unit': 50.0, + 'name': 'Invoice line with analytic account', + 'invoice_line_tax_ids': [(4, self.env['account.tax'].search( + [('type_tax_use', '=', 'sale')], limit=1).id, 0)] + }) + self.invoice.compute_taxes() + self.invoice.action_invoice_open() + + def test_invoice_two_line(self): + self.assertEqual( + self.analytic_account.total_invoiced, + self.invoice_line.price_subtotal, + msg="Amount invoiced is different from single invoice line wich " + "has analytic account") + self.invoice.action_invoice_cancel() + self.invoice.action_invoice_draft() + self.invoice_line1 = self.env['account.invoice.line'].create( + {'product_id': self.env.ref('product.product_product_2').id, + 'quantity': 2.0, + 'invoice_id': self.invoice.id, + 'account_analytic_id': False, + 'account_id': self.a_sale.id, + 'price_unit': 100.0, + 'name': 'Invoice line without analytic account', + 'invoice_line_tax_ids': [(4, self.env['account.tax'].search( + [('type_tax_use', '=', 'sale')], limit=1).id, 0)] + }) + self.invoice.compute_taxes() + self.invoice.action_invoice_open() + self.assertFalse(self.invoice_line1.account_analytic_id, + msg="Invoice line has analytic account") + self.assertEqual(len(self.invoice.analytic_account_ids), 1, + msg="Invoice lines with analytic account are more " + "than one") + self.assertEqual( + self.analytic_account.total_invoiced, + self.invoice_line.price_subtotal, + msg="Amount invoiced is different from invoice lines wich " + "has analytic account")