[FIX] mrp: open component quantity for kit

The 'On Hand' button triggers action_open_quants on product model. It
do not explode the kit into its component

closes odoo/odoo#62390

X-original-commit: 49b965eb1ec6a7ec6c07fa643cc6ae35ee8b5d91
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
William Henrotin
2020-11-26 11:33:00 +00:00
parent 31b2c5925f
commit bebe4bd591
3 changed files with 19 additions and 3 deletions
+15
View File
@@ -205,3 +205,18 @@ class ProductProduct(models.Model):
action = self.product_tmpl_id.action_view_mos()
action['domain'] = [('state', '=', 'done'), ('product_id', 'in', self.ids)]
return action
def action_open_quants(self):
bom_kits = {}
for product in self:
bom = self.env['mrp.bom']._bom_find(product=product, bom_type='phantom')
if bom:
bom_kits[product] = bom
components = self - self.env['product.product'].concat(*list(bom_kits.keys()))
for product in bom_kits:
boms, bom_sub_lines = bom_kits[product].explode(product, 1)
components |= self.env['product.product'].concat(*[l[0].product_id for l in bom_sub_lines])
res = super(ProductProduct, components).action_open_quants()
if bom_kits:
res['context']['single_product'] = False
return res
+1 -1
View File
@@ -484,7 +484,7 @@ class Product(models.Model):
single_product=True
)
else:
self = self.with_context(product_tmpl_id=self.product_tmpl_id.id)
self = self.with_context(product_tmpl_ids=self.product_tmpl_id.ids)
action = self.env['stock.quant']._get_quants_action(domain)
action["name"] = _('Update Quantity')
return action
+3 -2
View File
@@ -45,8 +45,9 @@ class StockQuant(models.Model):
if not self._is_inventory_mode():
return
domain = [('type', '=', 'product')]
if self.env.context.get('product_tmpl_id'):
domain = expression.AND([domain, [('product_tmpl_id', '=', self.env.context['product_tmpl_id'])]])
if self.env.context.get('product_tmpl_ids') or self.env.context.get('product_tmpl_id'):
products = self.env.context.get('product_tmpl_id', []) + [self.env.context.get('product_tmpl_id', 0)]
domain = expression.AND([domain, [('product_tmpl_id', 'in', products)]])
return domain
product_id = fields.Many2one(