Use MatchMixin to get product bom
This commit is contained in:
@@ -243,9 +243,10 @@ class BOMTree(ModelView):
|
||||
|
||||
result = []
|
||||
if bom is None:
|
||||
if not product.boms:
|
||||
pbom = product.get_bom()
|
||||
if pbom is None:
|
||||
return result
|
||||
bom = product.boms[0].bom
|
||||
bom = pbom.bom
|
||||
|
||||
factor = bom.compute_factor(product, quantity, unit)
|
||||
for input_ in bom.inputs:
|
||||
@@ -342,8 +343,10 @@ class OpenBOMTree(Wizard):
|
||||
defaults['product'] = product.id
|
||||
if getattr(self.start, 'bom', None):
|
||||
defaults['bom'] = self.start.bom.id
|
||||
elif product.boms:
|
||||
defaults['bom'] = product.boms[0].id
|
||||
else:
|
||||
bom = product.get_bom()
|
||||
if bom:
|
||||
defaults['bom'] = bom.id
|
||||
defaults['quantity'] = getattr(self.start, 'quantity', None)
|
||||
return defaults
|
||||
|
||||
|
||||
@@ -76,8 +76,15 @@ class Product(metaclass=PoolMeta):
|
||||
default.setdefault('production_lead_times', None)
|
||||
return super(Product, cls).copy(products, default=default)
|
||||
|
||||
def get_bom(self, pattern=None):
|
||||
if pattern is None:
|
||||
pattern = {}
|
||||
for bom in self.boms:
|
||||
if bom.match(pattern):
|
||||
return bom
|
||||
|
||||
class ProductBom(sequence_ordered(), ModelSQL, ModelView):
|
||||
|
||||
class ProductBom(sequence_ordered(), MatchMixin, ModelSQL, ModelView):
|
||||
'Product - BOM'
|
||||
__name__ = 'product.product-production.bom'
|
||||
|
||||
|
||||
@@ -36,9 +36,10 @@ class Production(metaclass=PoolMeta):
|
||||
@classmethod
|
||||
def compute_request(
|
||||
cls, product, warehouse, quantity, date, company,
|
||||
order_point=None):
|
||||
order_point=None, bom_pattern=None):
|
||||
production = super(Production, cls).compute_request(
|
||||
product, warehouse, quantity, date, company,
|
||||
order_point=order_point)
|
||||
production.routing = product.boms[0].routing if product.boms else None
|
||||
order_point=order_point, bom_pattern=bom_pattern)
|
||||
if bom := product.get_bom(bom_pattern):
|
||||
production.routing = bom.routing
|
||||
return production
|
||||
|
||||
@@ -66,7 +66,7 @@ class Line(metaclass=PoolMeta):
|
||||
default.setdefault('productions', None)
|
||||
return super().copy(lines, default=default)
|
||||
|
||||
def get_production(self, product_quantities):
|
||||
def get_production(self, product_quantities, bom_pattern=None):
|
||||
"Return production for the sale line"
|
||||
pool = Pool()
|
||||
Production = pool.get('production')
|
||||
@@ -99,13 +99,14 @@ class Line(metaclass=PoolMeta):
|
||||
date = today
|
||||
else:
|
||||
date -= dt.timedelta(1)
|
||||
pbom = product.get_bom(bom_pattern)
|
||||
return Production(
|
||||
planned_date=date,
|
||||
company=self.sale.company,
|
||||
warehouse=self.warehouse,
|
||||
location=self.warehouse.production_location,
|
||||
product=product,
|
||||
bom=product.boms[0].bom if product.boms else None,
|
||||
bom=pbom.bom if pbom else None,
|
||||
unit=self.unit,
|
||||
quantity=quantity,
|
||||
state='request',
|
||||
|
||||
@@ -151,7 +151,7 @@ class Production(metaclass=PoolMeta):
|
||||
@classmethod
|
||||
def compute_request(
|
||||
cls, product, warehouse, quantity, date, company,
|
||||
order_point=None):
|
||||
order_point=None, bom_pattern=None):
|
||||
"""
|
||||
Return the value of the production request.
|
||||
"""
|
||||
@@ -169,13 +169,14 @@ class Production(metaclass=PoolMeta):
|
||||
origin = str(order_point)
|
||||
else:
|
||||
origin = 'stock.order_point,-1'
|
||||
pbom = product.get_bom(bom_pattern)
|
||||
return cls(
|
||||
planned_date=date,
|
||||
company=company,
|
||||
warehouse=warehouse,
|
||||
location=warehouse.production_location,
|
||||
product=product,
|
||||
bom=product.boms[0].bom if product.boms else None,
|
||||
bom=pbom.bom if pbom else None,
|
||||
unit=unit,
|
||||
quantity=quantity,
|
||||
state='request',
|
||||
|
||||
Reference in New Issue
Block a user