mirror of
https://github.com/NaN-tic/trytond-systemlogics_modula.git
synced 2023-12-14 04:32:53 +01:00
EXP ORDINI Files + Process files to done move/packed shipments
This commit is contained in:
parent
9c6e955293
commit
22046de9e3
|
@ -10,6 +10,7 @@ from .stock import *
|
|||
def register():
|
||||
Pool.register(
|
||||
SystemLogicsModula,
|
||||
SystemLogicsModulaEXPOrdiniFile,
|
||||
Location,
|
||||
Product,
|
||||
ShipmentIn,
|
||||
|
|
144
systemlogics.py
144
systemlogics.py
|
@ -6,6 +6,7 @@ from trytond.model import ModelView, ModelSQL, fields
|
|||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from itertools import groupby
|
||||
from xml.dom.minidom import parseString
|
||||
import genshi
|
||||
import genshi.template
|
||||
import os
|
||||
|
@ -14,7 +15,7 @@ import logging
|
|||
import datetime
|
||||
import tempfile
|
||||
|
||||
__all__ = ['SystemLogicsModula']
|
||||
__all__ = ['SystemLogicsModula', 'SystemLogicsModulaEXPOrdiniFile']
|
||||
|
||||
loader = genshi.template.TemplateLoader(
|
||||
os.path.join(os.path.dirname(__file__), 'template'),
|
||||
|
@ -170,7 +171,7 @@ class SystemLogicsModula(ModelSQL, ModelView):
|
|||
systemlogic.id,
|
||||
))
|
||||
return
|
||||
|
||||
|
||||
articoli = getattr(self, 'imp_articoli_%s' % systemlogic.dbhost)
|
||||
articoli(systemlogic, products)
|
||||
|
||||
|
@ -206,3 +207,142 @@ class SystemLogicsModula(ModelSQL, ModelView):
|
|||
logging.getLogger('systemlogics-modula').info(
|
||||
'Generated XML %s' % (temp.name))
|
||||
temp.close()
|
||||
|
||||
@classmethod
|
||||
def export_ordini_file(cls, args=None):
|
||||
EXPOrdiniFile = Pool().get('systemlogics.modula.exp.ordini.file')
|
||||
|
||||
logging.getLogger('systemlogics-modula').info(
|
||||
'Start read SystemLogics Module files')
|
||||
|
||||
modulas = cls.search([
|
||||
('name', '=', 'EXP_ORDINI'),
|
||||
])
|
||||
|
||||
vlist = []
|
||||
to_delete = []
|
||||
for modula in modulas:
|
||||
try:
|
||||
filenames = os.listdir(modula.path)
|
||||
except OSError, e:
|
||||
logging.getLogger('systemlogics-modula').warning(
|
||||
'Error reading path: %s' % e)
|
||||
continue
|
||||
for filename in filenames:
|
||||
fullname = '%s/%s' % (modula.path, filename)
|
||||
values = {}
|
||||
exp_ordini_file = EXPOrdiniFile.search([
|
||||
('name', '=', filename)
|
||||
])
|
||||
if exp_ordini_file:
|
||||
to_delete.append(fullname)
|
||||
continue
|
||||
try:
|
||||
content = open(fullname, 'r').read()
|
||||
except IOError, e:
|
||||
logging.getLogger('systemlogics-modula').warning(
|
||||
'Error reading file %s: %s' % (fullname, e))
|
||||
continue
|
||||
values['name'] = filename
|
||||
values['modula'] = modula.id
|
||||
values['content'] = content
|
||||
values['state'] = 'pending'
|
||||
vlist.append(values)
|
||||
to_delete.append(fullname)
|
||||
ordini_files = EXPOrdiniFile.create(vlist)
|
||||
EXPOrdiniFile.process_export_ordini(ordini_files)
|
||||
for filename in to_delete:
|
||||
try:
|
||||
os.remove(filename)
|
||||
except OSError:
|
||||
pass
|
||||
logging.getLogger('systemlogics-modula').info(
|
||||
'Loaded SystemLogics Module %s files' % (len(to_delete)))
|
||||
|
||||
|
||||
class SystemLogicsModulaEXPOrdiniFile(ModelSQL, ModelView):
|
||||
'SystemLogics Modula EXP Ordini File'
|
||||
__name__ = 'systemlogics.modula.exp.ordini.file'
|
||||
name = fields.Char('Name', required=True)
|
||||
modula = fields.Many2One('systemlogics.modula', "Systemlogics Modula",
|
||||
required=True)
|
||||
content = fields.Text('Content', readonly=True)
|
||||
state = fields.Selection([
|
||||
('pending', 'Pending'),
|
||||
('done', 'Done'),
|
||||
], 'State', readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(SystemLogicsModulaEXPOrdiniFile, cls).__setup__()
|
||||
cls._sql_constraints += [
|
||||
('name_uniq', 'UNIQUE(name)', 'Name must be unique.'),
|
||||
]
|
||||
cls._buttons.update({
|
||||
'process_export_ordini': {
|
||||
'invisible': Eval('state') != 'pending',
|
||||
},
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def default_state(cls):
|
||||
return 'pending'
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def process_export_ordini(cls, executions, trigger=None):
|
||||
''''
|
||||
Read EXP ORDINI file
|
||||
1- Try to done a move (RIG_HOSTINF is ID move)
|
||||
2- Try to packed shipment if all moves are done
|
||||
'''
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
Shipment = pool.get('stock.shipment.out')
|
||||
|
||||
to_do = []
|
||||
update_executions = []
|
||||
shipments = set()
|
||||
for execution in executions:
|
||||
execution_to_done = True
|
||||
dom = parseString(execution.content)
|
||||
quantities = {}
|
||||
moves = []
|
||||
for o in dom.getElementsByTagName('EXP_ORDINI_RIGHE'):
|
||||
move = {}
|
||||
id_ = (o.getElementsByTagName('RIG_HOSTINF')[0]
|
||||
.firstChild.data)
|
||||
moves.append(id_)
|
||||
quantities[int(id_)] = float(
|
||||
o.getElementsByTagName('RIG_QTAE')
|
||||
[0].firstChild.data.replace(',', '.'))
|
||||
|
||||
moves = Move.search([
|
||||
('id', 'in', moves)
|
||||
])
|
||||
for move in moves:
|
||||
if (quantities[move.id] == move.quantity
|
||||
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)
|
||||
|
||||
if to_do:
|
||||
Move.do(to_do)
|
||||
|
||||
to_package = []
|
||||
for shipment in shipments:
|
||||
package = True
|
||||
for move in shipment.outgoing_moves:
|
||||
if move.state != 'done':
|
||||
package = False
|
||||
if package:
|
||||
to_package.append(shipment)
|
||||
if to_package:
|
||||
Shipment.pack(to_package)
|
||||
|
||||
if update_executions:
|
||||
cls.write(update_executions, {'state': 'done'})
|
||||
|
|
|
@ -53,6 +53,74 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
<menuitem parent="menu_systemlogics_modula" action="act_systemlogics_modula_form"
|
||||
id="menu_systemlogics_modula_form"/>
|
||||
|
||||
<!-- systemlogics.modula.exp.ordini.file -->
|
||||
<record model="ir.ui.view" id="systemlogics_modula_exp_ordini_file_view_tree">
|
||||
<field name="model">systemlogics.modula.exp.ordini.file</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">systemlogics_modula_exp_ordini_file_tree</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="systemlogics_modula_exp_ordini_file_view_form">
|
||||
<field name="model">systemlogics.modula.exp.ordini.file</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">systemlogics_modula_exp_ordini_file_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_systemlogics_modula_exp_ordini_file">
|
||||
<field name="name">SystemLogics Modula EXP Ordini Files</field>
|
||||
<field name="res_model">systemlogics.modula.exp.ordini.file</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window.view" id="act_systemlogics_modula_exp_ordini_file_tree">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="systemlogics_modula_exp_ordini_file_view_tree"/>
|
||||
<field name="act_window" ref="act_systemlogics_modula_exp_ordini_file"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window.view" id="act_systemlogics_modula_exp_ordini_file_form">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="systemlogics_modula_exp_ordini_file_view_form"/>
|
||||
<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_pending">
|
||||
<field name="name">Pending</field>
|
||||
<field name="sequence" eval="10"/>
|
||||
<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_done">
|
||||
<field name="name">Done</field>
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="domain">[('state', '=', 'done')]</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_all">
|
||||
<field name="name">All</field>
|
||||
<field name="sequence" eval="30"/>
|
||||
<field name="domain"></field>
|
||||
<field name="act_window" ref="act_systemlogics_modula_exp_ordini_file"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="menu_systemlogics_modula_exp_ordini_file"
|
||||
parent="menu_systemlogics_modula"
|
||||
action="act_systemlogics_modula_exp_ordini_file"
|
||||
name="EXP Ordini Files"/>
|
||||
|
||||
<!-- CRON for systemlogics.modula -->
|
||||
<record model="ir.cron" id="cron_export_ordini_file">
|
||||
<field name="name">Export Ordini Files</field>
|
||||
<field name="request_user" ref="res.user_admin"/>
|
||||
<field name="user" ref="res.user_trigger"/>
|
||||
<field name="active" eval="True"/>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="number_calls">-1</field>
|
||||
<field name="repeat_missed" eval="False"/>
|
||||
<field name="model">systemlogics.modula</field>
|
||||
<field name="function">export_ordini_file</field>
|
||||
</record>
|
||||
|
||||
<!-- Access -->
|
||||
<record model="ir.model.access" id="access_systemlogics_modula">
|
||||
<field name="model" search="[('model', '=', 'systemlogics.modula')]"/>
|
||||
|
@ -69,6 +137,14 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_systemlogics_modula_exp_ordini_file">
|
||||
<field name="model" search="[('model', '=', 'systemlogics.modula.exp.ordini.file')]"/>
|
||||
<field name="group" ref="group_systemlogics_modula"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<!-- End systemlogics -->
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
17
view/systemlogics_modula_exp_ordini_file_form.xml
Normal file
17
view/systemlogics_modula_exp_ordini_file_form.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part systemlogics_modula module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<form string="SystemLogics">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="modula"/>
|
||||
<field name="modula"/>
|
||||
<label name="content"/>
|
||||
<newline/>
|
||||
<field name="content" colspan="4"/>
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
<group col="4" colspan="2" id="buttons">
|
||||
<button name="process_export_ordini" string="Process" icon="tryton-go-next"/>
|
||||
</group>
|
||||
</form>
|
9
view/systemlogics_modula_exp_ordini_file_tree.xml
Normal file
9
view/systemlogics_modula_exp_ordini_file_tree.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part systemlogics_modula module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<tree string="SystemLogics">
|
||||
<field name="name"/>
|
||||
<field name="modula"/>
|
||||
<field name="state"/>
|
||||
<button name="process_export_ordini" string="Process" tree_invisible="1"/>
|
||||
</tree>
|
Loading…
Reference in a new issue