Commit ff6c76fd authored by Xiaowu Zhang's avatar Xiaowu Zhang Committed by Titouan Soulard

erp5_production_planning: reduce attribute access

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