diff --git a/contract_invoice_merge_by_partner/README.rst b/contract_invoice_merge_by_partner/README.rst index cc4465d2..8df01a9b 100644 --- a/contract_invoice_merge_by_partner/README.rst +++ b/contract_invoice_merge_by_partner/README.rst @@ -22,6 +22,8 @@ Usage activate checkbox " Merge contracts invoices " #. Go to *Sales > Contracts* and create some contracts with same partner you activated checkbox " Merge contracts invoices " +#. Click on **Generate recurring invoices automatically** checkbox and add a + product to invoice line. #. Go to *Settings > Automation > Scheduled Actions* #. Select *Generate Recurring Invoices from Contracts* #. Set previous time that now in *Next Execution Date* @@ -29,7 +31,7 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/95/8.0 + :target: https://runbot.odoo-community.org/runbot/95/9.0 Bug Tracker @@ -48,13 +50,14 @@ Contributors * Carlos Dauden * Pedro M. Baeza * Rafael Blasco +* Vicent Cubells Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. @@ -62,4 +65,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/contract_invoice_merge_by_partner/__init__.py b/contract_invoice_merge_by_partner/__init__.py index cfa84f54..1f89f45f 100644 --- a/contract_invoice_merge_by_partner/__init__.py +++ b/contract_invoice_merge_by_partner/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden +# Copyright 2016 Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/contract_invoice_merge_by_partner/__openerp__.py b/contract_invoice_merge_by_partner/__openerp__.py index 7ac7a2cd..1459bdcb 100644 --- a/contract_invoice_merge_by_partner/__openerp__.py +++ b/contract_invoice_merge_by_partner/__openerp__.py @@ -1,18 +1,22 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden +# Copyright 2016 Carlos Dauden +# Copyright 2017 Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Contract Invoice Merge By Partner', 'summary': 'This module merges same partner invoices generated by ' 'contracts', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Account', 'license': 'AGPL-3', 'author': "Tecnativa, " "Odoo Community Association (OCA)", 'website': 'http://www.tecnativa.com', - 'depends': ['account_analytic_analysis', 'account_invoice_merge'], + 'depends': [ + 'contract', + 'account_invoice_merge', + ], 'data': [ 'views/res_partner_view.xml', ], diff --git a/contract_invoice_merge_by_partner/models/__init__.py b/contract_invoice_merge_by_partner/models/__init__.py index 17b40b5b..d70f386e 100644 --- a/contract_invoice_merge_by_partner/models/__init__.py +++ b/contract_invoice_merge_by_partner/models/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden +# Copyright 2016 Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import account_analytic_analysis diff --git a/contract_invoice_merge_by_partner/models/account_analytic_analysis.py b/contract_invoice_merge_by_partner/models/account_analytic_analysis.py index 0fcb6dfb..4b29a9cc 100644 --- a/contract_invoice_merge_by_partner/models/account_analytic_analysis.py +++ b/contract_invoice_merge_by_partner/models/account_analytic_analysis.py @@ -1,29 +1,34 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden -# © 2016 Pedro M. Baeza +# Copyright 2016 Carlos Dauden +# Copyright 2016 Pedro M. Baeza +# Copyright 2017 Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import api, models +from openerp import api, fields, models class AccountAnalyticAccount(models.Model): _inherit = 'account.analytic.account' @api.multi - def _recurring_create_invoice(self, automatic=False): - invoice_ids = super( - AccountAnalyticAccount, self)._recurring_create_invoice(automatic) - invoices = self.env['account.invoice'].browse(invoice_ids) - res = [] + def recurring_create_invoice(self): + contracts = self.search( + [('recurring_next_date', '<=', fields.Date.today()), + ('account_type', '=', 'normal'), + ('recurring_invoices', '=', True)] + ) + res = super(AccountAnalyticAccount, self).recurring_create_invoice() + if not contracts: + return res + invoices = self.env['account.invoice'].search([ + ('contract_id', 'in', contracts.ids) + ]) invoices2unlink = self.env['account.invoice'] for partner in invoices.mapped('partner_id'): invoices2merge = invoices.filtered( lambda x: x.partner_id == partner) if partner.contract_invoice_merge and len(invoices2merge) > 1: - result = invoices2merge.do_merge() - res += result.keys() + invoices2merge.do_merge() invoices2unlink += invoices2merge - else: - res += invoices2merge.ids invoices2unlink.unlink() - return res + return True diff --git a/contract_invoice_merge_by_partner/models/res_partner.py b/contract_invoice_merge_by_partner/models/res_partner.py index 2f50523f..a17d6582 100644 --- a/contract_invoice_merge_by_partner/models/res_partner.py +++ b/contract_invoice_merge_by_partner/models/res_partner.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden -# © 2016 Pedro M. Baeza +# Copyright 2016 Carlos Dauden +# Copyright 2016 Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import fields, models diff --git a/contract_invoice_merge_by_partner/tests/__init__.py b/contract_invoice_merge_by_partner/tests/__init__.py index 181cf9bd..a0b714e4 100644 --- a/contract_invoice_merge_by_partner/tests/__init__.py +++ b/contract_invoice_merge_by_partner/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden +# Copyright 2016 Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import test_contract_invoice_merge_by_partner diff --git a/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py b/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py index b45150d6..d5c03925 100644 --- a/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py +++ b/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py @@ -1,25 +1,39 @@ # -*- coding: utf-8 -*- -# © 2016 Carlos Dauden +# Copyright 2016 Carlos Dauden +# Copyright 2017 Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.tests.common import TransactionCase +from openerp.tests import common -class TestContractInvoiceMergeByPartner(TransactionCase): +class TestContractInvoiceMergeByPartner(common.SavepointCase): """ Use case : Prepare some data for current test case """ - def setUp(self): - super(TestContractInvoiceMergeByPartner, self).setUp() - self.partner = self.env['res.partner'].create({ + @classmethod + def setUpClass(cls): + super(TestContractInvoiceMergeByPartner, cls).setUpClass() + cls.partner = cls.env['res.partner'].create({ 'customer': True, 'name': "Test Customer", 'contract_invoice_merge': True, }) - self.product = self.env.ref('product.product_product_consultant') - self.uom = self.env.ref('product.product_uom_hour') - self.contract1 = self.env['account.analytic.account'].create({ + cls.uom = cls.env.ref('product.product_uom_hour') + cls.product = cls.env['product.product'].create({ + 'name': 'Custom Service', + 'type': 'service', + 'uom_id': cls.uom.id, + 'uom_po_id': cls.uom.id, + 'sale_ok': True, + }) + cls.contract1 = cls.env['account.analytic.account'].create({ 'name': 'Test contract', - 'partner_id': self.partner.id, - 'type': 'contract', + 'partner_id': cls.partner.id, + 'recurring_invoices': False, + }) + + def test_invoices_merged(self): + res = self.env['account.analytic.account'].recurring_create_invoice() + self.assertEqual(res, True) + self.contract1.write({ 'recurring_invoices': True, 'recurring_rule_type': 'monthly', 'recurring_interval': 1, @@ -33,9 +47,10 @@ class TestContractInvoiceMergeByPartner(TransactionCase): self.contract2 = self.contract1.copy() self.contract3 = self.contract1.copy() self.contract4 = self.contract1.copy() - - def test_invoices_merged(self): - self.env['account.analytic.account']._recurring_create_invoice() + contracts = self.env['account.analytic.account'].search([ + ('partner_id', '=', self.partner.id) + ]) + contracts.recurring_create_invoice() invoices = self.env['account.invoice'].search( [('partner_id', '=', self.partner.id)]) inv_draft = invoices.filtered(lambda x: x.state == 'draft') diff --git a/contract_invoice_merge_by_partner/views/res_partner_view.xml b/contract_invoice_merge_by_partner/views/res_partner_view.xml index bc0540db..38567072 100644 --- a/contract_invoice_merge_by_partner/views/res_partner_view.xml +++ b/contract_invoice_merge_by_partner/views/res_partner_view.xml @@ -1,19 +1,18 @@ - - - + - - Partner Form Contract Invoice Merge - res.partner - - - - + + Partner Form Contract Invoice Merge + res.partner + + + + + - - - + diff --git a/oca_dependencies.txt b/oca_dependencies.txt index ac0117d1..88ba1100 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -13,3 +13,5 @@ # # To provide both the URL and a branch, use: # sale-workflow https://github.com/OCA/sale-workflow branchname + +account-invoicing