diff --git a/partner_invoicing_mode_cash_on_delivery/README.rst b/partner_invoicing_mode_cash_on_delivery/README.rst new file mode 100644 index 00000000000..f21e5bd0aab --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/README.rst @@ -0,0 +1,90 @@ +======================================= +Partner Invoicing Mode Cash on Delivery +======================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5525b56e6241690abaa44bb465f180508ee6a0af871cd8a3d2232216e25c602c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--invoicing-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoicing/tree/16.0/partner_invoicing_mode_cash_on_delivery + :alt: OCA/account-invoicing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoicing-16-0/account-invoicing-16-0-partner_invoicing_mode_cash_on_delivery + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Allow to mark a payment mode as "cash on delivery". +When the picking is delivered, an invoice is automaticaly generated with the +amount to be paid. +Allows users to identify cash on delivery invoices on shippings. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +You must mark a payment mode as "cash on delivery". If you want the invoice +to be posted at the same moment, check the "Auto validate Invoice When Cash On Delivery" + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* BCIM +* ACSONE SA/NV +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Jacques-Etienne Baudoux +* Souheil Bejaoui +* Tuan Tran +* Denis Roussel + +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/account-invoicing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_invoicing_mode_cash_on_delivery/__init__.py b/partner_invoicing_mode_cash_on_delivery/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_invoicing_mode_cash_on_delivery/__manifest__.py b/partner_invoicing_mode_cash_on_delivery/__manifest__.py new file mode 100644 index 00000000000..8e5588384c0 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2018 Jacques-Etienne Baudoux (BCIM) +# Copyright 2023 ACSONE SA/NV +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner Invoicing Mode Cash on Delivery", + "summary": """This module allows users to distinguish cash on delivery invoices + in the automatic invoicing flow""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "BCIM, ACSONE SA/NV, Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-invoicing", + "depends": [ + "account_payment_sale", + "partner_invoicing_mode_at_shipping", + ], + "data": [ + "views/account_payment_mode_views.xml", + "views/stock_picking_views.xml", + "data/account_payment_mode.xml", + ], +} diff --git a/partner_invoicing_mode_cash_on_delivery/data/account_payment_mode.xml b/partner_invoicing_mode_cash_on_delivery/data/account_payment_mode.xml new file mode 100644 index 00000000000..0fc8ff6ba86 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/data/account_payment_mode.xml @@ -0,0 +1,17 @@ + + + + + + Cash On Delivery + + + + variable + + + diff --git a/partner_invoicing_mode_cash_on_delivery/models/__init__.py b/partner_invoicing_mode_cash_on_delivery/models/__init__.py new file mode 100644 index 00000000000..dd21a50eb9f --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_payment_mode +from . import stock_picking diff --git a/partner_invoicing_mode_cash_on_delivery/models/account_payment_mode.py b/partner_invoicing_mode_cash_on_delivery/models/account_payment_mode.py new file mode 100644 index 00000000000..a595a64bbec --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/models/account_payment_mode.py @@ -0,0 +1,15 @@ +# Copyright 2018 Jacques-Etienne Baudoux (BCIM) + +from odoo import fields, models + + +class AccountPaymentMode(models.Model): + _inherit = "account.payment.mode" + + cash_on_delivery = fields.Boolean( + help="Check this if you want to identify Cash On Delivery invoices on stock pickings." + ) + auto_validate_invoice_cash_on_delivery = fields.Boolean( + help="Check this if you want Cash on Delivery deliveries to validate " + "automatically generated invoices." + ) diff --git a/partner_invoicing_mode_cash_on_delivery/models/stock_picking.py b/partner_invoicing_mode_cash_on_delivery/models/stock_picking.py new file mode 100644 index 00000000000..5a2774c950a --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/models/stock_picking.py @@ -0,0 +1,60 @@ +# Copyright 2018 Jacques-Etienne Baudoux (BCIM) +# Copyright 2023 ACSONE SA/NV +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + cash_on_delivery_invoice_ids = fields.Many2many( + comodel_name="account.move", + # Force the table relation to avoid naming collisions + relation="stock_picking_cash_on_delivery_move_id_rel", + column1="picking_id", + column2="move_id", + string="COD Invoices", + copy=False, + readonly=True, + ) + + def _invoice_at_shipping(self): + """ + This will take this picking into account for invoice creation (at shipping) + when sale order has Cash On Delivery set and even if the partner is not + using that mode (at shipping). + """ + self.ensure_one() + res = super()._invoice_at_shipping() + res = res or ( + self.picking_type_code == "outgoing" + and self.sale_id.payment_mode_id.cash_on_delivery + ) + return res + + def _invoicing_at_shipping_validation(self, invoices): + # COD invoices will be validated automatically + cod_invoices_to_validate = invoices.filtered( + lambda invoice: invoice.payment_mode_id.cash_on_delivery + and invoice.payment_mode_id.auto_validate_invoice_cash_on_delivery + ) + # Non-COD invoices need to check in the call of `super` + invoices_to_validate = invoices.filtered( + lambda invoice: not invoice.payment_mode_id.cash_on_delivery + ) + res = super()._invoicing_at_shipping_validation(invoices_to_validate) + if cod_invoices_to_validate: + res |= cod_invoices_to_validate + return res + + def _invoicing_at_shipping(self): + self.ensure_one() + res = super()._invoicing_at_shipping() + if not isinstance(res, str): + cod_invoices = res.filtered( + lambda inv: inv.payment_mode_id.cash_on_delivery + ) + self.cash_on_delivery_invoice_ids = cod_invoices + return res diff --git a/partner_invoicing_mode_cash_on_delivery/readme/CONFIGURE.rst b/partner_invoicing_mode_cash_on_delivery/readme/CONFIGURE.rst new file mode 100644 index 00000000000..7c8a9108918 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +You must mark a payment mode as "cash on delivery". If you want the invoice +to be posted at the same moment, check the "Auto validate Invoice When Cash On Delivery" diff --git a/partner_invoicing_mode_cash_on_delivery/readme/CONTRIBUTORS.rst b/partner_invoicing_mode_cash_on_delivery/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..d7b17518465 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Jacques-Etienne Baudoux +* Souheil Bejaoui +* Tuan Tran +* Denis Roussel diff --git a/partner_invoicing_mode_cash_on_delivery/readme/DESCRIPTION.rst b/partner_invoicing_mode_cash_on_delivery/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..f75c701ec88 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Allow to mark a payment mode as "cash on delivery". +When the picking is delivered, an invoice is automaticaly generated with the +amount to be paid. +Allows users to identify cash on delivery invoices on shippings. diff --git a/partner_invoicing_mode_cash_on_delivery/static/description/index.html b/partner_invoicing_mode_cash_on_delivery/static/description/index.html new file mode 100644 index 00000000000..37af8b004c3 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Partner Invoicing Mode Cash on Delivery + + + +
+

Partner Invoicing Mode Cash on Delivery

+ + +

Beta License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runboat

+

Allow to mark a payment mode as “cash on delivery”. +When the picking is delivered, an invoice is automaticaly generated with the +amount to be paid. +Allows users to identify cash on delivery invoices on shippings.

+

Table of contents

+ +
+

Configuration

+

You must mark a payment mode as “cash on delivery”. If you want the invoice +to be posted at the same moment, check the “Auto validate Invoice When Cash On Delivery”

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • BCIM
  • +
  • ACSONE SA/NV
  • +
  • Camptocamp
  • +
+
+
+

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/account-invoicing project on GitHub.

+

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

+
+
+
+ + diff --git a/partner_invoicing_mode_cash_on_delivery/tests/__init__.py b/partner_invoicing_mode_cash_on_delivery/tests/__init__.py new file mode 100644 index 00000000000..90b812091e2 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/tests/__init__.py @@ -0,0 +1 @@ +from . import test_shipment_advice_cash_on_delivery diff --git a/partner_invoicing_mode_cash_on_delivery/tests/test_shipment_advice_cash_on_delivery.py b/partner_invoicing_mode_cash_on_delivery/tests/test_shipment_advice_cash_on_delivery.py new file mode 100644 index 00000000000..3bd28e6f649 --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/tests/test_shipment_advice_cash_on_delivery.py @@ -0,0 +1,206 @@ +# Copyright 2024 Jacques-Etienne Baudoux (BCIM) +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import Command + +from odoo.addons.base.tests.common import BaseCommon +from odoo.addons.queue_job.tests.common import trap_jobs + + +class TestPartnerInvoiceCashOnDelivery(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.uom_kg = cls.env.ref("uom.product_uom_kgm") + cls.product = cls.env["product.product"].create( + { + "name": "Product COD", + "type": "product", + } + ) + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.company = cls.env.ref("base.main_company") + cls.manual_in = cls.env.ref("account.account_payment_method_manual_in") + cls.journal_c1 = cls.env["account.journal"].create( + { + "name": "J1", + "code": "J1", + "type": "bank", + "company_id": cls.company.id, + "bank_acc_number": "123456", + } + ) + + cls.payment_mode_normal = cls.env.ref( + "account_payment_mode.payment_mode_inbound_dd1" + ) + cls.payment_mode_cod = cls.env["account.payment.mode"].create( + { + "name": "COD", + "bank_account_link": "variable", + "payment_method_id": cls.manual_in.id, + "company_id": cls.company.id, + "fixed_journal_id": cls.journal_c1.id, + "variable_journal_ids": [(6, 0, [cls.journal_c1.id])], + "cash_on_delivery": True, + } + ) + cls.partner_standard = cls.env["res.partner"].create( + {"name": "partner_standard", "invoicing_mode": "standard"} + ) + cls.partner_at_shipping = cls.env["res.partner"].create( + {"name": "partner_at_shipping", "invoicing_mode": "at_shipping"} + ) + cls.company = cls.env.user.company_id + cls.default_pricelist = ( + cls.env["product.pricelist"] + .with_company(cls.company) + .create( + { + "name": "default_pricelist", + "currency_id": cls.company.currency_id.id, + } + ) + ) + cls.env["stock.quant"]._update_available_quantity( + cls.product, cls.warehouse.lot_stock_id, 3 + ) + + def _create_and_process_sale_order(self, dict_val): + # Create and confirm sale order + so = self.env["sale.order"].create(dict_val) + so.action_confirm() + pick = so.picking_ids + + pick.move_ids.write({"quantity_done": 1}) + with trap_jobs() as trap: + pick._action_done() + trap.perform_enqueued_jobs() + + return pick + + def _check_picking(self, pick, partner): + self.assertEqual(len(pick.cash_on_delivery_invoice_ids), 1) + cod_invoice = pick.cash_on_delivery_invoice_ids[0] + self.assertEqual(cod_invoice.invoice_partner_display_name, partner.name) + + def test01(self): + """ + Create 1 SO with payment mode cash on delivery for partner without + invoicing at shipping + => Should be listed in picking.cash_on_delivery_invoice_ids + """ + pick = self._create_and_process_sale_order( + { + "partner_id": self.partner_standard.id, + "partner_invoice_id": self.partner_standard.id, + "partner_shipping_id": self.partner_standard.id, + "order_line": [ + Command.create( + { + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 1, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ], + "pricelist_id": self.default_pricelist.id, + "picking_policy": "direct", + "payment_mode_id": self.payment_mode_cod.id, + } + ) + + self._check_picking(pick, self.partner_standard) + + def test02(self): + """ + Create 1 SO with payment mode cash on delivery for partner with + invoicing at shipping + => Should be listed in picking.cash_on_delivery_invoice_ids + """ + pick = self._create_and_process_sale_order( + { + "partner_id": self.partner_at_shipping.id, + "partner_invoice_id": self.partner_at_shipping.id, + "partner_shipping_id": self.partner_at_shipping.id, + "order_line": [ + Command.create( + { + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 1, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ], + "pricelist_id": self.default_pricelist.id, + "picking_policy": "direct", + "payment_mode_id": self.payment_mode_cod.id, + } + ) + + self._check_picking(pick, self.partner_at_shipping) + + def test03(self): + """ + Create 1 SO without payment mode cash on delivery for partner with + invoicing at shipping + => Should NOT be listed in picking.cash_on_delivery_invoice_ids + """ + pick = self._create_and_process_sale_order( + { + "partner_id": self.partner_at_shipping.id, + "partner_invoice_id": self.partner_at_shipping.id, + "partner_shipping_id": self.partner_at_shipping.id, + "order_line": [ + Command.create( + { + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 2, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ], + "pricelist_id": self.default_pricelist.id, + "picking_policy": "direct", + "payment_mode_id": self.payment_mode_normal.id, + } + ) + + self.assertEqual(len(pick.cash_on_delivery_invoice_ids), 0) + + def test04(self): + """ + Create 1 SO without payment mode cash on delivery for partner without + invoicing at shipping + => Should NOT be listed in picking.cash_on_delivery_invoice_ids + """ + pick = self._create_and_process_sale_order( + { + "partner_id": self.partner_standard.id, + "partner_invoice_id": self.partner_standard.id, + "partner_shipping_id": self.partner_standard.id, + "order_line": [ + Command.create( + { + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 2, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ], + "pricelist_id": self.default_pricelist.id, + "picking_policy": "direct", + "payment_mode_id": self.payment_mode_normal.id, + } + ) + + self.assertEqual(len(pick.cash_on_delivery_invoice_ids), 0) diff --git a/partner_invoicing_mode_cash_on_delivery/views/account_payment_mode_views.xml b/partner_invoicing_mode_cash_on_delivery/views/account_payment_mode_views.xml new file mode 100644 index 00000000000..a173c9a591a --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/views/account_payment_mode_views.xml @@ -0,0 +1,17 @@ + + + + cash on delivery + account.payment.mode + + + + + + + + + diff --git a/partner_invoicing_mode_cash_on_delivery/views/stock_picking_views.xml b/partner_invoicing_mode_cash_on_delivery/views/stock_picking_views.xml new file mode 100644 index 00000000000..d67fbcbf61a --- /dev/null +++ b/partner_invoicing_mode_cash_on_delivery/views/stock_picking_views.xml @@ -0,0 +1,20 @@ + + + + cash on delivery + stock.picking + + + + + + + + diff --git a/setup/partner_invoicing_mode_cash_on_delivery/odoo/addons/partner_invoicing_mode_cash_on_delivery b/setup/partner_invoicing_mode_cash_on_delivery/odoo/addons/partner_invoicing_mode_cash_on_delivery new file mode 120000 index 00000000000..d430887a99e --- /dev/null +++ b/setup/partner_invoicing_mode_cash_on_delivery/odoo/addons/partner_invoicing_mode_cash_on_delivery @@ -0,0 +1 @@ +../../../../partner_invoicing_mode_cash_on_delivery \ No newline at end of file diff --git a/setup/partner_invoicing_mode_cash_on_delivery/setup.py b/setup/partner_invoicing_mode_cash_on_delivery/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/partner_invoicing_mode_cash_on_delivery/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)