[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.
This commit is contained in:
Yoshi Tashiro
2021-01-27 14:45:14 +08:00
committed by Alexis de Lattre
parent 6b81ad9496
commit 80b596a237

View File

@@ -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)