From 40e579c148bd4068fd48808d35a42dbd4d1c67c5 Mon Sep 17 00:00:00 2001 From: dsolanki Date: Wed, 8 Feb 2023 14:46:21 +0530 Subject: [PATCH] [ADD] stock_picking_on_hold [15.0][upd] conditional readonly added to hold_picking_until_payment [15.0][upd] hold_picking_until_payment set to true by default [15.0][IMP] Base stock_picking_on_hold on sale_stock_picking_blocking --- .github/workflows/test.yml | 4 +- .../odoo/addons/stock_picking_on_hold | 1 + setup/stock_picking_on_hold/setup.py | 6 ++ stock_picking_on_hold/README.rst | 84 +++++++++++++++++++ stock_picking_on_hold/__init__.py | 3 + stock_picking_on_hold/__manifest__.py | 25 ++++++ stock_picking_on_hold/models/__init__.py | 1 + .../models/payment_method.py | 13 +++ stock_picking_on_hold/models/sale_order.py | 52 ++++++++++++ stock_picking_on_hold/readme/CONFIGURE.rst | 1 + stock_picking_on_hold/readme/CONTRIBUTORS.rst | 3 + stock_picking_on_hold/readme/DESCRIPTION.rst | 1 + stock_picking_on_hold/readme/USAGE.rst | 4 + .../views/payment_method.xml | 16 ++++ .../views/sale_order_view.xml | 27 ++++++ 15 files changed, 239 insertions(+), 2 deletions(-) create mode 120000 setup/stock_picking_on_hold/odoo/addons/stock_picking_on_hold create mode 100644 setup/stock_picking_on_hold/setup.py create mode 100644 stock_picking_on_hold/README.rst create mode 100644 stock_picking_on_hold/__init__.py create mode 100644 stock_picking_on_hold/__manifest__.py create mode 100644 stock_picking_on_hold/models/__init__.py create mode 100644 stock_picking_on_hold/models/payment_method.py create mode 100644 stock_picking_on_hold/models/sale_order.py create mode 100644 stock_picking_on_hold/readme/CONFIGURE.rst create mode 100644 stock_picking_on_hold/readme/CONTRIBUTORS.rst create mode 100644 stock_picking_on_hold/readme/DESCRIPTION.rst create mode 100644 stock_picking_on_hold/readme/USAGE.rst create mode 100644 stock_picking_on_hold/views/payment_method.xml create mode 100644 stock_picking_on_hold/views/sale_order_view.xml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 651375f866d9..9086b5360566 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,11 +43,11 @@ jobs: include: "portal_sale_personal_data_only" name: test with OCB - container: ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest - exclude: "portal_sale_personal_data_only" + exclude: "portal_sale_personal_data_only, sale_automatic_workflow_job, sale_stock_secondary_unit" makepot: "true" name: test with Odoo - container: ghcr.io/oca/oca-ci/py3.8-ocb15.0:latest - exclude: "portal_sale_personal_data_only" + exclude: "portal_sale_personal_data_only, sale_automatic_workflow_job, sale_stock_secondary_unit" name: test with OCB services: postgres: diff --git a/setup/stock_picking_on_hold/odoo/addons/stock_picking_on_hold b/setup/stock_picking_on_hold/odoo/addons/stock_picking_on_hold new file mode 120000 index 000000000000..d2ec518b64d6 --- /dev/null +++ b/setup/stock_picking_on_hold/odoo/addons/stock_picking_on_hold @@ -0,0 +1 @@ +../../../../stock_picking_on_hold \ No newline at end of file diff --git a/setup/stock_picking_on_hold/setup.py b/setup/stock_picking_on_hold/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_picking_on_hold/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_on_hold/README.rst b/stock_picking_on_hold/README.rst new file mode 100644 index 000000000000..8e2d94217dd0 --- /dev/null +++ b/stock_picking_on_hold/README.rst @@ -0,0 +1,84 @@ +=================================================== +Sale Payment Method - Hold Pickings (Until Payment) +=================================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/15.0/stock_picking_on_hold + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-stock_picking_on_hold + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/167/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to automatically hold a sale order's deliveries until the invoice is paid + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1) Set on payment methods whether they should block deliveries until paid +2) Set payment method on sale order +3) A sale order's picking won't be created until it is paid + + +Configuration +============= + +Go to Invoicing > Payment Methods > Select your payment method > Enable "Hold Picking Until Payment" + + +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. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +~~~~~~~~~~~~ + +* Thomas Rehn +* Katja Matthes +* Dhara Solanki +* Ruben Ortlam + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_on_hold/__init__.py b/stock_picking_on_hold/__init__.py new file mode 100644 index 000000000000..69f7babdfb1a --- /dev/null +++ b/stock_picking_on_hold/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_picking_on_hold/__manifest__.py b/stock_picking_on_hold/__manifest__.py new file mode 100644 index 000000000000..8f2cf41f0b81 --- /dev/null +++ b/stock_picking_on_hold/__manifest__.py @@ -0,0 +1,25 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Payment Method - Hold Pickings (until payment)", + "version": "15.0.1.0.0", + "website": "https://github.com/OCA/sale-workflow", + "category": "Warehouse", + "summary": """ + Sale Payment Method - Hold Pickings until payment + =================================================== + * This module allows to hold the picking until the invoice is paid""", + "depends": [ + "stock", + "sale_stock_picking_blocking", + "account_payment_mode", + ], + "author": "initOS GmbH, Odoo Community Association (OCA)", + "license": "AGPL-3", + "data": [ + "views/payment_method.xml", + "views/sale_order_view.xml", + ], + "installable": True, + "application": False, +} diff --git a/stock_picking_on_hold/models/__init__.py b/stock_picking_on_hold/models/__init__.py new file mode 100644 index 000000000000..7517e58f7d3d --- /dev/null +++ b/stock_picking_on_hold/models/__init__.py @@ -0,0 +1 @@ +from . import payment_method, sale_order diff --git a/stock_picking_on_hold/models/payment_method.py b/stock_picking_on_hold/models/payment_method.py new file mode 100644 index 000000000000..c0cb32a23a0f --- /dev/null +++ b/stock_picking_on_hold/models/payment_method.py @@ -0,0 +1,13 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class PaymentMethod(models.Model): + _inherit = "account.payment.method" + + hold_picking_until_payment = fields.Boolean( + help="If set to true, pickings will not be automatically confirmed when " + "the invoice has not been paid.", + default=True, + ) diff --git a/stock_picking_on_hold/models/sale_order.py b/stock_picking_on_hold/models/sale_order.py new file mode 100644 index 000000000000..2ca2009e25fb --- /dev/null +++ b/stock_picking_on_hold/models/sale_order.py @@ -0,0 +1,52 @@ +from odoo import fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + payment_method_id = fields.Many2one( + "account.payment.method", + string="Payment Method", + ondelete="restrict", + ) + + def auto_set_invoice_block(self): + recs = self.filtered_domain( + [("payment_method_id.hold_picking_until_payment", "=", True)] + ) + + if not recs: + return + + block_reason = self.env.ref("sale_stock_picking_blocking.pay_before_delivery") + + # Block records that are not yet invoiced or draft + # Unblock the rest + block = recs.filtered_domain( + [ + "|", + "&", + ("state", "=", "draft"), + ("invoice_status", "=", "no"), + ("invoice_status", "!=", "invoiced"), + ] + ) + + unblock = recs - block + + block.write({"delivery_block_id": block_reason.id}) + unblock.action_remove_delivery_block() + + def onchange_partner_id(self): + result = super().onchange_partner_id() + + self.auto_set_invoice_block() + + return result + + def _get_invoice_status(self): + result = super()._get_invoice_status() + + self.auto_set_invoice_block() + + return result diff --git a/stock_picking_on_hold/readme/CONFIGURE.rst b/stock_picking_on_hold/readme/CONFIGURE.rst new file mode 100644 index 000000000000..452a2565c8a8 --- /dev/null +++ b/stock_picking_on_hold/readme/CONFIGURE.rst @@ -0,0 +1 @@ +#. Go to Invoicing > Payment Methods > Select your payment method > Enable "Hold Picking Untill Payment" diff --git a/stock_picking_on_hold/readme/CONTRIBUTORS.rst b/stock_picking_on_hold/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..3c02a874f620 --- /dev/null +++ b/stock_picking_on_hold/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Thomas Rehn +* Katja Matthes +* Dhara Solanki diff --git a/stock_picking_on_hold/readme/DESCRIPTION.rst b/stock_picking_on_hold/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..39fba1240a20 --- /dev/null +++ b/stock_picking_on_hold/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to hold the picking until the invoice is paid. diff --git a/stock_picking_on_hold/readme/USAGE.rst b/stock_picking_on_hold/readme/USAGE.rst new file mode 100644 index 000000000000..72445f6cfa73 --- /dev/null +++ b/stock_picking_on_hold/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use functionality of module, + +1) You need to generate "Sale Order" using "Payment Method: Enabled Hold Picking Untill Payment" +2) Picking can not "confirm" untill the payment is "confirmed" of that Sale Order diff --git a/stock_picking_on_hold/views/payment_method.xml b/stock_picking_on_hold/views/payment_method.xml new file mode 100644 index 000000000000..1e1cdbe098a2 --- /dev/null +++ b/stock_picking_on_hold/views/payment_method.xml @@ -0,0 +1,16 @@ + + + + sale_payment_method.payment_method.view_form + account.payment.method + + + + + + + + diff --git a/stock_picking_on_hold/views/sale_order_view.xml b/stock_picking_on_hold/views/sale_order_view.xml new file mode 100644 index 000000000000..d884ce98e151 --- /dev/null +++ b/stock_picking_on_hold/views/sale_order_view.xml @@ -0,0 +1,27 @@ + + + + sale.order.payment_method.view_form + sale.order + + + + + + + + + + sale.order.tree.stock_picking_on_hold + sale.order + + + + + + + +