[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
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user