Review PROCESS EXPORT ORDINI + trigger

This commit is contained in:
resteve 2015-11-04 14:53:52 +01:00
parent 0a3c0d3fa9
commit 0a67eb0d22
3 changed files with 54 additions and 16 deletions

View file

@ -3,3 +3,9 @@ SystemLogics Modula
===================
Integración con sistemas de almacén de SystemLogics Modula.
* EXP ORDINI
- Para la importación de ficehros XML, se dispone del cron "Export Ordini Files"
que lee los ficheros del directorio y los carga en el sistema.
- Se dispone de un disparador al crear un fichero "EXP ORDINI" se activa
el proceso de realizado movimientos y empaquetar albarán.

View file

@ -258,6 +258,8 @@ class SystemLogicsModulaEXPOrdiniFile(ModelSQL, ModelView):
content = fields.Text('Content', readonly=True)
state = fields.Selection([
('pending', 'Pending'),
('in_progress', 'In progress'),
('failed', 'Failed'),
('done', 'Done'),
], 'State', readonly=True)
@ -269,7 +271,7 @@ class SystemLogicsModulaEXPOrdiniFile(ModelSQL, ModelView):
]
cls._buttons.update({
'process_export_ordini': {
'invisible': Eval('state') != 'pending',
'invisible': ~Eval('state').in_(['pending', 'failed']),
},
})
@ -279,7 +281,7 @@ class SystemLogicsModulaEXPOrdiniFile(ModelSQL, ModelView):
@classmethod
@ModelView.button
def process_export_ordini(cls, executions, trigger=None):
def process_export_ordini(cls, ordini_files, trigger=None):
''''
Read EXP ORDINI file
1- Try to done a move (RIG_HOSTINF is ID move)
@ -288,13 +290,18 @@ class SystemLogicsModulaEXPOrdiniFile(ModelSQL, ModelView):
pool = Pool()
Move = pool.get('stock.move')
Shipment = pool.get('stock.shipment.out')
EXPOrdiniFile = pool.get('systemlogics.modula.exp.ordini.file')
EXPOrdiniFile.write(ordini_files, {'state': 'in_progress'})
Transaction().cursor.commit()
to_do = []
update_executions = []
done_ordini_files = []
fail_ordini_files = []
shipments = set()
for execution in executions:
execution_to_done = True
dom = parseString(execution.content)
for ofile in ordini_files:
dom = parseString(ofile.content)
quantities = {}
moves = []
for o in dom.getElementsByTagName('EXP_ORDINI_RIGHE'):
@ -314,24 +321,28 @@ class SystemLogicsModulaEXPOrdiniFile(ModelSQL, ModelView):
and move.shipment.state == 'assigned'):
to_do.append(move)
shipments.add(move.shipment)
else:
execution_to_done = False
if execution_to_done:
update_executions.append(execution)
done_ordini_files.append(ofile)
if to_do:
Move.do(to_do)
Move.do(to_do) # TODO try/except move error
if shipments:
Shipment._sync_inventory_to_outgoing(shipments)
Move.assign([m for s in shipments for m in s.outgoing_moves])
to_package = []
for shipment in shipments:
package = True
for move in shipment.outgoing_moves:
if move.state != 'done':
if move.state != 'assigned':
package = False
if package:
to_package.append(shipment)
if to_package:
Shipment.pack(to_package)
if update_executions:
cls.write(update_executions, {'state': 'done'})
if done_ordini_files:
cls.write(done_ordini_files, {'state': 'done'})
if fail_ordini_files:
cls.write(fail_ordini_files, {'state': 'failed'})

View file

@ -19,8 +19,10 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<field name="group" ref="group_systemlogics_modula"/>
</record>
<!-- Menu Top -->
<!-- Menus -->
<menuitem parent="stock.menu_configuration"
name="SystemLogics Modula" id="menu_systemlogics_modula_configuration"/>
<menuitem parent="stock.menu_stock"
name="SystemLogics Modula" id="menu_systemlogics_modula"/>
<!-- systemlogics -->
@ -50,7 +52,8 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<field name="view" ref="systemlogics_modula_view_form"/>
<field name="act_window" ref="act_systemlogics_modula_form"/>
</record>
<menuitem parent="menu_systemlogics_modula" action="act_systemlogics_modula_form"
<menuitem parent="menu_systemlogics_modula_configuration"
action="act_systemlogics_modula_form"
id="menu_systemlogics_modula_form"/>
<!-- systemlogics.modula.exp.ordini.file -->
@ -88,6 +91,12 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<field name="domain">[('state', '=', 'pending')]</field>
<field name="act_window" ref="act_systemlogics_modula_exp_ordini_file"/>
</record>
<record model="ir.action.act_window.domain" id="act_systemlogics_modula_exp_ordini_file_failed">
<field name="name">Failed</field>
<field name="sequence" eval="10"/>
<field name="domain">[('state', '=', 'failed')]</field>
<field name="act_window" ref="act_systemlogics_modula_exp_ordini_file"/>
</record>
<record model="ir.action.act_window.domain" id="act_systemlogics_modula_exp_ordini_file_done">
<field name="name">Done</field>
<field name="sequence" eval="20"/>
@ -121,6 +130,18 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<field name="function">export_ordini_file</field>
</record>
<!-- Trigger for systemlogics.modula -->
<record model="ir.trigger" id="trigger_export_ordini_file">
<field name="name">SystemLogics Modula EXP Ordini File</field>
<field name="active" eval="True"/>
<field name="model" search="[('model', '=', 'systemlogics.modula.exp.ordini.file')]"/>
<field name="on_create" eval="True"/>
<field name="condition">True</field>
<field name="limit_number">0</field>
<field name="action_model" search="[('model', '=', 'systemlogics.modula.exp.ordini.file')]"/>
<field name="action_function">process_export_ordini</field>
</record>
<!-- Access -->
<record model="ir.model.access" id="access_systemlogics_modula">
<field name="model" search="[('model', '=', 'systemlogics.modula')]"/>