diff --git a/contract_sale_invoicing/README.rst b/contract_sale_invoicing/README.rst new file mode 100644 index 00000000..ea7021dd --- /dev/null +++ b/contract_sale_invoicing/README.rst @@ -0,0 +1,69 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +========================================== +Contract Invoicing of Pending Sales Orders +========================================== + +This modules allows to include on the same invoice than the recurring invoice +contract, all the pending to invoice sales orders that you have with the same +analytic account. + +Usage +===== + +To use this module, you need to: + +#. Go to Invoicing > Sales > Contracts and select or create a new contract. +#. Check *Generate recurring invoices automatically*. +#. Mark the check "Invoice Pending Sales Orders". +#. On each invoicing, system will check if there's any pending sales orders + with same analyitic account and will append the lines to the invoice being + generated. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/110/11.0 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* `Tecnativa `_: + + * Carlos Dauden + +Do not contact contributors directly about support or help with technical issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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 https://odoo-community.org. diff --git a/contract_sale_invoicing/__init__.py b/contract_sale_invoicing/__init__.py new file mode 100644 index 00000000..31660d6a --- /dev/null +++ b/contract_sale_invoicing/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/contract_sale_invoicing/__manifest__.py b/contract_sale_invoicing/__manifest__.py new file mode 100644 index 00000000..8d606c34 --- /dev/null +++ b/contract_sale_invoicing/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2018 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': 'Contract Invoicing of Pending Sales Orders', + 'summary': 'Include sales to invoice in contract invoice creation', + 'version': '11.0.1.0.0', + 'category': 'Contract Management', + 'website': 'https://github.com/oca/contract', + 'author': 'Tecnativa, ' + 'Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'installable': True, + 'depends': [ + 'contract', + 'sale_management', + ], + 'data': [ + 'views/contract_view.xml', + ], +} diff --git a/contract_sale_invoicing/i18n/es.po b/contract_sale_invoicing/i18n/es.po new file mode 100644 index 00000000..ad5d7744 --- /dev/null +++ b/contract_sale_invoicing/i18n/es.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_sale_invoicing +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-04-06 17:36+0200\n" +"PO-Revision-Date: 2018-04-06 17:38+0200\n" +"Last-Translator: Carlos Dauden \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.8.7.1\n" + +#. module: contract_sale_invoicing +#: model:ir.model,name:contract_sale_invoicing.model_account_analytic_account +msgid "Analytic Account" +msgstr "Cuenta analítica" + +#. module: contract_sale_invoicing +#: model:ir.model.fields,help:contract_sale_invoicing.field_account_analytic_account_invoicing_sales +#: model:ir.model.fields,help:contract_sale_invoicing.field_project_project_invoicing_sales +msgid "If checked include sales with same analytic account to invoice in contract invoice creation." +msgstr "Si está marcado se incluyen los pedidos a facturar que tengan la misma cuenta analítica en la creación de la factura del contrato" + +#. module: contract_sale_invoicing +#: model:ir.model.fields,field_description:contract_sale_invoicing.field_account_analytic_account_invoicing_sales +#: model:ir.model.fields,field_description:contract_sale_invoicing.field_project_project_invoicing_sales +msgid "Invoice Pending Sales Orders" +msgstr "Facturar pedidos pendientes" diff --git a/contract_sale_invoicing/models/__init__.py b/contract_sale_invoicing/models/__init__.py new file mode 100644 index 00000000..d639560e --- /dev/null +++ b/contract_sale_invoicing/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import contract diff --git a/contract_sale_invoicing/models/contract.py b/contract_sale_invoicing/models/contract.py new file mode 100644 index 00000000..9ae245bb --- /dev/null +++ b/contract_sale_invoicing/models/contract.py @@ -0,0 +1,32 @@ +# Copyright 2018 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountAnalyticAccount(models.Model): + _inherit = 'account.analytic.account' + + invoicing_sales = fields.Boolean( + string='Invoice Pending Sales Orders', + help='If checked include sales with same analytic account to invoice ' + 'in contract invoice creation.', + ) + + @api.multi + def _create_invoice(self, invoice=False): + if not self.invoicing_sales: + return super(AccountAnalyticAccount, self)._create_invoice() + sales = self.env['sale.order'].search([ + ('analytic_account_id', '=', self.id), + ('partner_invoice_id', 'child_of', + self.partner_id.commercial_partner_id.ids), + ('invoice_status', '=', 'to invoice'), + ('date_order', '<=', + '{} 23:59:59'.format(self.recurring_next_date)), + ]) + if sales: + invoice_ids = sales.action_invoice_create() + invoice = self.env['account.invoice'].browse(invoice_ids)[:1] + return super(AccountAnalyticAccount, self)._create_invoice( + invoice=invoice) diff --git a/contract_sale_invoicing/static/description/icon.png b/contract_sale_invoicing/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/contract_sale_invoicing/static/description/icon.png differ diff --git a/contract_sale_invoicing/tests/__init__.py b/contract_sale_invoicing/tests/__init__.py new file mode 100644 index 00000000..0d440aef --- /dev/null +++ b/contract_sale_invoicing/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_contract_sale_invoicing diff --git a/contract_sale_invoicing/tests/test_contract_sale_invoicing.py b/contract_sale_invoicing/tests/test_contract_sale_invoicing.py new file mode 100644 index 00000000..a0eaf523 --- /dev/null +++ b/contract_sale_invoicing/tests/test_contract_sale_invoicing.py @@ -0,0 +1,44 @@ +# Copyright 2018 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.contract.tests.test_contract import TestContractBase + + +class TestContractSaleInvoicing(TestContractBase): + @classmethod + def setUpClass(cls): + super(TestContractSaleInvoicing, cls).setUpClass() + cls.product_so = cls.env.ref( + 'product.service_order_01_product_template') + cls.sale_order = cls.env['sale.order'].create({ + 'partner_id': cls.partner.id, + 'partner_invoice_id': cls.partner.id, + 'partner_shipping_id': cls.partner.id, + 'order_line': [(0, 0, {'name': cls.product_so.name, + 'product_id': cls.product_so.id, + 'product_uom_qty': 2, + 'product_uom': cls.product_so.uom_id.id, + 'price_unit': cls.product_so.list_price})], + 'pricelist_id': cls.partner.property_product_pricelist.id, + 'analytic_account_id': cls.contract.id, + 'date_order': '2016-02-15', + }) + + def test_not_sale_invoicing(self): + self.contract.invoicing_sales = False + self.sale_order.action_confirm() + self.contract.recurring_create_invoice() + self.assertEqual(self.sale_order.invoice_status, 'to invoice') + + def test_sale_invoicing(self): + self.contract.invoicing_sales = True + self.sale_order.action_confirm() + self.contract.recurring_create_invoice() + self.assertEqual(self.sale_order.invoice_status, 'invoiced') + + def test_contract_sale_invoicing_without(self): + self.contract.invoicing_sales = True + self.sale_order.analytic_account_id = False + self.sale_order.action_confirm() + self.contract.recurring_create_invoice() + self.assertEqual(self.sale_order.invoice_status, 'to invoice') diff --git a/contract_sale_invoicing/views/contract_view.xml b/contract_sale_invoicing/views/contract_view.xml new file mode 100644 index 00000000..b492211f --- /dev/null +++ b/contract_sale_invoicing/views/contract_view.xml @@ -0,0 +1,17 @@ + + + + + + + account.analytic.account + + + + + + + + +