[FIX] mrp: BoM count detection in case it is a single variant

In case a product is a single variant we should not leave it with a BoM
of zero as soon there is a BoM for its template. This would for example
hide the `compute_price` object button which relies on the `bom_count`to
be visible.

BoM is not found for a single variant product and compute price not
possible from the `product.product` view although it is implemented
actually there.

Closes #16237
This commit is contained in:
Wolfgang Taferner
2017-04-05 12:00:39 +02:00
committed by Nicolas Martinelli
parent 85132f68d2
commit bf781cf740
+6 -1
View File
@@ -44,7 +44,12 @@ class ProductProduct(models.Model):
read_group_res = self.env['mrp.bom'].read_group([('product_id', 'in', self.ids)], ['product_id'], ['product_id'])
mapped_data = dict([(data['product_id'][0], data['product_id_count']) for data in read_group_res])
for product in self:
product.bom_count = mapped_data.get(product.id, 0)
if product.product_tmpl_id.product_variant_count == 1:
bom_count = mapped_data.get(product.id, product.product_tmpl_id.bom_count)
else:
bom_count = mapped_data.get(product.id, 0)
product.bom_count = bom_count
def _compute_mo_count(self):
read_group_res = self.env['mrp.production'].read_group([('product_id', 'in', self.ids)], ['product_id'], ['product_id'])