From e717280533e851cba9da90dd20137719befc2613 Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Tue, 10 Mar 2020 11:28:23 +0100 Subject: [PATCH 01/25] [ADD] stock_picking_return_restricted_qty New module --- .../README.rst | 85 ++++ .../__init__.py | 3 + .../__manifest__.py | 13 + .../i18n/es.po | 29 ++ .../stock_picking_return_restricted_qty.pot | 27 ++ .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 2 + .../readme/USAGE.rst | 4 + .../static/description/index.html | 434 ++++++++++++++++++ .../tests/__init__.py | 3 + ...est_stock_picking_return_restricted_qty.py | 77 ++++ .../wizard/__init__.py | 3 + .../wizard/stock_picking_return.py | 56 +++ 13 files changed, 740 insertions(+) create mode 100644 stock_picking_return_restricted_qty/README.rst create mode 100644 stock_picking_return_restricted_qty/__init__.py create mode 100644 stock_picking_return_restricted_qty/__manifest__.py create mode 100644 stock_picking_return_restricted_qty/i18n/es.po create mode 100644 stock_picking_return_restricted_qty/i18n/stock_picking_return_restricted_qty.pot create mode 100644 stock_picking_return_restricted_qty/readme/CONTRIBUTORS.rst create mode 100644 stock_picking_return_restricted_qty/readme/DESCRIPTION.rst create mode 100644 stock_picking_return_restricted_qty/readme/USAGE.rst create mode 100644 stock_picking_return_restricted_qty/static/description/index.html create mode 100644 stock_picking_return_restricted_qty/tests/__init__.py create mode 100644 stock_picking_return_restricted_qty/tests/test_stock_picking_return_restricted_qty.py create mode 100644 stock_picking_return_restricted_qty/wizard/__init__.py create mode 100644 stock_picking_return_restricted_qty/wizard/stock_picking_return.py 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..5338f740b37e --- /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": "13.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..f6a093ac71b7 --- /dev/null +++ b/stock_picking_return_restricted_qty/i18n/es.po @@ -0,0 +1,29 @@ +# 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" +"Language-Team: \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" +"Last-Translator: Carlos \n" +"Language: es\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 +#: 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..1ba357d8c48a --- /dev/null +++ b/stock_picking_return_restricted_qty/i18n/stock_picking_return_restricted_qty.pot @@ -0,0 +1,27 @@ +# 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 10:45+0000\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 +#: 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/index.html b/stock_picking_return_restricted_qty/static/description/index.html new file mode 100644 index 000000000000..dab31cb4cf3d --- /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..228507655fd3 --- /dev/null +++ b/stock_picking_return_restricted_qty/tests/test_stock_picking_return_restricted_qty.py @@ -0,0 +1,77 @@ +# 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 common + + +class StockPickingReturnRestrictedQtyTest(common.SavepointCase): + 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 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.env["stock.return.picking"].create( + {"picking_id": self.picking.id} + ) + return_picking._onchange_picking_id() + 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.env["stock.return.picking"].create({"picking_id": self.picking.id}) + wiz._onchange_picking_id() + 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.env["stock.return.picking"].create({"picking_id": self.picking.id}) + wiz._onchange_picking_id() + self.assertEqual(wiz.product_return_moves.quantity, 10) + + picking_returned.action_done() + wiz = self.env["stock.return.picking"].create({"picking_id": self.picking.id}) + wiz._onchange_picking_id() + 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..370210ece5e4 --- /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) From 18b730f4f8cb37041d5282d72ad1b9141f475e2f Mon Sep 17 00:00:00 2001 From: oca-travis Date: Thu, 16 Apr 2020 16:43:26 +0000 Subject: [PATCH 02/25] [UPD] Update stock_picking_return_restricted_qty.pot --- .../i18n/stock_picking_return_restricted_qty.pot | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 index 1ba357d8c48a..ba0b153a30ea 100644 --- 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 @@ -4,10 +4,8 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 13.0+e\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-09 10:45+0000\n" -"PO-Revision-Date: 2020-03-09 10:45+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -21,6 +19,12 @@ 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." From 7cb90c94b861ba258de1c3143c0d0b5c434f382e Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Thu, 16 Apr 2020 16:57:24 +0000 Subject: [PATCH 03/25] [UPD] README.rst --- .../static/description/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_picking_return_restricted_qty/static/description/index.html b/stock_picking_return_restricted_qty/static/description/index.html index dab31cb4cf3d..6ec5a3321058 100644 --- a/stock_picking_return_restricted_qty/static/description/index.html +++ b/stock_picking_return_restricted_qty/static/description/index.html @@ -3,7 +3,7 @@ - + Stock Picking Return Restricted Qty