summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Baes <arb@odoo.com>2018-12-04 12:38:40 +0000
committerArnaud Baes <arb@odoo.com>2018-12-19 10:50:29 +0000
commitefb255246b1a60b8299ce1c39ef404d3618b368a (patch)
tree695fe0ad556a607f9674f51c2e5f0e985ad3e4d2
parent45e53ff7a599f87bf98fc67934ebf083c2dcaee1 (diff)
[REF] mrp, purchase_mrp: find bom depending on its type
This commit refactors the method '_bom_find' in order to search bom based on their type. This allows to handle the cases where a Kit has the route 'Manufacture' set. TaskID: 1863856
-rw-r--r--addons/mrp/models/mrp_bom.py8
-rw-r--r--addons/mrp/models/mrp_production.py4
-rw-r--r--addons/mrp/models/stock_move.py4
-rw-r--r--addons/mrp/models/stock_rule.py2
-rw-r--r--addons/purchase_mrp/models/purchase_mrp.py4
-rw-r--r--addons/sale_mrp/models/sale_mrp.py4
6 files changed, 14 insertions, 12 deletions
diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index b756f77957f..d9eeba3beaf 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -111,7 +111,7 @@ class MrpBom(models.Model):
return super(MrpBom, self).unlink()
@api.model
- def _bom_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False):
+ def _bom_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False, bom_type=False):
""" Finds BoM for particular product, picking and company """
if product:
if not product_tmpl:
@@ -126,6 +126,8 @@ class MrpBom(models.Model):
domain += ['|', ('picking_type_id', '=', picking_type.id), ('picking_type_id', '=', False)]
if company_id or self.env.context.get('company_id'):
domain = domain + [('company_id', '=', company_id or self.env.context.get('company_id'))]
+ if bom_type:
+ domain += [('type', '=', bom_type)]
# order to prioritize bom with product_id over the one without
return self.search(domain, order='sequence, product_id', limit=1)
@@ -168,8 +170,8 @@ class MrpBom(models.Model):
continue
line_quantity = current_qty * current_line.product_qty
- bom = self._bom_find(product=current_line.product_id, picking_type=picking_type or self.picking_type_id, company_id=self.company_id.id)
- if bom.type == 'phantom':
+ bom = self._bom_find(product=current_line.product_id, picking_type=picking_type or self.picking_type_id, company_id=self.company_id.id, bom_type='phantom')
+ if bom:
converted_line_quantity = current_line.product_uom_id._compute_quantity(line_quantity / bom.product_qty, bom.product_uom_id)
bom_lines = [(line, current_line.product_id, converted_line_quantity, current_line) for line in bom.bom_line_ids] + bom_lines
for bom_line in bom.bom_line_ids:
diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py
index c6ca7dd25d0..462268fb443 100644
--- a/addons/mrp/models/mrp_production.py
+++ b/addons/mrp/models/mrp_production.py
@@ -356,8 +356,8 @@ class MrpProduction(models.Model):
if not self.product_id:
self.bom_id = False
else:
- bom = self.env['mrp.bom']._bom_find(product=self.product_id, picking_type=self.picking_type_id, company_id=self.company_id.id)
- if bom.type == 'normal':
+ bom = self.env['mrp.bom']._bom_find(product=self.product_id, picking_type=self.picking_type_id, company_id=self.company_id.id, bom_type='normal')
+ if bom:
self.bom_id = bom.id
self.product_qty = self.bom_id.product_qty
self.product_uom_id = self.bom_id.product_uom_id.id
diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py
index 2234d34f5f4..610c1934b29 100644
--- a/addons/mrp/models/stock_move.py
+++ b/addons/mrp/models/stock_move.py
@@ -158,8 +158,8 @@ class StockMove(models.Model):
# all grouped in the same picking.
if not self.picking_type_id:
return self
- bom = self.env['mrp.bom'].sudo()._bom_find(product=self.product_id, company_id=self.company_id.id)
- if not bom or bom.type != 'phantom':
+ bom = self.env['mrp.bom'].sudo()._bom_find(product=self.product_id, company_id=self.company_id.id, bom_type='phantom')
+ if not bom:
return self
phantom_moves = self.env['stock.move']
processed_moves = self.env['stock.move']
diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py
index d66d1af3298..dd58d85bf3f 100644
--- a/addons/mrp/models/stock_rule.py
+++ b/addons/mrp/models/stock_rule.py
@@ -60,7 +60,7 @@ class StockRule(models.Model):
return values['bom_id']
return self.env['mrp.bom'].with_context(
company_id=values['company_id'].id, force_company=values['company_id'].id
- )._bom_find(product=product_id, picking_type=self.picking_type_id) # TDE FIXME: context bullshit
+ )._bom_find(product=product_id, picking_type=self.picking_type_id, bom_type='normal') # TDE FIXME: context bullshit
def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_id, name, origin, values, bom):
return {
diff --git a/addons/purchase_mrp/models/purchase_mrp.py b/addons/purchase_mrp/models/purchase_mrp.py
index 20d10244015..7c0e78381a8 100644
--- a/addons/purchase_mrp/models/purchase_mrp.py
+++ b/addons/purchase_mrp/models/purchase_mrp.py
@@ -19,8 +19,8 @@ class PurchaseOrderLine(models.Model):
super(PurchaseOrderLine, self)._compute_qty_received()
for line in self:
if line.qty_received_method == 'stock_moves' and line.move_ids and line.product_id.id not in line.move_ids.mapped('product_id').ids:
- bom = self.env['mrp.bom']._bom_find(product=line.product_id, company_id=line.company_id.id)
- if bom and bom.type == 'phantom':
+ bom = self.env['mrp.bom']._bom_find(product=line.product_id, company_id=line.company_id.id, bom_type='phantom')
+ if bom:
line.qty_received = line._get_bom_delivered(bom=bom)
def _get_bom_delivered(self, bom=False):
diff --git a/addons/sale_mrp/models/sale_mrp.py b/addons/sale_mrp/models/sale_mrp.py
index 06a43667f9a..f1bdfc3f9de 100644
--- a/addons/sale_mrp/models/sale_mrp.py
+++ b/addons/sale_mrp/models/sale_mrp.py
@@ -55,8 +55,8 @@ class SaleOrderLine(models.Model):
# We don't try to be too smart and keep a simple approach: we compare the quantity before
# and after update, and return the difference. We don't take into account what was already
# sent, or any other exceptional case.
- bom = self.env['mrp.bom']._bom_find(product=self.product_id)
- if bom and bom.type == 'phantom' and 'previous_product_uom_qty' in self.env.context:
+ bom = self.env['mrp.bom']._bom_find(product=self.product_id, bom_type='phantom')
+ if bom and 'previous_product_uom_qty' in self.env.context:
return self.env.context['previous_product_uom_qty'].get(self.id, 0.0)
return super(SaleOrderLine, self)._get_qty_procurement()