diff --git a/rma_filter_lot/README.rst b/rma_filter_lot/README.rst new file mode 100644 index 00000000..e36debc6 --- /dev/null +++ b/rma_filter_lot/README.rst @@ -0,0 +1,37 @@ +============== +RMA Filter Lot +============== + +Filter RMA lots in customer RMA to only allow lots sent to customer. + +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 S.L. + +Contributors +~~~~~~~~~~~~ + +* Mateu Griful +* Lois Rilo + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the ForgeFlow. + +This module is part of the `ForgeFlow/stock-rma `_ project on GitHub. + diff --git a/rma_filter_lot/__init__.py b/rma_filter_lot/__init__.py new file mode 100644 index 00000000..e6d259b1 --- /dev/null +++ b/rma_filter_lot/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2021 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from . import models diff --git a/rma_filter_lot/__manifest__.py b/rma_filter_lot/__manifest__.py new file mode 100644 index 00000000..c7366a60 --- /dev/null +++ b/rma_filter_lot/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2021 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +{ + "name": "RMA Filter Lot", + "version": "15.0.1.0.0", + "license": "LGPL-3", + "category": "RMA", + "summary": "Filter RMA lots", + "author": "ForgeFlow", + "website": "https://github.com/ForgeFlow/stock-rma", + "depends": ["rma"], + "data": [ + "views/rma_order_view.xml", + ], + "installable": True, +} diff --git a/rma_filter_lot/models/__init__.py b/rma_filter_lot/models/__init__.py new file mode 100644 index 00000000..0ec42a97 --- /dev/null +++ b/rma_filter_lot/models/__init__.py @@ -0,0 +1 @@ +from . import rma_order_line diff --git a/rma_filter_lot/models/rma_order_line.py b/rma_filter_lot/models/rma_order_line.py new file mode 100644 index 00000000..d3283271 --- /dev/null +++ b/rma_filter_lot/models/rma_order_line.py @@ -0,0 +1,47 @@ +# Copyright 2021 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import api, fields, models +from odoo.tools import float_compare + + +class RmaOrderLine(models.Model): + _inherit = "rma.order.line" + + lot_id = fields.Many2one( + domain="[('id', 'in', valid_lot_ids)]", + ) + valid_lot_ids = fields.One2many( + comodel_name="stock.production.lot", + compute="_compute_domain_lot_ids", + ) + + @api.depends("product_id") + def _compute_domain_lot_ids(self): + for rec in self: + lots = rec.env["stock.production.lot"].search( + [("product_id", "=", rec.product_id.id)] + ) + if ( + lots + and rec.type == "customer" + and rec.product_id + and rec.product_id.tracking != "none" + ): + valid_ids = self.env["stock.production.lot"] + for quant in rec.product_id.stock_quant_ids: + if ( + float_compare(quant.available_quantity, 0.0, precision_digits=2) + > 0 + and quant.location_id.usage == "customer" + and quant.lot_id + ): + valid_ids |= quant.lot_id + if valid_ids: + lots = valid_ids + rec.valid_lot_ids = lots + + def _onchange_product_id(self): + super()._onchange_product_id() + # Override domain added in base `rma` module. + return {"domain": {"lot_id": [("id", "in", self.valid_lot_ids.ids)]}} diff --git a/rma_filter_lot/readme/CONTRIBUTORS.rst b/rma_filter_lot/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..087dd292 --- /dev/null +++ b/rma_filter_lot/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Mateu Griful +* Lois Rilo diff --git a/rma_filter_lot/readme/DESCRIPTION.rst b/rma_filter_lot/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c6c49173 --- /dev/null +++ b/rma_filter_lot/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module filters the lots in the rma by searching if there are units of the selected product in any customer +location in order to ease the search. diff --git a/rma_filter_lot/views/rma_order_view.xml b/rma_filter_lot/views/rma_order_view.xml new file mode 100644 index 00000000..cef3c835 --- /dev/null +++ b/rma_filter_lot/views/rma_order_view.xml @@ -0,0 +1,13 @@ + + + + rma.order.line.form + rma.order.line + + + + + + + + diff --git a/setup/rma_filter_lot/odoo/addons/rma_filter_lot b/setup/rma_filter_lot/odoo/addons/rma_filter_lot new file mode 120000 index 00000000..7e5b7be6 --- /dev/null +++ b/setup/rma_filter_lot/odoo/addons/rma_filter_lot @@ -0,0 +1 @@ +../../../../rma_filter_lot \ No newline at end of file diff --git a/setup/rma_filter_lot/setup.py b/setup/rma_filter_lot/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/rma_filter_lot/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)