diff --git a/purchase_force_invoiced/README.rst b/purchase_force_invoiced/README.rst new file mode 100644 index 00000000000..3ee3525aa7d --- /dev/null +++ b/purchase_force_invoiced/README.rst @@ -0,0 +1,96 @@ +======================= +Purchase Force Invoiced +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/15.0/purchase_force_invoiced + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_force_invoiced + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/142/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the possibility for users to force the invoice status of the +purchase orders to 'No Bill to Receive', even when not all the +quantities, ordered or delivered, have been invoiced. + +This feature is useful in the following scenario: + +* The supplier disputes the quantities to be billed for, after the + products have been delivered to her/him, and you agree to reduce the + quantity to invoice (without expecting a refund). + +* When migrating from a previous Odoo version, in some cases there is less + quantity billed to what was delivered, and you don't want these old purchase + orders to appear in your 'Waiting Bills' list. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Create a purchase order and confirm it. +#. Receive the products/services. +#. Create a vendor bill and reduce the invoiced quantity. The purchase order + invoicing status is 'Waiting Bills'. +#. Lock the Purchase Order and change its status to 'Done'. +#. Check the field 'Force Invoiced'. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Forgeflow + +Contributors +~~~~~~~~~~~~ + +* Jordi Ballester +* Rattapong Chokmasermkul + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_force_invoiced/__init__.py b/purchase_force_invoiced/__init__.py new file mode 100644 index 00000000000..cfd243e8f09 --- /dev/null +++ b/purchase_force_invoiced/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import model +from . import reports diff --git a/purchase_force_invoiced/__manifest__.py b/purchase_force_invoiced/__manifest__.py new file mode 100644 index 00000000000..9b739167747 --- /dev/null +++ b/purchase_force_invoiced/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2019 ForgeFlow S.L. +# Copyright 2019 Aleph Objects, Inc. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +{ + "name": "Purchase Force Invoiced", + "summary": "Allows to force the billing status of the purchase order to " + '"Invoiced"', + "version": "16.0.1.0.0", + "author": "Forgeflow, Odoo Community Association (OCA)", + "category": "Purchase Management", + "license": "AGPL-3", + "website": "https://github.com/OCA/purchase-workflow", + "depends": ["purchase"], + "data": ["view/purchase_view.xml"], + "installable": True, +} diff --git a/purchase_force_invoiced/i18n/purchase_force_invoiced.pot b/purchase_force_invoiced/i18n/purchase_force_invoiced.pot new file mode 100644 index 00000000000..f97037b20b9 --- /dev/null +++ b/purchase_force_invoiced/i18n/purchase_force_invoiced.pot @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_force_invoiced +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \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: purchase_force_invoiced +#: model:ir.model.fields,field_description:purchase_force_invoiced.field_purchase_order__force_invoiced +msgid "Force Invoiced" +msgstr "" + +#. module: purchase_force_invoiced +#: model:ir.model,name:purchase_force_invoiced.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_force_invoiced +#: model:ir.model,name:purchase_force_invoiced.model_purchase_report +msgid "Purchase Report" +msgstr "" + +#. module: purchase_force_invoiced +#: model:ir.model.fields,help:purchase_force_invoiced.field_purchase_order__force_invoiced +msgid "" +"When you set this field, the purchase order will be considered as fully " +"billed, even when there may be ordered or delivered quantities pending to " +"bill. To use this field, the order must be in 'Locked' state" +msgstr "" diff --git a/purchase_force_invoiced/i18n/zh_CN.po b/purchase_force_invoiced/i18n/zh_CN.po new file mode 100644 index 00000000000..beba15ae3b2 --- /dev/null +++ b/purchase_force_invoiced/i18n/zh_CN.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_force_invoiced +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-09-02 14:40+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: purchase_force_invoiced +#: model:ir.model.fields,field_description:purchase_force_invoiced.field_purchase_order__force_invoiced +msgid "Force Invoiced" +msgstr "" + +#. module: purchase_force_invoiced +#: model:ir.model,name:purchase_force_invoiced.model_purchase_order +msgid "Purchase Order" +msgstr "采购订单" + +#. module: purchase_force_invoiced +#: model:ir.model,name:purchase_force_invoiced.model_purchase_report +msgid "Purchase Report" +msgstr "" + +#. module: purchase_force_invoiced +#: model:ir.model.fields,help:purchase_force_invoiced.field_purchase_order__force_invoiced +msgid "" +"When you set this field, the purchase order will be considered as fully " +"billed, even when there may be ordered or delivered quantities pending to " +"bill. To use this field, the order must be in 'Locked' state" +msgstr "" + +#~ msgid "Force invoiced" +#~ msgstr "强制开具发票" + +#~ msgid "" +#~ "When you set this field, the purchase order will be considered as fully " +#~ "billed, even when there may be ordered or delivered quantities pending to " +#~ "bill." +#~ msgstr "" +#~ "设置此字段时,即使订单或已交付的数量待处理,也会将采购订单视为已完成开票。" + +#~ msgid "Invoice" +#~ msgstr "发票" diff --git a/purchase_force_invoiced/model/__init__.py b/purchase_force_invoiced/model/__init__.py new file mode 100644 index 00000000000..02aef857653 --- /dev/null +++ b/purchase_force_invoiced/model/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import purchase diff --git a/purchase_force_invoiced/model/purchase.py b/purchase_force_invoiced/model/purchase.py new file mode 100644 index 00000000000..412d9ebf51d --- /dev/null +++ b/purchase_force_invoiced/model/purchase.py @@ -0,0 +1,26 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import api, fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + force_invoiced = fields.Boolean( + readonly=True, + states={"done": [("readonly", False)]}, + copy=False, + help="When you set this field, the purchase order will be " + "considered as fully billed, even when there may be ordered " + "or delivered quantities pending to bill. To use this field, " + "the order must be in 'Locked' state", + ) + + @api.depends("force_invoiced") + def _get_invoiced(self): + res = super()._get_invoiced() + for order in self.filtered( + lambda po: po.force_invoiced and po.invoice_status == "to invoice" + ): + order.invoice_status = "invoiced" + return res diff --git a/purchase_force_invoiced/readme/CONTRIBUTORS.rst b/purchase_force_invoiced/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..99fcc2d3f77 --- /dev/null +++ b/purchase_force_invoiced/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester +* Rattapong Chokmasermkul diff --git a/purchase_force_invoiced/readme/DESCRIPTION.rst b/purchase_force_invoiced/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..d855cbe5833 --- /dev/null +++ b/purchase_force_invoiced/readme/DESCRIPTION.rst @@ -0,0 +1,13 @@ +This module adds the possibility for users to force the invoice status of the +purchase orders to 'No Bill to Receive', even when not all the +quantities, ordered or delivered, have been invoiced. + +This feature is useful in the following scenario: + +* The supplier disputes the quantities to be billed for, after the + products have been delivered to her/him, and you agree to reduce the + quantity to invoice (without expecting a refund). + +* When migrating from a previous Odoo version, in some cases there is less + quantity billed to what was delivered, and you don't want these old purchase + orders to appear in your 'Waiting Bills' list. diff --git a/purchase_force_invoiced/readme/USAGE.rst b/purchase_force_invoiced/readme/USAGE.rst new file mode 100644 index 00000000000..f4991e40a35 --- /dev/null +++ b/purchase_force_invoiced/readme/USAGE.rst @@ -0,0 +1,6 @@ +#. Create a purchase order and confirm it. +#. Receive the products/services. +#. Create a vendor bill and reduce the invoiced quantity. The purchase order + invoicing status is 'Waiting Bills'. +#. Lock the Purchase Order and change its status to 'Done'. +#. Check the field 'Force Invoiced'. diff --git a/purchase_force_invoiced/reports/__init__.py b/purchase_force_invoiced/reports/__init__.py new file mode 100644 index 00000000000..b343999721b --- /dev/null +++ b/purchase_force_invoiced/reports/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import purchase_report diff --git a/purchase_force_invoiced/reports/purchase_report.py b/purchase_force_invoiced/reports/purchase_report.py new file mode 100644 index 00000000000..9859847aa9e --- /dev/null +++ b/purchase_force_invoiced/reports/purchase_report.py @@ -0,0 +1,21 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +# Copyright 2022 Tecnativa - Pedro M. Baeza + +from odoo import models + + +class PurchaseReport(models.Model): + _inherit = "purchase.report" + + def _select(self): + """Put quantity to be billed as 0 if it has been forced.""" + select_str = super()._select() + select_str = select_str.replace( + "case when t.purchase_method = 'purchase'", + "case when po.force_invoiced then 0.0 " + "else (case when t.purchase_method = 'purchase' ", + ) + select_str = select_str.replace( + "end as qty_to_be_billed", "end) end as qty_to_be_billed" + ) + return select_str diff --git a/purchase_force_invoiced/static/description/icon.png b/purchase_force_invoiced/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_force_invoiced/static/description/icon.png differ diff --git a/purchase_force_invoiced/static/description/index.html b/purchase_force_invoiced/static/description/index.html new file mode 100644 index 00000000000..732f2730b81 --- /dev/null +++ b/purchase_force_invoiced/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Purchase Force Invoiced + + + +
+

Purchase Force Invoiced

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runbot

+

This module adds the possibility for users to force the invoice status of the +purchase orders to ‘No Bill to Receive’, even when not all the +quantities, ordered or delivered, have been invoiced.

+

This feature is useful in the following scenario:

+
    +
  • The supplier disputes the quantities to be billed for, after the +products have been delivered to her/him, and you agree to reduce the +quantity to invoice (without expecting a refund).
  • +
  • When migrating from a previous Odoo version, in some cases there is less +quantity billed to what was delivered, and you don’t want these old purchase +orders to appear in your ‘Waiting Bills’ list.
  • +
+

Table of contents

+ +
+

Usage

+
    +
  1. Create a purchase order and confirm it.
  2. +
  3. Receive the products/services.
  4. +
  5. Create a vendor bill and reduce the invoiced quantity. The purchase order +invoicing status is ‘Waiting Bills’.
  6. +
  7. Lock the Purchase Order and change its status to ‘Done’.
  8. +
  9. Check the field ‘Force Invoiced’.
  10. +
+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Forgeflow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_force_invoiced/tests/__init__.py b/purchase_force_invoiced/tests/__init__.py new file mode 100644 index 00000000000..533f70698a9 --- /dev/null +++ b/purchase_force_invoiced/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import test_purchase_force_invoiced diff --git a/purchase_force_invoiced/tests/test_purchase_force_invoiced.py b/purchase_force_invoiced/tests/test_purchase_force_invoiced.py new file mode 100644 index 00000000000..55047de8687 --- /dev/null +++ b/purchase_force_invoiced/tests/test_purchase_force_invoiced.py @@ -0,0 +1,137 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# Copyright 2019 Aleph Objects, Inc. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import fields +from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase + + +class TestPurchaseForceInvoiced(TransactionCase): + def setUp(self): + super(TestPurchaseForceInvoiced, self).setUp() + self.purchase_order_model = self.env["purchase.order"] + self.purchase_order_line_model = self.env["purchase.order.line"] + self.account_invoice_model = self.env["account.move"] + self.account_invoice_line = self.env["account.move.line"] + self.invoice_account = self.env["account.account"].search( + [ + ("account_type", "=", "income"), + ("company_id", "=", self.env.company.id), + ], + limit=1, + ) + + # 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_supplier("Test Supplier") + + def _create_supplier(self, name): + """Create a Partner.""" + return self.env["res.partner"].create( + {"name": name, "email": "example@yourcompany.com", "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", + "purchase_method": "receive", + } + ) + return product + + def _create_invoice_from_purchase(self, purchase): + purchase.action_create_invoice() + return self.account_invoice_model.search([], order="id desc", limit=1) + + def create_invoice_line(self, line, invoice): + vals = [ + ( + 0, + 0, + { + "name": line.name, + "product_id": line.product_id.id, + "quantity": line.qty_received - line.qty_invoiced, + "price_unit": line.price_unit, + "account_id": self.invoice_account.id, + "purchase_line_id": line.id, + }, + ) + ] + return invoice.update({"invoice_line_ids": vals}) + + def test_purchase_order(self): + po = self.purchase_order_model.create({"partner_id": self.customer.id}) + pol1 = self.purchase_order_line_model.create( + { + "name": self.service_1.name, + "product_id": self.service_1.id, + "product_qty": 1, + "product_uom": self.service_1.uom_po_id.id, + "price_unit": 500.0, + "date_planned": fields.Date.today(), + "order_id": po.id, + } + ) + pol2 = self.purchase_order_line_model.create( + { + "name": self.service_2.name, + "product_id": self.service_2.id, + "product_qty": 2, + "product_uom": self.service_2.uom_po_id.id, + "price_unit": 500.0, + "date_planned": fields.Date.today(), + "order_id": po.id, + } + ) + + # confirm quotation + po.button_confirm() + # update quantities delivered + pol1.qty_received = 1 + pol2.qty_received = 2 + + self.assertEqual( + po.invoice_status, "to invoice", "The invoice status should be To Invoice" + ) + + invoice = self._create_invoice_from_purchase(po) + self.create_invoice_line(pol1, invoice) + self.create_invoice_line(pol2, invoice) + self.assertEqual( + po.invoice_status, "invoiced", "The invoice status should be Invoiced" + ) + + # Reduce the invoiced qty + for line in pol2.invoice_lines: + line.with_context(check_move_validity=False).unlink() + self.assertEqual( + po.invoice_status, "to invoice", "The invoice status should be To Invoice" + ) + # We set the force invoiced. + po.button_done() + po.force_invoiced = True + self.assertEqual( + po.invoice_status, "invoiced", "The invoice status should be Invoiced" + ) + with self.assertRaises(UserError): + self._create_invoice_from_purchase(po) + # We remove the force invoiced. + po.force_invoiced = False + self.assertEqual( + po.invoice_status, "to invoice", "The invoice status should be To Invoice" + ) + invoice = self._create_invoice_from_purchase(po) + self.create_invoice_line(pol2, invoice) + invoice_qty = sum(invoice.mapped("invoice_line_ids.quantity")) + self.assertEqual(invoice_qty, 2.0) diff --git a/purchase_force_invoiced/view/purchase_view.xml b/purchase_force_invoiced/view/purchase_view.xml new file mode 100644 index 00000000000..af472d5dbc3 --- /dev/null +++ b/purchase_force_invoiced/view/purchase_view.xml @@ -0,0 +1,16 @@ + + + + + purchase.order.form + purchase.order + + + + + + + + diff --git a/setup/purchase_force_invoiced/odoo/addons/purchase_force_invoiced b/setup/purchase_force_invoiced/odoo/addons/purchase_force_invoiced new file mode 120000 index 00000000000..7187e13b930 --- /dev/null +++ b/setup/purchase_force_invoiced/odoo/addons/purchase_force_invoiced @@ -0,0 +1 @@ +../../../../purchase_force_invoiced \ No newline at end of file diff --git a/setup/purchase_force_invoiced/setup.py b/setup/purchase_force_invoiced/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/purchase_force_invoiced/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)