diff --git a/sale_force_invoiced/README.rst b/sale_force_invoiced/README.rst new file mode 100644 index 00000000000..b06d76f7693 --- /dev/null +++ b/sale_force_invoiced/README.rst @@ -0,0 +1,74 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +=================== +Sale Force Invoiced +=================== + +This module adds the possibility for users to force the invoice status of the + sales orders to 'Invoiced', even when not all the quantities ordered or + delivered have been invoiced. + +This feature useful in the following scenario: + +* The customer disputes the quantities to be invoiced for, after the + products have been delivered to her/him, and you agree to reduce the + quantity to invoice (without sending a refund). + +* When migrating from a previous Odoo version, in some cases there is less + quantity invoiced to what was delivered, and you don't want these old sales + orders to appear in your 'To Invoice' list. + + +Usage +===== + +#. Create a sales order and confirm it. +#. Deliver the products/services. +#. Create an invoice and reduce the invoiced quantity. The sales order + invoicing status is 'To Invoice'. +#. Change the status of the sales order to 'Done'. +#. Check the field 'Force Invoiced' + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/167/9.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 smashing it by providing a detailed and welcomed feedback. + + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + + +Contributors +------------ + +* Jordi Ballester + + +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/sale_force_invoiced/__init__.py b/sale_force_invoiced/__init__.py new file mode 100644 index 00000000000..412f9fe11fa --- /dev/null +++ b/sale_force_invoiced/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import model diff --git a/sale_force_invoiced/__openerp__.py b/sale_force_invoiced/__openerp__.py new file mode 100644 index 00000000000..25df66222df --- /dev/null +++ b/sale_force_invoiced/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Sale Force Invoiced', + 'summary': 'Allows to force the invoice status of the sales order to ' + 'Invoiced', + 'version': '9.0.1.0.0', + "author": "Eficent," + "Odoo Community Association (OCA)", + 'category': 'sale', + 'license': 'AGPL-3', + 'website': "https://github.com/OCA/sale-workflow", + 'depends': ['sale'], + 'data': [ + 'view/sale_view.xml' + ], + 'installable': True, +} diff --git a/sale_force_invoiced/model/__init__.py b/sale_force_invoiced/model/__init__.py new file mode 100644 index 00000000000..ce1f320f233 --- /dev/null +++ b/sale_force_invoiced/model/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import sale_order diff --git a/sale_force_invoiced/model/sale_order.py b/sale_force_invoiced/model/sale_order.py new file mode 100644 index 00000000000..124d3762d13 --- /dev/null +++ b/sale_force_invoiced/model/sale_order.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + force_invoiced = fields.Boolean(string='Force invoiced', + help='When you set this field, the sales ' + 'order will be considered as fully ' + 'invoiced, even when there may be ' + 'ordered or delivered quantities ' + 'pending to invoice.', + readonly=True, + states={'done': [('readonly', False)]}, + default=False) + + @api.depends('force_invoiced') + def _get_invoiced(self): + super(SaleOrder, self)._get_invoiced() + for order in self: + if order.force_invoiced and order.invoice_status == 'to invoice': + order.invoice_status = 'invoiced' diff --git a/sale_force_invoiced/static/description/icon.png b/sale_force_invoiced/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_force_invoiced/static/description/icon.png differ diff --git a/sale_force_invoiced/tests/__init__.py b/sale_force_invoiced/tests/__init__.py new file mode 100644 index 00000000000..f62b4553b82 --- /dev/null +++ b/sale_force_invoiced/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_sale_force_invoiced diff --git a/sale_force_invoiced/tests/test_sale_force_invoiced.py b/sale_force_invoiced/tests/test_sale_force_invoiced.py new file mode 100644 index 00000000000..705245fd094 --- /dev/null +++ b/sale_force_invoiced/tests/test_sale_force_invoiced.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class TestSaleForceInvoiced(TransactionCase): + + def setUp(self): + super(TestSaleForceInvoiced, self).setUp() + self.sale_order_model = self.env['sale.order'] + self.sale_order_line_model = self.env['sale.order.line'] + + # Data + product_ctg = self._create_product_category() + self.service_1 = self._create_product('test_product1', + product_ctg) + self.service_2 = self._create_product('test_product2', + product_ctg) + self.customer = self._create_customer('Test Customer') + + def _create_customer(self, name): + """Create a Partner.""" + return self.env['res.partner'].create({ + 'name': name, + 'email': 'example@yourcompany.com', + 'customer': True, + 'phone': 123456, + }) + + def _create_product_category(self): + product_ctg = self.env['product.category'].create({ + 'name': 'test_product_ctg', + }) + return product_ctg + + def _create_product(self, name, product_ctg): + product = self.env['product.product'].create({ + 'name': name, + 'categ_id': product_ctg.id, + 'type': 'service', + 'invoice_policy': 'order', + 'track_service': 'manual' + }) + return product + + def _create_invoice_from_sale(self, sale): + payment = self.env['sale.advance.payment.inv'].create({ + 'advance_payment_method': 'delivered' + }) + sale_context = { + 'active_id': sale.id, + 'active_ids': sale.ids, + 'active_model': 'sale.order', + 'open_invoices': True, + } + res = payment.with_context(sale_context).create_invoices() + invoice_id = res['res_id'] + return invoice_id + + def test_sales_order(self): + so = self.sale_order_model.create({ + 'partner_id': self.customer.id, + }) + sol1 = self.sale_order_line_model.create({ + 'product_id': self.service_1.id, + 'product_uom_qty': 1, + 'order_id': so.id + }) + sol2 = self.sale_order_line_model.create({ + 'product_id': self.service_2.id, + 'product_uom_qty': 2, + 'order_id': so.id + }) + + # confirm quotation + so.action_confirm() + # update quantities delivered + sol1.qty_delivered = 1 + sol2.qty_delivered = 2 + + self.assertEquals(so.invoice_status, 'to invoice', + "The invoice status should be To Invoice") + + self._create_invoice_from_sale(so) + self.assertEquals(so.invoice_status, 'invoiced', + "The invoice status should be Invoiced") + + # Reduce the invoiced qty + for line in sol2.invoice_lines: + line.quantity = 1 + + self.assertEquals(so.invoice_status, 'to invoice', + "The invoice status should be To Invoice") + + so.action_done() + so.force_invoiced = True + self.assertEquals(so.invoice_status, 'invoiced', + "The invoice status should be Invoiced") + + so.force_invoiced = False + self.assertEquals(so.invoice_status, 'to invoice', + "The invoice status should be To Invoice") diff --git a/sale_force_invoiced/view/sale_view.xml b/sale_force_invoiced/view/sale_view.xml new file mode 100644 index 00000000000..51e7cafe7be --- /dev/null +++ b/sale_force_invoiced/view/sale_view.xml @@ -0,0 +1,15 @@ + + + + + sale.order.form + sale.order + + + + + + + + +