From 59a1acd0f114f2d3877b1e294876bc88b3076300 Mon Sep 17 00:00:00 2001 From: Yoshi Tashiro Date: Wed, 27 Jan 2021 14:45:14 +0800 Subject: [PATCH] [IMP] stock_quant_manual_assign: make quant search flexible This is to make it easier to manipulate with the domain conditions and search results for available quants. --- .../wizard/assign_manual_quants.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index 88bb41c90..273f4f113 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -69,17 +69,24 @@ class AssignManualQuants(models.TransientModel): move.mapped("picking_id")._compute_state() return {} + @api.model + def _domain_for_available_quants(self, move): + return [ + ("location_id", "child_of", move.location_id.id), + ("product_id", "=", move.product_id.id), + ("quantity", ">", 0), + ] + + @api.model + def _get_available_quants(self, move): + domain = self._domain_for_available_quants(move) + return self.env["stock.quant"].search(domain) + @api.model def default_get(self, fields): res = super(AssignManualQuants, self).default_get(fields) move = self.env["stock.move"].browse(self.env.context["active_id"]) - available_quants = self.env["stock.quant"].search( - [ - ("location_id", "child_of", move.location_id.id), - ("product_id", "=", move.product_id.id), - ("quantity", ">", 0), - ] - ) + available_quants = self._get_available_quants(move) q_lines = [] for quant in available_quants: line = self._prepare_wizard_line(move, quant)