Commit 05903603 authored by Xiaowu Zhang's avatar Xiaowu Zhang Committed by Cédric Le Ninivin

erp5_production_planning: reduce attribute access

parent 68d93ee8
......@@ -33,9 +33,10 @@ while tmp_date < stop_date:
tmp_date = addToDate(tmp_date, {'day': 7})
line_list = []
validation_state = context.getValidationState()
for product in portal.portal_catalog(portal_type='Product', product_line_relative_url='product_line/car', sort_on=(('uid', 'ascending'),)):
line_list.append((int(product.getUid()), '%s/%s'% (product.getReference(), product.getTitle())))
if context.getValidationState() in ('draft'):
if validation_state in ('draft',):
continue
# Now check existed production order to add more columns
product_uid = product.getUid()
......@@ -54,10 +55,12 @@ for product in portal.portal_catalog(portal_type='Product', product_line_relativ
column_dict[tmp_start_date.Date()] = '%s, week %s' % (tmp_start_date.Date(), tmp_start_date.week())
#Not lost already created cell
keyToId = context.keyToId
cell_get = context.get
for cell_keys in context.getCellKeys():
cell_id = context.keyToId(cell_keys)
cell_id = keyToId(cell_keys)
if cell_id is not None:
cell = context.get(cell_id)
cell = cell_get(cell_id)
if cell is not None:
[_, tmp_start_date] = cell_keys
if tmp_start_date not in column_dict:
......
......@@ -5,20 +5,26 @@ production_planning = state_change['object']
portal = production_planning.getPortalObject()
created_production_order_dict = {}
keyToId = production_planning.keyToId
get_cell = production_planning.get
relative_url = production_planning.getRelativeUrl()
catalog_method = portal.portal_catalog
for cell_keys in production_planning.getCellKeys():
cell_id = production_planning.keyToId(cell_keys)
cell_id = keyToId(cell_keys)
if cell_id is not None:
cell = production_planning.get(cell_id)
cell = get_cell(cell_id)
if cell is not None:
cell_quantity = cell.getQuantity()
production_order_line = cell.getSpecialiseValue()
if production_order_line:
if production_order_line.getQuantity() != cell.getQuantity():
production_order_line.edit(quantity = cell.getQuantity())
if production_order_line.getQuantity() != cell_quantity:
production_order_line.edit(quantity = cell_quantity)
portal.portal_workflow.doActionFor(
production_order_line,
"edit_action",
comment='Modified by production planning %s' % production_planning.getRelativeUrl())
elif cell.getQuantity():
comment='Modified by production planning %s' % relative_url)
elif cell_quantity:
# 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
......@@ -26,7 +32,7 @@ for cell_keys in production_planning.getCellKeys():
'portal_type': 'Production Order',
'delivery.start_date': {'query': start_date, 'type': 'date'}
}
production_order_list = portal.portal_catalog(**kw)
production_order_list = catalog_method(**kw)
if len(production_order_list):
production_order = production_order_list[0]
else:
......@@ -47,12 +53,12 @@ for cell_keys in production_planning.getCellKeys():
production_order_line = production_order.newContent(
portal_type='Production Order Line',
resource_uid = resource_uid,
quantity = cell.getQuantity())
quantity = cell_quantity)
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())
comment='Added by production planning %s' % relative_url)
if portal.portal_workflow.isTransitionPossible(production_planning, 'apply'):
production_planning.apply()
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