diff --git a/rma_filter_lot/README.rst b/rma_filter_lot/README.rst index e36debc6..f30b5a16 100644 --- a/rma_filter_lot/README.rst +++ b/rma_filter_lot/README.rst @@ -27,6 +27,7 @@ Contributors * Mateu Griful * Lois Rilo +* Jordi Ballester Maintainers ~~~~~~~~~~~ diff --git a/rma_filter_lot/__manifest__.py b/rma_filter_lot/__manifest__.py index 3773e24d..09754d92 100644 --- a/rma_filter_lot/__manifest__.py +++ b/rma_filter_lot/__manifest__.py @@ -3,15 +3,13 @@ { "name": "RMA Filter Lot", - "version": "14.0.1.0.0", + "version": "14.0.1.1.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", - ], + "data": ["views/rma_order_view.xml"], "installable": True, } diff --git a/rma_filter_lot/models/rma_order_line.py b/rma_filter_lot/models/rma_order_line.py index d3283271..3dcd5913 100644 --- a/rma_filter_lot/models/rma_order_line.py +++ b/rma_filter_lot/models/rma_order_line.py @@ -16,7 +16,20 @@ class RmaOrderLine(models.Model): compute="_compute_domain_lot_ids", ) - @api.depends("product_id") + def _get_filter_lot_customer_domain(self): + self.ensure_one() + return [ + ("location_dest_id.usage", "=", "customer"), + ("product_id", "=", self.product_id.id), + ("state", "=", "done"), + ( + "move_id.partner_id", + "child_of", + self.partner_id.commercial_partner_id.ids, + ), + ] + + @api.depends("product_id", "operation_id") def _compute_domain_lot_ids(self): for rec in self: lots = rec.env["stock.production.lot"].search( @@ -39,6 +52,14 @@ class RmaOrderLine(models.Model): valid_ids |= quant.lot_id if valid_ids: lots = valid_ids + # Check if the lot has ever been shipped to that customer. + # In that case restrict to those. + mls = rec.env["stock.move.line"].search( + rec._get_filter_lot_customer_domain() + ) + moved_lots = mls.mapped("lot_id") + if moved_lots: + lots = lots.filtered(lambda l: l in moved_lots) rec.valid_lot_ids = lots def _onchange_product_id(self): diff --git a/rma_filter_lot/views/rma_order_view.xml b/rma_filter_lot/views/rma_order_view.xml index cef3c835..f846026a 100644 --- a/rma_filter_lot/views/rma_order_view.xml +++ b/rma_filter_lot/views/rma_order_view.xml @@ -1,4 +1,3 @@ - rma.order.line.form