Commit 47dd3e8c authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_production_planning: Move rendering and applying to skin folder for customization per project

parent 32daa656
from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate
production_planning = context
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 = keyToId(cell_keys)
if cell_id is not None:
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_quantity:
production_order_line.edit(quantity = cell_quantity)
portal.portal_workflow.doActionFor(
production_order_line,
"edit_action",
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
kw = {
'portal_type': 'Production Order',
'delivery.start_date': {'query': start_date, 'type': 'date'},
'simulation_state' : ('planned','auto_planned')
}
production_order_list = catalog_method(**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/psa_jv',
destination_section = 'organisation_module/psa_jv'
)
production_order.plan()
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_quantity)
cell.edit(
specialise_value = production_order_line,
related_url = production_order.getAbsoluteUrl()
)
portal.portal_workflow.doActionFor(
production_order_line,
"edit_action",
comment='Added by production planning %s' % relative_url)
if portal.portal_workflow.isTransitionPossible(production_planning, 'apply'):
production_planning.apply()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ProductionPlanning_applyProductionPlanning</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
production_planning = context
portal = production_planning.getPortalObject()
line_list, column_list = production_planning.ProductionPlanning_getCellRange()
line_ids = map(lambda x: x[0], line_list)
column_ids = map(lambda x: x[0], column_list)
production_planning.setCellRange(line_ids, column_ids, base_id='cell')
start_date = DateTime(column_list[0][0])
stop_date = addToDate(DateTime(column_list[-1][0]), {'day':1})
for product in portal.portal_catalog(portal_type='Product', product_line_relative_url='product_line/car'):
product_uid = product.getUid()
query_list = [
Query(portal_type='Production Order'),
Query(simulation_state=('planned','auto_planned')),
Query(child_resource_uid=product_uid),
ComplexQuery(Query(**{'delivery.start_date': {'query': stop_date, 'range': '<='}}),
Query(**{'delivery.start_date': {'query': start_date, 'range': '>='}}),
logical_operator='AND')
]
production_order_list = portal.portal_catalog(query=ComplexQuery(logical_operator='AND', *query_list))
line = int(product_uid)
kd = {'portal_type':'Production Planning Cell', 'base_id':'cell'}
for production_order in production_order_list:
column = '%s' % production_order.getStartDate().Date()
related_url = production_order.getAbsoluteUrl()
for production_order_line in production_order.searchFolder(portal_type='Production Order Line', strict_resource_uid=product_uid):
k = (line, column)
if not production_planning.hasInRange(*k, **kd):
production_planning.log('Waring: Production order date %s is not in range which should not be, need to check' % start_date)
if not production_planning.hasCell(*k, **kd):
new_cell = production_planning.newCell(*k, **kd)
quantity = production_order_line.getQuantity()
new_cell.edit(
quantity = quantity,
default_quantity = quantity,
related_url = related_url,
specialise_value = production_order_line)
production_planning.record()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ProductionPlanning_renderProductionPlanning</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate
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 = keyToId(cell_keys)
if cell_id is not None:
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_quantity:
production_order_line.edit(quantity = cell_quantity)
portal.portal_workflow.doActionFor(
production_order_line,
"edit_action",
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
kw = {
'portal_type': 'Production Order',
'delivery.start_date': {'query': start_date, 'type': 'date'},
'simulation_state' : ('planned','auto_planned')
}
production_order_list = catalog_method(**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/psa_jv',
destination_section = 'organisation_module/psa_jv'
)
production_order.plan()
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_quantity)
cell.edit(
specialise_value = production_order_line,
related_url = production_order.getAbsoluteUrl()
)
portal.portal_workflow.doActionFor(
production_order_line,
"edit_action",
comment='Added by production planning %s' % relative_url)
if portal.portal_workflow.isTransitionPossible(production_planning, 'apply'):
production_planning.apply()
state_change['object'].ProductionPlanning_applyProductionPlanning()
......@@ -60,6 +60,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_ProductionPlanning_applyProductionPlanningChanges</string> </value>
......
from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
production_planning = state_change['object']
portal = production_planning.getPortalObject()
line_list, column_list = production_planning.ProductionPlanning_getCellRange()
line_ids = map(lambda x: x[0], line_list)
column_ids = map(lambda x: x[0], column_list)
production_planning.setCellRange(line_ids, column_ids, base_id='cell')
start_date = DateTime(column_list[0][0])
stop_date = addToDate(DateTime(column_list[-1][0]), {'day':1})
for product in portal.portal_catalog(portal_type='Product', product_line_relative_url='product_line/car'):
product_uid = product.getUid()
query_list = [
Query(portal_type='Production Order'),
Query(simulation_state=('planned','auto_planned')),
Query(child_resource_uid=product_uid),
ComplexQuery(Query(**{'delivery.start_date': {'query': stop_date, 'range': '<='}}),
Query(**{'delivery.start_date': {'query': start_date, 'range': '>='}}),
logical_operator='AND')
]
production_order_list = portal.portal_catalog(query=ComplexQuery(logical_operator='AND', *query_list))
line = int(product_uid)
kd = {'portal_type':'Production Planning Cell', 'base_id':'cell'}
for production_order in production_order_list:
column = '%s' % production_order.getStartDate().Date()
related_url = production_order.getAbsoluteUrl()
for production_order_line in production_order.searchFolder(portal_type='Production Order Line', strict_resource_uid=product_uid):
k = (line, column)
if not production_planning.hasInRange(*k, **kd):
production_planning.log('Waring: Production order date %s is not in range which should not be, need to check' % start_date)
if not production_planning.hasCell(*k, **kd):
new_cell = production_planning.newCell(*k, **kd)
quantity = production_order_line.getQuantity()
new_cell.edit(
quantity = quantity,
default_quantity = quantity,
related_url = related_url,
specialise_value = production_order_line)
production_planning.record()
state_change['object'].ProductionPlanning_renderProductionPlanning()
......@@ -60,6 +60,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_ProductionPlanning_renderProductionPlanningStatus</string> </value>
......
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