diff --git a/rma_sale_lot/README.rst b/rma_sale_lot/README.rst new file mode 100644 index 000000000..bac91c966 --- /dev/null +++ b/rma_sale_lot/README.rst @@ -0,0 +1,84 @@ +============ +Rma Sale Lot +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b78509745350922121af05dc007a0cbd04294051b18538e0e52ba5ce0eb984c4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Frma-lightgray.png?logo=github + :target: https://github.com/OCA/rma/tree/16.0/rma_sale_lot + :alt: OCA/rma +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/rma-16-0/rma-16-0-rma_sale_lot + :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/rma&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the rma_lot module by integrating lot tracking into +the return wizard in the sales orders. It assists salespeople in +accurately recording returns by ensuring that customers are returning +the correct lot that was originally delivered. + +This enhancement improves both tracking and inventory accuracy, leading +to more efficient and reliable return processing. + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV +* BCIM + +Contributors +------------ + +- Jacques-Etienne Baudoux - BCIM je@bcim.be +- Souheil Bejaoui - ACSONE SA/NV souheil.bejaoui@acsone.eu + +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/rma `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/rma_sale_lot/__init__.py b/rma_sale_lot/__init__.py new file mode 100644 index 000000000..976591c99 --- /dev/null +++ b/rma_sale_lot/__init__.py @@ -0,0 +1,2 @@ +from . import wizards +from . import models diff --git a/rma_sale_lot/__manifest__.py b/rma_sale_lot/__manifest__.py new file mode 100644 index 000000000..6025d231d --- /dev/null +++ b/rma_sale_lot/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 ACSONE SA/NV,BCIM +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Rma Sale Lot", + "summary": """ + Manage sale returns with lot.""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,BCIM,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/rma", + "depends": ["rma_lot", "rma_sale"], + "data": ["wizards/sale_order_rma_wizard.xml"], + "demo": [], +} diff --git a/rma_sale_lot/models/__init__.py b/rma_sale_lot/models/__init__.py new file mode 100644 index 000000000..e7e9273fc --- /dev/null +++ b/rma_sale_lot/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order_line +from . import sale_order diff --git a/rma_sale_lot/models/sale_order.py b/rma_sale_lot/models/sale_order.py new file mode 100644 index 000000000..a117d1036 --- /dev/null +++ b/rma_sale_lot/models/sale_order.py @@ -0,0 +1,14 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrder(models.Model): + + _inherit = "sale.order" + + def _prepare_rma_wizard_line_vals(self, data): + vals = super()._prepare_rma_wizard_line_vals(data) + vals["lot_id"] = data.get("lot_id") + return vals diff --git a/rma_sale_lot/models/sale_order_line.py b/rma_sale_lot/models/sale_order_line.py new file mode 100644 index 000000000..c6f9a55b7 --- /dev/null +++ b/rma_sale_lot/models/sale_order_line.py @@ -0,0 +1,75 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from collections import defaultdict + +from odoo import models +from odoo.tools.float_utils import float_round + + +class SaleOrderLine(models.Model): + + _inherit = "sale.order.line" + + def _get_qty_done_by_product_lot(self, moves): + res = defaultdict(float) + for group in self.env["stock.move.line"].read_group( + [ + ("move_id", "in", moves.ids), + ("state", "=", "done"), + ("move_id.scrapped", "=", False), + ], + ["qty_done:sum"], + ["product_id", "lot_id"], + lazy=False, + ): + lot_id = group.get("lot_id")[0] if group.get("lot_id") else False + product_id = group.get("product_id")[0] + qty_done = group.get("qty_done") + res[(product_id, lot_id)] += qty_done + return res + + def prepare_sale_rma_data(self): + self.ensure_one() + if self.product_id.type not in ["product", "consu"]: + return {} + if not self.product_id.tracking or self.product_id.tracking == "none": + return super().prepare_sale_rma_data() + moves = self.get_delivery_move() + data = [] + qty_done_by_product_lot = self._get_qty_done_by_product_lot(moves) + for (product_id, lot_id), qty_done in qty_done_by_product_lot.items(): + data.append( + self._prepare_sale_rma_data_line(moves, product_id, lot_id, qty_done) + ) + return data + + def _prepare_sale_rma_data_line(self, moves, product_id, lot_id, qty_done): + moves = moves.move_line_ids.filtered( + lambda ml, p_id=product_id, l_id=lot_id: ml.product_id.id == p_id + and ml.lot_id.id == l_id + ).move_id + quantity = qty_done + for returned_move in moves.returned_move_ids.filtered( + lambda r: r.state in ["partially_available", "assigned", "done"] + ): + if ( + returned_move.restrict_lot_id + and returned_move.restrict_lot_id.id == lot_id + or not lot_id + ): + if returned_move.state in ("partially_available", "assigned"): + quantity -= sum(returned_move.move_line_ids.mapped("reserved_qty")) + elif returned_move.state == "done": + quantity -= returned_move.product_qty + quantity = float_round( + quantity, precision_rounding=moves.product_id.uom_id.rounding + ) + return { + "product": moves.product_id, + "quantity": quantity, + "uom": moves.product_uom, + "picking": moves.picking_id[0], + "sale_line_id": self, + "lot_id": lot_id, + } diff --git a/rma_sale_lot/readme/CONTRIBUTORS.md b/rma_sale_lot/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..0d74d13b4 --- /dev/null +++ b/rma_sale_lot/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Jacques-Etienne Baudoux - BCIM +- Souheil Bejaoui - ACSONE SA/NV \ No newline at end of file diff --git a/rma_sale_lot/readme/DESCRIPTION.md b/rma_sale_lot/readme/DESCRIPTION.md new file mode 100644 index 000000000..fc2a778bb --- /dev/null +++ b/rma_sale_lot/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module extends the rma_lot module by integrating lot tracking into the +return wizard in the sales orders. It assists salespeople in accurately +recording returns by ensuring that customers are returning the correct lot that +was originally delivered. + +This enhancement improves both tracking and inventory accuracy, leading to +more efficient and reliable return processing. diff --git a/rma_sale_lot/static/description/icon.png b/rma_sale_lot/static/description/icon.png new file mode 100644 index 000000000..e69de29bb diff --git a/rma_sale_lot/static/description/index.html b/rma_sale_lot/static/description/index.html new file mode 100644 index 000000000..f6162af29 --- /dev/null +++ b/rma_sale_lot/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Rma Sale Lot + + + +
+

Rma Sale Lot

+ + +

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

+

This module extends the rma_lot module by integrating lot tracking into +the return wizard in the sales orders. It assists salespeople in +accurately recording returns by ensuring that customers are returning +the correct lot that was originally delivered.

+

This enhancement improves both tracking and inventory accuracy, leading +to more efficient and reliable return processing.

+

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

+

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

+
+
+

Credits

+
+

Authors

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

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

+

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

+
+
+
+ + diff --git a/rma_sale_lot/tests/__init__.py b/rma_sale_lot/tests/__init__.py new file mode 100644 index 000000000..c65ce3d57 --- /dev/null +++ b/rma_sale_lot/tests/__init__.py @@ -0,0 +1 @@ +from . import test_rma_sale_lot diff --git a/rma_sale_lot/tests/test_rma_sale_lot.py b/rma_sale_lot/tests/test_rma_sale_lot.py new file mode 100644 index 000000000..31e0d954f --- /dev/null +++ b/rma_sale_lot/tests/test_rma_sale_lot.py @@ -0,0 +1,66 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.rma_sale.tests.test_rma_sale import TestRmaSaleBase + + +class TestRmaSaleLot(TestRmaSaleBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env["product.product"].create( + {"name": "test_product", "type": "product", "tracking": "lot"} + ) + cls.lot_1 = cls.env["stock.lot"].create( + {"name": "000001", "product_id": cls.product.id} + ) + cls.lot_2 = cls.env["stock.lot"].create( + {"name": "000002", "product_id": cls.product.id} + ) + stock_location = cls.env.ref("stock.stock_location_stock") + cls.env["stock.quant"]._update_available_quantity( + cls.product, stock_location, 1, lot_id=cls.lot_1 + ) + cls.env["stock.quant"]._update_available_quantity( + cls.product, stock_location, 2, lot_id=cls.lot_2 + ) + cls.sale_order = cls._create_sale_order(cls, [[cls.product, 3]]) + cls.sale_order.action_confirm() + cls.order_line = cls.sale_order.order_line + cls.order_out_picking = cls.sale_order.picking_ids + cls.order_out_picking.action_set_quantities_to_reservation() + cls.order_out_picking._action_done() + cls.operation = cls.env.ref("rma.rma_operation_replace") + + def test_partial_return(self): + wizard = self._rma_sale_wizard(self.sale_order) + line_1 = wizard.line_ids.filtered( + lambda line, lot=self.lot_1: line.lot_id == lot + ) + line_2 = wizard.line_ids.filtered( + lambda line, lot=self.lot_2: line.lot_id == lot + ) + self.assertEqual(line_1.quantity, 1) + self.assertEqual(line_2.quantity, 2) + line_2.quantity = 1 + rma = self.env["rma"].search(wizard.create_and_open_rma()["domain"]) + rma_1 = rma.filtered(lambda r, lot=self.lot_1: r.lot_id == lot) + rma_2 = rma.filtered(lambda r, lot=self.lot_2: r.lot_id == lot) + self.assertEqual(rma_1.reception_move_id.restrict_lot_id, self.lot_1) + self.assertEqual(rma_2.reception_move_id.restrict_lot_id, self.lot_2) + self.assertEqual(rma_2.product_uom_qty, 1) + + def test_full_return_after_partial_return(self): + self.test_partial_return() + wizard = self._rma_sale_wizard(self.sale_order) + line_1 = wizard.line_ids.filtered( + lambda line, lot=self.lot_1: line.lot_id == lot + ) + line_2 = wizard.line_ids.filtered( + lambda line, lot=self.lot_2: line.lot_id == lot + ) + self.assertEqual(line_1.quantity, 0) + self.assertEqual(line_2.quantity, 1) + rma_2 = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"]) + self.assertEqual(rma_2.reception_move_id.restrict_lot_id, self.lot_2) + self.assertEqual(rma_2.product_uom_qty, 1) diff --git a/rma_sale_lot/wizards/__init__.py b/rma_sale_lot/wizards/__init__.py new file mode 100644 index 000000000..dca5a8b16 --- /dev/null +++ b/rma_sale_lot/wizards/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order_rma_wizard +from . import sale_order_line_rma_wizard diff --git a/rma_sale_lot/wizards/sale_order_line_rma_wizard.py b/rma_sale_lot/wizards/sale_order_line_rma_wizard.py new file mode 100644 index 000000000..ff50d2e08 --- /dev/null +++ b/rma_sale_lot/wizards/sale_order_line_rma_wizard.py @@ -0,0 +1,23 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrderLineRmaWizard(models.TransientModel): + + _inherit = "sale.order.line.rma.wizard" + + lot_id = fields.Many2one(comodel_name="stock.lot", string="Lot/Serial Number") + lots_visible = fields.Boolean(compute="_compute_lots_visible") + + @api.depends("product_id.tracking") + def _compute_lots_visible(self): + for rec in self: + rec.lots_visible = rec.product_id.tracking != "none" + + def _prepare_rma_values(self): + self.ensure_one() + values = super()._prepare_rma_values() + values["lot_id"] = self.lot_id.id + return values diff --git a/rma_sale_lot/wizards/sale_order_rma_wizard.py b/rma_sale_lot/wizards/sale_order_rma_wizard.py new file mode 100644 index 000000000..bdbf914ef --- /dev/null +++ b/rma_sale_lot/wizards/sale_order_rma_wizard.py @@ -0,0 +1,9 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrderRmaWizard(models.TransientModel): + + _inherit = "sale.order.rma.wizard" diff --git a/rma_sale_lot/wizards/sale_order_rma_wizard.xml b/rma_sale_lot/wizards/sale_order_rma_wizard.xml new file mode 100644 index 000000000..4a45e331f --- /dev/null +++ b/rma_sale_lot/wizards/sale_order_rma_wizard.xml @@ -0,0 +1,23 @@ + + + + + + sale.order.rma.wizard + + + + + + + + + + + + diff --git a/setup/rma_sale_lot/odoo/addons/rma_sale_lot b/setup/rma_sale_lot/odoo/addons/rma_sale_lot new file mode 120000 index 000000000..682ac8117 --- /dev/null +++ b/setup/rma_sale_lot/odoo/addons/rma_sale_lot @@ -0,0 +1 @@ +../../../../rma_sale_lot \ No newline at end of file diff --git a/setup/rma_sale_lot/setup.py b/setup/rma_sale_lot/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/rma_sale_lot/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)