erp5_production_planning: add production planning module to make production order change easier
Showing
from DateTime import DateTime | |||
from Products.ERP5Type.DateUtils import addToDate | |||
production_planning = state_change['object'] | |||
portal = production_planning.getPortalObject() | |||
created_production_order_dict = {} | |||
for cell_keys in production_planning.getCellKeys(): | |||
cell_id = production_planning.keyToId(cell_keys) | |||
if cell_id is not None: | |||
cell = production_planning.get(cell_id) | |||
if cell is not None: | |||
production_order_line = cell.getSpecialiseValue() | |||
if production_order_line: | |||
if production_order_line.getQuantity() != cell.getQuantity(): | |||
production_order_line.edit(quantity = cell.getQuantity()) | |||
portal.portal_workflow.doActionFor( | |||
production_order_line, | |||
"edit_action", | |||
comment='Modified by production planning %s' % production_planning.getRelativeUrl()) | |||
elif cell.getQuantity(): | |||
# It's a new cell, create producton order&production order line | |||
[resource_uid,start_date] = cell_keys | |||
# Check if it existes a production order for the date | |||
kw = { | |||
'portal_type': 'Production Order', | |||
'delivery.start_date': {'query': start_date, 'type': 'date'} | |||
|
|||
} | |||
production_order_list = portal.portal_catalog(**kw) | |||
if len(production_order_list): | |||
production_order = production_order_list[0] | |||
else: | |||
# Search in the new created dict | |||
if start_date in created_production_order_dict: | |||
production_order = created_production_order_dict[start_date] | |||
else: | |||
production_order = portal.production_order_module.newContent( | |||
portal_type='Production Order', | |||
start_date = DateTime(start_date), | |||
stop_date = addToDate(DateTime(start_date), {'day':2}), | |||
destination = 'organisation_module/test_psa_jv', | |||
destination_section = 'organisation_module/test_psa_jv' | |||
) | |||
production_order.autoPlan() | |||
created_production_order_dict[start_date] = production_order | |||
# Add new production order line for resource | |||
production_order_line = production_order.newContent( | |||
portal_type='Production Order Line', | |||
resource_uid = resource_uid, | |||
quantity = cell.getQuantity()) | |||
cell.edit(specialise_value = production_order_line) | |||
portal.portal_workflow.doActionFor( | |||
production_order_line, | |||
"edit_action", | |||
comment='Added by production planning %s' % production_planning.getRelativeUrl()) | |||
if portal.portal_workflow.isTransitionPossible(production_planning, 'apply'): | |||
production_planning.apply() |