Commit b042c5df authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_production_planning: use cell id to get resource,date is wrong

parent f13738a1
......@@ -2,55 +2,56 @@ from DateTime import DateTime
from Products.ERP5Type.DateUtils import addToDate
portal = context.getPortalObject()
line_list, column_list = context.ProductionPlanning_getCellRange()
line_id_list = [x[0] for x in line_list]
column_id_list = [x[0] for x in column_list]
created_production_order_dict = {}
for cell in context.getCellValueList():
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' % context.getRelativeUrl())
else:
# It's a new cell, create producton order&production order line
[_, line_index, column_index] = cell.getId().split('_')
resource_uid = line_id_list[int(line_index)]
start_date = column_id_list[int(column_index)]
# 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]
for cell_keys in context.getCellKeys():
cell_id = context.keyToId(cell_keys)
if cell_id is not None:
cell = context.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' % context.getRelativeUrl())
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' % context.getRelativeUrl())
# 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' % context.getRelativeUrl())
if portal.portal_workflow.isTransitionPossible(context, 'record'):
context.record()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment