diff --git a/contract_show_invoice/README.rst b/contract_show_invoice/README.rst index 9f1fc92e..bf10bd32 100644 --- a/contract_show_invoice/README.rst +++ b/contract_show_invoice/README.rst @@ -40,6 +40,7 @@ Contributors ------------ * Ángel Moya +* Carlos Dauden Maintainer diff --git a/contract_show_invoice/__openerp__.py b/contract_show_invoice/__openerp__.py index 22db7e3c..441e17cf 100644 --- a/contract_show_invoice/__openerp__.py +++ b/contract_show_invoice/__openerp__.py @@ -1,38 +1,20 @@ # -*- coding: utf-8 -*- +# © 2015 Angel Moya +# © 2016 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -############################################################################### -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2015 Domatix (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### { 'name': 'Contract Show Invoice', 'summary': 'Button in contracts to show their invoices', - 'version': '8.0.1.0.0', - 'author': 'Domatix, Odoo Community Association (OCA)', + 'version': '9.0.1.0.0', + 'author': 'Domatix,' + 'Tecnativa,' + 'Odoo Community Association (OCA)', 'website': 'http://www.domatix.com', - 'depends': ['account_analytic_analysis'], + 'depends': ['account', 'analytic'], 'category': 'Sales Management', 'data': [ 'views/contract_view.xml', ], - 'test': [ - 'test/contract_show_invoice_test.yml' - ], - 'installable': False, - 'auto_install': False, + 'installable': True, } diff --git a/contract_show_invoice/i18n/contract_invoices_button.pot b/contract_show_invoice/i18n/contract_invoices_button.pot deleted file mode 100644 index 6341c066..00000000 --- a/contract_show_invoice/i18n/contract_invoices_button.pot +++ /dev/null @@ -1,38 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * contract_show_invoice -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-10-01 07:58+0000\n" -"PO-Revision-Date: 2015-10-01 07:58+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: contract_show_invoice -#: field:account.invoice,analytic_account_ids:0 -msgid "Contracts" -msgstr "" - -#. module: contract_show_invoice -#: model:ir.model,name:contract_show_invoice.model_account_invoice -msgid "Invoice" -msgstr "" - -#. module: contract_show_invoice -#: view:account.analytic.account:contract_show_invoice.account_analytic_account_button_invoice -#: model:ir.actions.act_window,name:contract_show_invoice.act_analytic_invoices -msgid "Invoices" -msgstr "" - -#. module: contract_show_invoice -#: view:account.analytic.account:contract_show_invoice.account_analytic_account_button_invoice -msgid "Invoices related with this contract" -msgstr "" - diff --git a/contract_show_invoice/models/invoice.py b/contract_show_invoice/models/invoice.py index e3d3efb0..43eea3e9 100644 --- a/contract_show_invoice/models/invoice.py +++ b/contract_show_invoice/models/invoice.py @@ -1,19 +1,24 @@ # -*- coding: utf-8 -*- +# © 2015 Angel Moya +# © 2016 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, fields, api +from openerp import api, fields, models class AccountInvoice(models.Model): _inherit = 'account.invoice' - @api.one - @api.depends('invoice_line.account_analytic_id') - def _analytic_account_ids(self): - self.analytic_account_ids = \ - self.mapped('invoice_line.account_analytic_id') - analytic_account_ids = fields.Many2many( comodel_name='account.analytic.account', - compute='_analytic_account_ids', + compute='_compute_analytic_account_ids', store=True, string='Contracts') + + @api.multi + @api.depends('invoice_line_ids.account_analytic_id') + def _compute_analytic_account_ids(self): + for invoice in self: + invoice.analytic_account_ids = invoice.mapped( + 'invoice_line_ids.account_analytic_id' + ) diff --git a/contract_show_invoice/test/__init__.py b/contract_show_invoice/test/__init__.py new file mode 100644 index 00000000..b2a43516 --- /dev/null +++ b/contract_show_invoice/test/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_contract_show_invoice diff --git a/contract_show_invoice/test/contract_show_invoice_test.yml b/contract_show_invoice/test/contract_show_invoice_test.yml deleted file mode 100644 index b0174271..00000000 --- a/contract_show_invoice/test/contract_show_invoice_test.yml +++ /dev/null @@ -1,35 +0,0 @@ -- - In order to test Contract Invoices Button I create a new Contract -- - !record {model: account.analytic.account, id: contract_main}: - name: Maintenance of Servers - company_id: base.main_company - partner_id: base.main_partner - type: contract - recurring_invoices : 1 - recurring_interval : 1 - recurring_invoice_line_ids: - - quantity: 2.0 - price_unit: 100.0 - name: Database Administration 25 - product_id: product.product_product_consultant - uom_id: product.product_uom_hour -- - I test the invoices button -- - !python {model: account.invoice}: | - contract_id = ref('contract_show_invoice.contract_main') - invoices = self.search(cr, uid,[('analytic_account_ids','=',contract_id)],context=context) - assert len(invoices) == 0, "No invoices related this contract, but get (%s)"%(invoices,) -- - I generate all invoices from contracts having recurring invoicing -- - !python {model: account.analytic.account}: | - self.recurring_create_invoice(cr, uid, []) -- - I test the invoices button -- - !python {model: account.invoice}: | - contract_id = ref('contract_show_invoice.contract_main') - invoices = self.search(cr, uid,[('analytic_account_ids','=',contract_id)],context=context) - assert len(invoices) == 1, "Must have one invoice related this contract, but get (%s)"%(invoices,) \ No newline at end of file diff --git a/contract_show_invoice/test/test_contract_show_invoice.py b/contract_show_invoice/test/test_contract_show_invoice.py new file mode 100644 index 00000000..6bd8639a --- /dev/null +++ b/contract_show_invoice/test/test_contract_show_invoice.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# © 2016 Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp.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) diff --git a/contract_show_invoice/views/contract_view.xml b/contract_show_invoice/views/contract_view.xml index e89fa445..8069770a 100644 --- a/contract_show_invoice/views/contract_view.xml +++ b/contract_show_invoice/views/contract_view.xml @@ -18,7 +18,7 @@ account.analytic.account - +