Filter moves that has multiple moves and different lot
This commit is contained in:
parent
56fc77f0ce
commit
a1beb7ec67
|
@ -21,14 +21,16 @@ _ZERO = 0.0
|
|||
class Production(metaclass=PoolMeta):
|
||||
__name__ = 'production'
|
||||
|
||||
def mass_balance_report_data(self, requested_product, direction):
|
||||
def mass_balance_report_data(self, requested_product, direction, lot=None):
|
||||
Uom = Pool().get('product.uom')
|
||||
|
||||
digits = self.on_change_with_unit_digits()
|
||||
|
||||
quantity = 0.0
|
||||
for move in getattr(self, 'outputs' if direction == 'backward' else 'inputs'):
|
||||
if move.product == requested_product:
|
||||
# skip moves that same product but different lot
|
||||
if lot and lot != move.lot:
|
||||
continue
|
||||
quantity += Uom.compute_qty(move.uom, move.quantity, move.product.default_uom, True)
|
||||
|
||||
moves = {}
|
||||
|
@ -56,12 +58,11 @@ class Production(metaclass=PoolMeta):
|
|||
balance_plan_consumption = balance_difference = balance_difference_percent = 0.0
|
||||
if self.bom:
|
||||
bom = self.bom
|
||||
uom = self.uom
|
||||
for bm in bom.inputs:
|
||||
if bm.product == product:
|
||||
default_uom = self.product.default_uom
|
||||
bqty = Uom.compute_qty(
|
||||
uom, bm.quantity, default_uom, True)
|
||||
bm.uom, bm.quantity, bm.product.default_uom, True)
|
||||
factor = bom.compute_factor(self.product, bqty, default_uom)
|
||||
balance_plan_consumption = default_uom.ceil(self.quantity * factor)
|
||||
break
|
||||
|
@ -83,12 +84,11 @@ class Production(metaclass=PoolMeta):
|
|||
balance_plan_consumption = balance_difference = balance_difference_percent = 0.0
|
||||
if self.bom:
|
||||
bom = self.bom
|
||||
uom = self.uom
|
||||
for bm in bom.inputs:
|
||||
if bm.product == requested_product:
|
||||
default_uom = self.product.default_uom
|
||||
bqty = Uom.compute_qty(
|
||||
uom, bm.quantity, default_uom, True)
|
||||
bm.uom, bm.quantity, bm.product.default_uom, True)
|
||||
factor = bom.compute_factor(self.product, bqty, default_uom)
|
||||
balance_plan_consumption = default_uom.ceil(self.quantity * factor)
|
||||
break
|
||||
|
@ -248,6 +248,7 @@ class PrintProductionMassBalanceReport(HTMLReport):
|
|||
|
||||
requested_product = Product(data['product'])
|
||||
direction = data['direction']
|
||||
lot = Lot(data['lot']) if data.get('lot') else None
|
||||
|
||||
parameters = {}
|
||||
parameters['direction'] = direction
|
||||
|
@ -270,8 +271,8 @@ class PrintProductionMassBalanceReport(HTMLReport):
|
|||
('outputs.state', '=', 'done'),
|
||||
('company', '=', company_id),
|
||||
]
|
||||
if data.get('lot'):
|
||||
domain += [('outputs.lot', '=', data['lot'])]
|
||||
if lot:
|
||||
domain += [('outputs.lot', '=', lot)]
|
||||
else:
|
||||
domain = [
|
||||
('inputs.product', '=', requested_product),
|
||||
|
@ -280,14 +281,15 @@ class PrintProductionMassBalanceReport(HTMLReport):
|
|||
('inputs.state', '=', 'done'),
|
||||
('company', '=', company_id),
|
||||
]
|
||||
if data.get('lot'):
|
||||
domain += [('inputs.lot', '=', data['lot'])]
|
||||
if lot:
|
||||
domain += [('inputs.lot', '=', lot)]
|
||||
|
||||
productions = Production.search(domain)
|
||||
|
||||
records = {}
|
||||
for production in productions:
|
||||
res = production.mass_balance_report_data(requested_product, direction)
|
||||
res = production.mass_balance_report_data(requested_product,
|
||||
direction, lot)
|
||||
|
||||
for key, values in res.items():
|
||||
if not records.get(key):
|
||||
|
|
Loading…
Reference in New Issue