mirror of
https://gitlab.com/datalifeit/trytond-sale_supply_production
synced 2023-12-14 06:02:55 +01:00
Parse operation values to support it comes with lines
This commit is contained in:
parent
e30b723d44
commit
52446ba9d2
|
@ -9,6 +9,34 @@ __all__ = ['Production', 'Plan', 'PlanBOM']
|
|||
__metaclass__ = PoolMeta
|
||||
|
||||
|
||||
def prepare_vals(values, to_write=False):
|
||||
if isinstance(values, dict):
|
||||
if set(values.keys()) <= set(['add', 'remove']):
|
||||
res = []
|
||||
if to_write:
|
||||
if 'add' in values.keys():
|
||||
res.append(('create',
|
||||
prepare_vals([v[1] for v in values['add']])))
|
||||
if 'remove' in values.keys():
|
||||
res.append(('delete', values['remove']))
|
||||
else:
|
||||
# to create
|
||||
if 'add' in values.keys():
|
||||
res = [x for _, x in values['add']]
|
||||
else:
|
||||
res = {}
|
||||
for key, value in values.iteritems():
|
||||
if 'rec_name' in key or key == 'id':
|
||||
continue
|
||||
value = prepare_vals(value)
|
||||
if value is not None:
|
||||
res[key] = value
|
||||
return res or None
|
||||
elif isinstance(values, list):
|
||||
return [prepare_vals(v) for v in values]
|
||||
return values
|
||||
|
||||
|
||||
class Production:
|
||||
__name__ = 'production'
|
||||
|
||||
|
@ -143,6 +171,7 @@ class Plan:
|
|||
production.operations = []
|
||||
changes = production.update_operations()
|
||||
for index, operation_vals in changes['operations']['add']:
|
||||
operation_vals = prepare_vals(operation_vals)
|
||||
production.operations.append(Operation(**operation_vals))
|
||||
|
||||
if 'bom' in values:
|
||||
|
|
3
sale.py
3
sale.py
|
@ -50,6 +50,7 @@ class Sale:
|
|||
for line in self.lines:
|
||||
productions = line.get_productions()
|
||||
for production in productions:
|
||||
# TODO: move this code to sale line get_produtions() method
|
||||
production.cost_plan = line.cost_plan
|
||||
production.origin = str(line)
|
||||
production.reference = self.reference
|
||||
|
@ -98,6 +99,8 @@ class SaleLine:
|
|||
return []
|
||||
if len(self.productions) > 0:
|
||||
return []
|
||||
# TODO: It will be better, to improve modularity, to call a sale.line
|
||||
# method
|
||||
return self.cost_plan.get_productions(self.sale.warehouse, self.unit,
|
||||
self.quantity)
|
||||
|
||||
|
|
Loading…
Reference in a new issue