diff --git a/sale_line_returned_qty/README.rst b/sale_line_returned_qty/README.rst new file mode 100644 index 000000000000..1648e996aa51 --- /dev/null +++ b/sale_line_returned_qty/README.rst @@ -0,0 +1,75 @@ +====================== +Sale Line Returned 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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-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/16.0/sale_line_returned_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-16-0/stock-logistics-workflow-16-0-sale_line_returned_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/16.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the returned quantity of sale order lines as a computed field. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~~~~~~ + +* `ForgeFlow `_: + + * Jordi Masvidal + +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/sale_line_returned_qty/__init__.py b/sale_line_returned_qty/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/sale_line_returned_qty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_line_returned_qty/__manifest__.py b/sale_line_returned_qty/__manifest__.py new file mode 100644 index 000000000000..da1fbee0365f --- /dev/null +++ b/sale_line_returned_qty/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Sale Line Returned Qty", + "summary": "Track returned quantity of sale order lines.", + "version": "16.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/stock-logistics-workflow", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "LGPL-3", + "installable": True, + "depends": ["sale_stock"], + "data": ["views/sale_order_views.xml"], +} diff --git a/sale_line_returned_qty/i18n/sale_line_returned_qty.pot b/sale_line_returned_qty/i18n/sale_line_returned_qty.pot new file mode 100644 index 000000000000..455e8baa97d8 --- /dev/null +++ b/sale_line_returned_qty/i18n/sale_line_returned_qty.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_line_returned_qty +# +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: sale_line_returned_qty +#: model_terms:ir.ui.view,arch_db:sale_line_returned_qty.view_order_form +msgid "Returned" +msgstr "" + +#. module: sale_line_returned_qty +#: model:ir.model.fields,field_description:sale_line_returned_qty.field_sale_order_line__qty_returned +msgid "Returned Qty" +msgstr "" + +#. module: sale_line_returned_qty +#: model:ir.model,name:sale_line_returned_qty.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/sale_line_returned_qty/models/__init__.py b/sale_line_returned_qty/models/__init__.py new file mode 100644 index 000000000000..8eb9d1d40467 --- /dev/null +++ b/sale_line_returned_qty/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order_line diff --git a/sale_line_returned_qty/models/sale_order_line.py b/sale_line_returned_qty/models/sale_order_line.py new file mode 100644 index 000000000000..8a788fa1b57c --- /dev/null +++ b/sale_line_returned_qty/models/sale_order_line.py @@ -0,0 +1,40 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + qty_returned = fields.Float( + compute="_compute_qty_returned", + string="Returned Qty", + store=True, + readonly=True, + compute_sudo=True, + digits="Product Unit of Measure", + default=0.0, + copy=False, + ) + + @api.depends( + "move_ids.state", + "move_ids.scrapped", + "move_ids.product_uom_qty", + "move_ids.product_uom", + ) + def _compute_qty_returned(self): + for line in self: + qty = 0.0 + if line.qty_delivered_method == "stock_move": + _, incoming_moves = line._get_outgoing_incoming_moves() + for move in incoming_moves: + if move.state != "done": + continue + qty += move.product_uom._compute_quantity( + move.product_uom_qty, + line.product_uom, + rounding_method="HALF-UP", + ) + line.qty_returned = qty diff --git a/sale_line_returned_qty/readme/CONTRIBUTORS.rst b/sale_line_returned_qty/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..9a27457986db --- /dev/null +++ b/sale_line_returned_qty/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `ForgeFlow `_: + + * Jordi Masvidal + * Pau Sanchez (pau.sanchez@qubiq.es) diff --git a/sale_line_returned_qty/readme/DESCRIPTION.rst b/sale_line_returned_qty/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..6b9af115eb32 --- /dev/null +++ b/sale_line_returned_qty/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds the quantity returned field in the lines of the sale. The quantity appears if a return delivery note is created and validated. diff --git a/sale_line_returned_qty/static/description/icon.png b/sale_line_returned_qty/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/sale_line_returned_qty/static/description/icon.png differ diff --git a/sale_line_returned_qty/static/description/index.html b/sale_line_returned_qty/static/description/index.html new file mode 100644 index 000000000000..5608135495d4 --- /dev/null +++ b/sale_line_returned_qty/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +Sale Line Returned Qty + + + +
+

Sale Line Returned Qty

+ + +

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

+

This module adds the returned quantity of sale order lines as a computed field.

+

Table of contents

+ +
+

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/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/sale_line_returned_qty/tests/__init__.py b/sale_line_returned_qty/tests/__init__.py new file mode 100644 index 000000000000..3b610fe54a0d --- /dev/null +++ b/sale_line_returned_qty/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_line_returned_qty diff --git a/sale_line_returned_qty/tests/test_sale_line_returned_qty.py b/sale_line_returned_qty/tests/test_sale_line_returned_qty.py new file mode 100644 index 000000000000..4ecfda9c55e2 --- /dev/null +++ b/sale_line_returned_qty/tests/test_sale_line_returned_qty.py @@ -0,0 +1,65 @@ +# Copyright 2022 ForgeFlow (http://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo.tests import Form, common + + +class TestSaleLineReturnedQty(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.product = cls.env["product.product"].create( + {"name": "test", "type": "product"} + ) + cls.env["stock.quant"].create( + { + "product_id": cls.product.id, + "location_id": cls.warehouse.lot_stock_id.id, + "quantity": 100, + } + ) + cls.partner = cls.env["res.partner"].create({"name": "test - partner"}) + order_form = Form(cls.env["sale.order"]) + order_form.partner_id = cls.partner + with order_form.order_line.new() as line_form: + line_form.product_id = cls.product + line_form.product_uom_qty = 10 + line_form.price_unit = 1000 + cls.order = order_form.save() + + def _return_picking(self, picking, qty, to_refund=True): + """Helper method to create a return of the original picking. It could + be refundable or not""" + return_wiz_form = Form( + self.env["stock.return.picking"].with_context( + active_ids=picking.ids, + active_id=picking.ids[0], + active_model="stock.picking", + ) + ) + return_wiz = return_wiz_form.save() + return_wiz.product_return_moves.quantity = qty + return_wiz.product_return_moves.to_refund = to_refund + res = return_wiz.create_returns() + return_picking = self.env["stock.picking"].browse(res["res_id"]) + self._validate_picking(return_picking) + + def _validate_picking(self, picking): + """Helper method to confirm the pickings""" + for line in picking.move_ids: + line.quantity_done = line.product_uom_qty + picking._action_done() + + def test_returned_qty(self): + self.order.action_confirm() + so_line = self.order.order_line[0] + self.assertEqual(so_line.qty_returned, 0.0) + # Partial delivery one + picking = self.order.picking_ids + picking.action_assign() + picking.move_ids.quantity_done = 10.0 + picking._action_done() + self.assertEqual(so_line.qty_returned, 0.0) + # Make a return for 5 units + self._return_picking(picking, 5.0, to_refund=True) + self.assertEqual(so_line.qty_returned, 5.0) diff --git a/sale_line_returned_qty/views/sale_order_views.xml b/sale_line_returned_qty/views/sale_order_views.xml new file mode 100644 index 000000000000..1e608ca91619 --- /dev/null +++ b/sale_line_returned_qty/views/sale_order_views.xml @@ -0,0 +1,41 @@ + + + + + sale.order.form - sale_line_returned_qty + sale.order + + + + + + + + + + diff --git a/setup/sale_line_returned_qty/odoo/addons/sale_line_returned_qty b/setup/sale_line_returned_qty/odoo/addons/sale_line_returned_qty new file mode 120000 index 000000000000..cdfe120d9b79 --- /dev/null +++ b/setup/sale_line_returned_qty/odoo/addons/sale_line_returned_qty @@ -0,0 +1 @@ +../../../../sale_line_returned_qty \ No newline at end of file diff --git a/setup/sale_line_returned_qty/setup.py b/setup/sale_line_returned_qty/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/sale_line_returned_qty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)