diff --git a/setup/stock_picking_return_restricted_qty/odoo/addons/stock_picking_return_restricted_qty b/setup/stock_picking_return_restricted_qty/odoo/addons/stock_picking_return_restricted_qty new file mode 120000 index 000000000000..4f7ad6659af9 --- /dev/null +++ b/setup/stock_picking_return_restricted_qty/odoo/addons/stock_picking_return_restricted_qty @@ -0,0 +1 @@ +../../../../stock_picking_return_restricted_qty \ No newline at end of file diff --git a/setup/stock_picking_return_restricted_qty/setup.py b/setup/stock_picking_return_restricted_qty/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_picking_return_restricted_qty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_return_restricted_qty/README.rst b/stock_picking_return_restricted_qty/README.rst new file mode 100644 index 000000000000..360402799e54 --- /dev/null +++ b/stock_picking_return_restricted_qty/README.rst @@ -0,0 +1,85 @@ +=================================== +Stock Picking Return Restricted Qty +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fstock--logistics--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-workflow/tree/13.0/stock_picking_return_restricted_qty + :alt: OCA/stock-logistics-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-workflow-13-0/stock-logistics-workflow-13-0-stock_picking_return_restricted_qty + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/154/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module don't allow you to return more quantity of products than the +delivered. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Create an outgoing or an internal picking. +#. Include one or more products with enough stock. +#. Validate the picking. +#. Try to return more products than the delivered and see the warning. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Carlos Roca + * Sergio Teruel + +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/stock-logistics-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_return_restricted_qty/__init__.py b/stock_picking_return_restricted_qty/__init__.py new file mode 100644 index 000000000000..14cd1b0579ca --- /dev/null +++ b/stock_picking_return_restricted_qty/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard diff --git a/stock_picking_return_restricted_qty/__manifest__.py b/stock_picking_return_restricted_qty/__manifest__.py new file mode 100644 index 000000000000..77d0efd95efb --- /dev/null +++ b/stock_picking_return_restricted_qty/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2020 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Picking Return Restricted Qty", + "summary": "Restrict the return to delivered quantity", + "version": "15.0.1.0.0", + "license": "AGPL-3", + "author": "Tecnativa," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-workflow", + "depends": ["stock"], + "data": [], +} diff --git a/stock_picking_return_restricted_qty/i18n/es.po b/stock_picking_return_restricted_qty/i18n/es.po new file mode 100644 index 000000000000..22a76d17bbe6 --- /dev/null +++ b/stock_picking_return_restricted_qty/i18n/es.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_return_restricted_qty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-03-09 10:45+0000\n" +"PO-Revision-Date: 2020-03-09 11:54+0100\n" +"Last-Translator: Carlos \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 2.0.6\n" + +#. module: stock_picking_return_restricted_qty +#: model:ir.model,name:stock_picking_return_restricted_qty.model_stock_return_picking +msgid "Return Picking" +msgstr "Albarán de devolución" + +#. module: stock_picking_return_restricted_qty +#: model:ir.model,name:stock_picking_return_restricted_qty.model_stock_return_picking_line +#, fuzzy +msgid "Return Picking Line" +msgstr "Albarán de devolución" + +#. module: stock_picking_return_restricted_qty +#: code:addons/stock_picking_return_restricted_qty/wizard/stock_picking_return.py:0 +#, python-format +msgid "Return more quantities than delivered is not allowed." +msgstr "No está permitido devolver más cantidades de las entregadas." diff --git a/stock_picking_return_restricted_qty/i18n/stock_picking_return_restricted_qty.pot b/stock_picking_return_restricted_qty/i18n/stock_picking_return_restricted_qty.pot new file mode 100644 index 000000000000..ba0b153a30ea --- /dev/null +++ b/stock_picking_return_restricted_qty/i18n/stock_picking_return_restricted_qty.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_return_restricted_qty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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: stock_picking_return_restricted_qty +#: model:ir.model,name:stock_picking_return_restricted_qty.model_stock_return_picking +msgid "Return Picking" +msgstr "" + +#. module: stock_picking_return_restricted_qty +#: model:ir.model,name:stock_picking_return_restricted_qty.model_stock_return_picking_line +msgid "Return Picking Line" +msgstr "" + +#. module: stock_picking_return_restricted_qty +#: code:addons/stock_picking_return_restricted_qty/wizard/stock_picking_return.py:0 +#: code:addons/stock_picking_return_restricted_qty/wizard/stock_picking_return.py:0 +#, python-format +msgid "Return more quantities than delivered is not allowed." +msgstr "" diff --git a/stock_picking_return_restricted_qty/i18n/zh_CN.po b/stock_picking_return_restricted_qty/i18n/zh_CN.po new file mode 100644 index 000000000000..086ccc6c2afb --- /dev/null +++ b/stock_picking_return_restricted_qty/i18n/zh_CN.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_return_restricted_qty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-05-02 13:19+0000\n" +"Last-Translator: Dong \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.10\n" + +#. module: stock_picking_return_restricted_qty +#: model:ir.model,name:stock_picking_return_restricted_qty.model_stock_return_picking +msgid "Return Picking" +msgstr "退货调拨单" + +#. module: stock_picking_return_restricted_qty +#: model:ir.model,name:stock_picking_return_restricted_qty.model_stock_return_picking_line +msgid "Return Picking Line" +msgstr "退货调拨明细" + +#. module: stock_picking_return_restricted_qty +#: code:addons/stock_picking_return_restricted_qty/wizard/stock_picking_return.py:0 +#: code:addons/stock_picking_return_restricted_qty/wizard/stock_picking_return.py:0 +#, python-format +msgid "Return more quantities than delivered is not allowed." +msgstr "退货数量不允许超出送货数量。" diff --git a/stock_picking_return_restricted_qty/readme/CONTRIBUTORS.rst b/stock_picking_return_restricted_qty/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..88dc1504c1fd --- /dev/null +++ b/stock_picking_return_restricted_qty/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Carlos Roca + * Sergio Teruel diff --git a/stock_picking_return_restricted_qty/readme/DESCRIPTION.rst b/stock_picking_return_restricted_qty/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..3dbcefdbf828 --- /dev/null +++ b/stock_picking_return_restricted_qty/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module don't allow you to return more quantity of products than the +delivered. diff --git a/stock_picking_return_restricted_qty/readme/USAGE.rst b/stock_picking_return_restricted_qty/readme/USAGE.rst new file mode 100644 index 000000000000..1ca162ba53c8 --- /dev/null +++ b/stock_picking_return_restricted_qty/readme/USAGE.rst @@ -0,0 +1,4 @@ +#. Create an outgoing or an internal picking. +#. Include one or more products with enough stock. +#. Validate the picking. +#. Try to return more products than the delivered and see the warning. diff --git a/stock_picking_return_restricted_qty/static/description/icon.png b/stock_picking_return_restricted_qty/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/stock_picking_return_restricted_qty/static/description/icon.png differ diff --git a/stock_picking_return_restricted_qty/static/description/index.html b/stock_picking_return_restricted_qty/static/description/index.html new file mode 100644 index 000000000000..6ec5a3321058 --- /dev/null +++ b/stock_picking_return_restricted_qty/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Stock Picking Return Restricted Qty + + + +
+

Stock Picking Return Restricted Qty

+ + +

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

+

This module don’t allow you to return more quantity of products than the +delivered.

+

Table of contents

+ +
+

Usage

+
    +
  1. Create an outgoing or an internal picking.
  2. +
  3. Include one or more products with enough stock.
  4. +
  5. Validate the picking.
  6. +
  7. Try to return more products than the delivered and see the warning.
  8. +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Carlos Roca
    • +
    • Sergio Teruel
    • +
    +
  • +
+
+
+

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/stock-logistics-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_return_restricted_qty/tests/__init__.py b/stock_picking_return_restricted_qty/tests/__init__.py new file mode 100644 index 000000000000..bef8cf4a5532 --- /dev/null +++ b/stock_picking_return_restricted_qty/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_stock_picking_return_restricted_qty diff --git a/stock_picking_return_restricted_qty/tests/test_stock_picking_return_restricted_qty.py b/stock_picking_return_restricted_qty/tests/test_stock_picking_return_restricted_qty.py new file mode 100644 index 000000000000..1d9b4c77ad5e --- /dev/null +++ b/stock_picking_return_restricted_qty/tests/test_stock_picking_return_restricted_qty.py @@ -0,0 +1,81 @@ +# Copyright 2020 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import UserError +from odoo.tests import Form, common + + +class StockPickingReturnRestrictedQtyTest(common.TransactionCase): + def setUp(self): + super().setUp() + partner = self.env["res.partner"].create({"name": "Test"}) + product = self.env["product.product"].create( + {"name": "test_product", "type": "product"} + ) + picking_type_out = self.env.ref("stock.picking_type_out") + stock_location = self.env.ref("stock.stock_location_stock") + customer_location = self.env.ref("stock.stock_location_customers") + self.picking = self.env["stock.picking"].create( + { + "partner_id": partner.id, + "picking_type_id": picking_type_out.id, + "location_id": stock_location.id, + "location_dest_id": customer_location.id, + "move_lines": [ + ( + 0, + 0, + { + "name": product.name, + "product_id": product.id, + "product_uom_qty": 20, + "product_uom": product.uom_id.id, + "location_id": stock_location.id, + "location_dest_id": customer_location.id, + }, + ) + ], + } + ) + self.picking.action_confirm() + self.picking.action_assign() + self.picking.move_lines[:1].quantity_done = 20 + self.picking.button_validate() + + def get_return_picking_wizard(self, picking): + stock_return_picking_form = Form( + self.env["stock.return.picking"].with_context( + active_ids=picking.ids, + active_id=picking.ids[0], + active_model="stock.picking", + ) + ) + return stock_return_picking_form.save() + + def test_return_not_allowed(self): + """On this test we create a return picking with more quantity + than the quantity that client have on his hand""" + return_picking = self.get_return_picking_wizard(self.picking) + self.assertEqual(return_picking.product_return_moves.quantity, 20) + return_picking.product_return_moves.quantity = 30 + with self.assertRaises(UserError): + return_picking._create_returns() + + def test_multiple_return(self): + """On this test we are going to follow a sequence that a client + can follow if he tries to return a product""" + wiz = self.get_return_picking_wizard(self.picking) + wiz.product_return_moves.quantity = 10 + picking_returned_id = wiz._create_returns()[0] + picking_returned = self.env["stock.picking"].browse(picking_returned_id) + + wiz = self.get_return_picking_wizard(self.picking) + self.assertEqual(wiz.product_return_moves.quantity, 10) + + picking_returned._action_done() + wiz = self.get_return_picking_wizard(self.picking) + self.assertEqual(wiz.product_return_moves.quantity, 10) + + wiz.product_return_moves.quantity = 80 + with self.assertRaises(UserError): + wiz.product_return_moves._onchange_quantity() diff --git a/stock_picking_return_restricted_qty/wizard/__init__.py b/stock_picking_return_restricted_qty/wizard/__init__.py new file mode 100644 index 000000000000..f8de18c1e06f --- /dev/null +++ b/stock_picking_return_restricted_qty/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import stock_picking_return diff --git a/stock_picking_return_restricted_qty/wizard/stock_picking_return.py b/stock_picking_return_restricted_qty/wizard/stock_picking_return.py new file mode 100644 index 000000000000..66054485893e --- /dev/null +++ b/stock_picking_return_restricted_qty/wizard/stock_picking_return.py @@ -0,0 +1,56 @@ +# Copyright 2020 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import UserError +from odoo.tools import float_compare + + +class ReturnPicking(models.TransientModel): + _inherit = "stock.return.picking" + + @api.model + def _prepare_stock_return_picking_line_vals_from_move(self, stock_move): + val = super()._prepare_stock_return_picking_line_vals_from_move(stock_move) + return_lines = self.env["stock.return.picking.line"] + val["quantity"] = return_lines.get_returned_restricted_quantity(stock_move) + return val + + def _create_returns(self): + precision = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + for return_line in self.product_return_moves: + quantity = return_line.get_returned_restricted_quantity(return_line.move_id) + if ( + float_compare( + return_line.quantity, quantity, precision_digits=precision + ) + > 0 + ): + raise UserError( + _("Return more quantities than delivered is not allowed.") + ) + return super()._create_returns() + + +class ReturnPickingLine(models.TransientModel): + _inherit = "stock.return.picking.line" + + @api.onchange("quantity") + def _onchange_quantity(self): + qty = self.get_returned_restricted_quantity(self.move_id) + if self.quantity > qty: + raise UserError(_("Return more quantities than delivered is not allowed.")) + + def get_returned_restricted_quantity(self, stock_move): + """This function is created to know how many products + have the person who tries to create a return picking + on his hand.""" + qty = stock_move.product_qty + for line in stock_move.move_dest_ids.mapped("move_line_ids"): + if line.state in {"partially_available", "assigned"}: + qty -= line.product_qty + elif line.state == "done": + qty -= line.qty_done + return max(qty, 0.0)