diff --git a/rma_lot/README.rst b/rma_lot/README.rst new file mode 100644 index 000000000..d473ba7c1 --- /dev/null +++ b/rma_lot/README.rst @@ -0,0 +1,93 @@ +======= +Rma Lot +======= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:179ae979736d64a8afa520769acb7d060690a304e812587c70bf43b4542d2ea6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_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_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| + +Tracking returned products by lot or serial number is crucial for +businesses that require precise monitoring, especially in industries +where quality control, compliance, and inventory accuracy are critical. +By enabling returns to be tracked by lot or serial numbers, this module +ensures that each returned item is handled correctly, reducing the risk +of errors, fraud, or compliance issues. + +This level of detail is essential for maintaining the integrity of +inventory records, meeting regulatory requirements, and providing +excellent customer service. + +The module extends the existing RMA functionality by adding a lot field +to the RMA model, allowing users to associate returns with specific lot +or serial numbers. This enhancement enforces stricter controls over +return processes, ensuring that only the correct items are accepted +during a return and that inventory records remain accurate. + +**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_lot/__init__.py b/rma_lot/__init__.py new file mode 100644 index 000000000..aee8895e7 --- /dev/null +++ b/rma_lot/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/rma_lot/__manifest__.py b/rma_lot/__manifest__.py new file mode 100644 index 000000000..55c32a6fd --- /dev/null +++ b/rma_lot/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Rma Lot", + "summary": """ + Manage lot in RMA""", + "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", "stock_picking_return_lot"], + "data": ["views/rma.xml"], + "demo": [], +} diff --git a/rma_lot/models/__init__.py b/rma_lot/models/__init__.py new file mode 100644 index 000000000..0031f431f --- /dev/null +++ b/rma_lot/models/__init__.py @@ -0,0 +1 @@ +from . import rma diff --git a/rma_lot/models/rma.py b/rma_lot/models/rma.py new file mode 100644 index 000000000..55d18a984 --- /dev/null +++ b/rma_lot/models/rma.py @@ -0,0 +1,41 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class Rma(models.Model): + + _inherit = "rma" + + lot_id = fields.Many2one( + comodel_name="stock.lot", + string="Lot/Serial Number", + domain="[('product_id', '=?', product_id)]", + compute="_compute_lot_id", + store=True, + readonly=False, + ) + 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_reception_procurement_vals(self, group=None): + vals = super()._prepare_reception_procurement_vals(group=group) + vals["restrict_lot_id"] = self.lot_id.id + return vals + + @api.depends("move_id", "lot_id") + def _compute_product_id(self): + res = super()._compute_product_id() + for rec in self: + if not rec.move_id and rec.lot_id: + self.product_id = rec.lot_id.product_id + return res + + @api.depends("product_id") + def _compute_lot_id(self): + self.update({"lot_id": False}) diff --git a/rma_lot/readme/CONTRIBUTORS.md b/rma_lot/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..0d74d13b4 --- /dev/null +++ b/rma_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_lot/readme/DESCRIPTION.md b/rma_lot/readme/DESCRIPTION.md new file mode 100644 index 000000000..637ea4605 --- /dev/null +++ b/rma_lot/readme/DESCRIPTION.md @@ -0,0 +1,15 @@ +Tracking returned products by lot or serial number is crucial for businesses +that require precise monitoring, especially in industries where quality control, +compliance, and inventory accuracy are critical. +By enabling returns to be tracked by lot or serial numbers, this module ensures +that each returned item is handled correctly, reducing the risk of errors, +fraud, or compliance issues. + +This level of detail is essential for maintaining the integrity of inventory +records, meeting regulatory requirements, and providing excellent customer service. + +The module extends the existing RMA functionality by adding a lot field to the +RMA model, allowing users to associate returns with specific lot or serial numbers. +This enhancement enforces stricter controls over return processes, +ensuring that only the correct items are accepted during a return and that +inventory records remain accurate. diff --git a/rma_lot/static/description/icon.png b/rma_lot/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/rma_lot/static/description/icon.png differ diff --git a/rma_lot/static/description/index.html b/rma_lot/static/description/index.html new file mode 100644 index 000000000..78f04070d --- /dev/null +++ b/rma_lot/static/description/index.html @@ -0,0 +1,435 @@ + + + + + +Rma Lot + + + +
+

Rma Lot

+ + +

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

+

Tracking returned products by lot or serial number is crucial for +businesses that require precise monitoring, especially in industries +where quality control, compliance, and inventory accuracy are critical. +By enabling returns to be tracked by lot or serial numbers, this module +ensures that each returned item is handled correctly, reducing the risk +of errors, fraud, or compliance issues.

+

This level of detail is essential for maintaining the integrity of +inventory records, meeting regulatory requirements, and providing +excellent customer service.

+

The module extends the existing RMA functionality by adding a lot field +to the RMA model, allowing users to associate returns with specific lot +or serial numbers. This enhancement enforces stricter controls over +return processes, ensuring that only the correct items are accepted +during a return and that inventory records remain accurate.

+

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_lot/tests/__init__.py b/rma_lot/tests/__init__.py new file mode 100644 index 000000000..25cf26216 --- /dev/null +++ b/rma_lot/tests/__init__.py @@ -0,0 +1 @@ +from . import test_rma_lot diff --git a/rma_lot/tests/test_rma_lot.py b/rma_lot/tests/test_rma_lot.py new file mode 100644 index 000000000..7f16241b9 --- /dev/null +++ b/rma_lot/tests/test_rma_lot.py @@ -0,0 +1,103 @@ +# Copyright 2020 Iryna Vyshnevska Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import Command +from odoo.tests.common import Form, TransactionCase + + +class TestRMALot(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.picking_obj = cls.env["stock.picking"] + partner = cls.env["res.partner"].create({"name": "Test"}) + 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} + ) + picking_type_out = cls.env.ref("stock.picking_type_out") + stock_location = cls.env.ref("stock.stock_location_stock") + customer_location = cls.env.ref("stock.stock_location_customers") + 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.picking = cls.picking_obj.create( + { + "partner_id": partner.id, + "picking_type_id": picking_type_out.id, + "location_id": stock_location.id, + "location_dest_id": customer_location.id, + "move_ids": [ + Command.create( + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_uom_qty": 3, + "product_uom": cls.product.uom_id.id, + "location_id": stock_location.id, + "location_dest_id": customer_location.id, + }, + ) + ], + } + ) + cls.picking.action_confirm() + cls.picking.action_assign() + cls.picking.action_set_quantities_to_reservation() + cls.picking._action_done() + cls.operation = cls.env.ref("rma.rma_operation_replace") + + @classmethod + def create_return_wiz(cls): + return ( + cls.env["stock.return.picking"] + .with_context(active_id=cls.picking.id, active_model="stock.picking") + .create({"create_rma": True}) + ) + + def test_00(self): + """ + Check the process of creating RMAs when returning products tracked by lot + - The correct number of RMAs is created + - The RMAs are correctly associated with the lot + """ + stock_return_picking_form = Form( + self.env["stock.return.picking"].with_context( + active_ids=self.picking.ids, + active_id=self.picking.id, + active_model="stock.picking", + ) + ) + stock_return_picking_form.create_rma = True + stock_return_picking_form.rma_operation_id = self.operation + return_wizard = stock_return_picking_form.save() + self.assertEqual(len(return_wizard.product_return_moves), 2) + return_wizard.create_returns() + self.assertEqual(self.picking.rma_count, 2) + rmas = self.picking.move_ids.rma_ids + rma_lot_1 = rmas.filtered(lambda r, lot=self.lot_1: r.lot_id == lot) + rma_lot_2 = rmas.filtered(lambda r, lot=self.lot_2: r.lot_id == lot) + self.assertTrue(rma_lot_1) + self.assertEqual(rma_lot_1.reception_move_id.restrict_lot_id, self.lot_1) + self.assertEqual(rma_lot_1.reception_move_id.state, "assigned") + self.assertEqual(rma_lot_1.reception_move_id.move_line_ids.lot_id, self.lot_1) + self.assertTrue(rma_lot_2) + self.assertEqual(rma_lot_2.reception_move_id.restrict_lot_id, self.lot_2) + self.assertEqual(rma_lot_2.reception_move_id.state, "assigned") + self.assertEqual(rma_lot_2.reception_move_id.move_line_ids.lot_id, self.lot_2) + + def test_rma_form(self): + rma_form = Form(self.env["rma"]) + self.assertFalse(rma_form.product_id) + rma_form.lot_id = self.lot_1 + self.assertEqual(rma_form.product_id, self.product) + rma_form.product_id = self.env.ref("product.product_product_4") + self.assertFalse(rma_form.lot_id) diff --git a/rma_lot/views/rma.xml b/rma_lot/views/rma.xml new file mode 100644 index 000000000..45dbfaeac --- /dev/null +++ b/rma_lot/views/rma.xml @@ -0,0 +1,41 @@ + + + + + + rma + + + + + + + + + + + rma + + + + + + + + + + rma + + + + + + + + + diff --git a/rma_lot/wizards/__init__.py b/rma_lot/wizards/__init__.py new file mode 100644 index 000000000..2ed06ea13 --- /dev/null +++ b/rma_lot/wizards/__init__.py @@ -0,0 +1 @@ +from . import stock_return_picking_line diff --git a/rma_lot/wizards/stock_return_picking_line.py b/rma_lot/wizards/stock_return_picking_line.py new file mode 100644 index 000000000..f96353b87 --- /dev/null +++ b/rma_lot/wizards/stock_return_picking_line.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 StockReturnPickingLine(models.TransientModel): + + _inherit = "stock.return.picking.line" + + def _prepare_rma_vals(self): + vals = super()._prepare_rma_vals() + vals.update({"lot_id": self.lot_id.id}) + return vals 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..8efcbacda --- /dev/null +++ b/rma_sale_lot/wizards/__init__.py @@ -0,0 +1 @@ +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.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_lot/odoo/addons/rma_lot b/setup/rma_lot/odoo/addons/rma_lot new file mode 120000 index 000000000..d1c73ea9f --- /dev/null +++ b/setup/rma_lot/odoo/addons/rma_lot @@ -0,0 +1 @@ +../../../../rma_lot \ No newline at end of file diff --git a/setup/rma_lot/setup.py b/setup/rma_lot/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/rma_lot/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) 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, +)