Wizard Export Articoli + XML template py loop

This commit is contained in:
resteve 2015-09-23 18:53:24 +02:00
parent 1eacbe4867
commit 086f8a1b14
10 changed files with 111 additions and 55 deletions

View file

@ -12,7 +12,11 @@ def register():
SystemLogicsModula, SystemLogicsModula,
Location, Location,
Product, Product,
ProductCode,
ShipmentOut, ShipmentOut,
ShipmentInternal, ShipmentInternal,
SystemlogicsModulaArticoli,
SystemlogicsModulaArticoliResult,
module='systemlogics_modula', type_='model') module='systemlogics_modula', type_='model')
Pool.register(
SystemlogicsModulaArticoli,
module='systemlogics_modula', type_='wizard')

View file

@ -2,8 +2,11 @@
#The COPYRIGHT file at the top level of this repository contains #The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms. #the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from trytond.model import ModelView, fields
from trytond.wizard import Wizard, StateTransition, StateView, Button
from trytond.transaction import Transaction
__all__ = ['Product', 'ProductCode'] __all__ = ['Product', 'SystemlogicsModulaArticoli', 'SystemlogicsModulaArticoliResult']
__metaclass__ = PoolMeta __metaclass__ = PoolMeta
@ -18,7 +21,7 @@ class Product:
systemlogics_products = [] systemlogics_products = []
for product in products: for product in products:
if product.code and not product.codes: if product.code:
systemlogics_products.append(product) systemlogics_products.append(product)
if systemlogics_products: if systemlogics_products:
SystemLogicsModula.imp_articoli(systemlogics_products) SystemLogicsModula.imp_articoli(systemlogics_products)
@ -33,43 +36,51 @@ class Product:
systemlogics_products = [] systemlogics_products = []
actions = iter(args) actions = iter(args)
for products, values in zip(actions, actions): for products, values in zip(actions, actions):
if values.get('code') and not values.get('codes'): # generate xml if code or codes changed
if values.get('code') or values.get('codes'):
systemlogics_products = products systemlogics_products = products
if systemlogics_products: if systemlogics_products:
SystemLogicsModula.imp_articoli(systemlogics_products) SystemLogicsModula.imp_articoli(systemlogics_products)
class ProductCode: class SystemlogicsModulaArticoliResult(ModelView):
__name__ = 'product.code' 'Systemlogics Modula Articoli Result'
__name__ = 'systemlogics.modula.articoli.result'
info = fields.Text('Info', readonly=True)
class SystemlogicsModulaArticoli(Wizard):
'Systemlogics Modula Articoli'
__name__ = 'systemlogics.modula.articoli'
start_state = 'export'
export = StateTransition()
result = StateView('systemlogics.modula.articoli.result',
'systemlogics_modula.systemlogics_modula_articoli_result', [
Button('Close', 'end', 'tryton-close'),
])
@classmethod @classmethod
def create(cls, vlist): def __setup__(cls):
super(SystemlogicsModulaArticoli, cls).__setup__()
cls._error_messages.update({
'export_info': 'Export %s product/s (IMP ARTICOLI)',
})
def transition_export(self):
pool = Pool() pool = Pool()
SystemLogicsModula = pool.get('systemlogics.modula')
Product = pool.get('product.product') Product = pool.get('product.product')
codes = super(ProductCode, cls).create(vlist)
vlist = [v.copy() for v in vlist]
systemlogics_products = set()
for values in vlist:
systemlogics_products.add(values.get('product'))
if systemlogics_products:
products = Product.browse(list(systemlogics_products))
SystemLogicsModula.imp_articoli(products)
return codes
@classmethod
def write(cls, *args):
pool = Pool()
SystemLogicsModula = pool.get('systemlogics.modula') SystemLogicsModula = pool.get('systemlogics.modula')
Product = pool.get('product.product')
super(ProductCode, cls).write(*args) products = Product.browse(Transaction().context['active_ids'])
SystemLogicsModula.imp_articoli(products)
self.result.info = self.raise_user_error('export_info',
(len(products)), raise_exception=False)
return 'result'
codes = sum(args[::2], []) def default_result(self, fields):
systemlogics_products = set(c.product for c in codes) info_ = self.result.info
if systemlogics_products: return {
products = Product.browse(list(systemlogics_products)) 'info': info_,
SystemLogicsModula.imp_articoli(products) }

29
product.xml Normal file
View file

@ -0,0 +1,29 @@
<?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. -->
<tryton>
<data>
<!-- systemlogics.modula.articoli.result - Wizard -->
<record model="ir.ui.view" id="systemlogics_modula_articoli_result">
<field name="model">systemlogics.modula.articoli.result</field>
<field name="type">form</field>
<field name="name">systemlogics_modula_articoli_result</field>
</record>
<record model="ir.action.wizard" id="wizard_systemlogics_modula_articoli">
<field name="name">Export Products Modula</field>
<field name="wiz_name">systemlogics.modula.articoli</field>
<field name="model">product.product</field>
</record>
<record model="ir.action.keyword" id="systemlogics_modula_articoli_keyword">
<field name="keyword">form_action</field>
<field name="model">product.product,-1</field>
<field name="action" ref="wizard_systemlogics_modula_articoli"/>
</record>
<record model="ir.action-res.group"
id="action_group_wizard_systemlogics_modula_articoli">
<field name="action" ref="wizard_systemlogics_modula_articoli"/>
<field name="group" ref="group_systemlogics_modula"/>
</record>
</data>
</tryton>

View file

@ -123,18 +123,17 @@ class SystemLogicsModula(ModelSQL, ModelView):
dbname = Transaction().cursor.dbname dbname = Transaction().cursor.dbname
for shipment in shipments: xml = tmpl.generate(
xml = tmpl.generate( shipments=shipments, type_=type_, datetime=datetime).render()
shipment=shipment, type_=type_, datetime=datetime).render()
with tempfile.NamedTemporaryFile( with tempfile.NamedTemporaryFile(
dir=systemlogic.path, dir=systemlogic.path,
prefix='%s-%s-' % (dbname, shipment.code), prefix='%s-' % (dbname),
suffix='.xml', delete=False) as temp: suffix='.xml', delete=False) as temp:
temp.write(xml) temp.write(xml)
logging.getLogger('systemlogics-modula').info( logging.getLogger('systemlogics-modula').info(
'Generated XML %s' % (temp.name)) 'Generated XML %s' % (temp.name))
temp.close() temp.close()
@classmethod @classmethod
def imp_articoli(self, products): def imp_articoli(self, products):
@ -189,14 +188,13 @@ class SystemLogicsModula(ModelSQL, ModelView):
dbname = Transaction().cursor.dbname dbname = Transaction().cursor.dbname
for product in products: xml = tmpl.generate(products=products).render()
xml = tmpl.generate(product=product).render()
with tempfile.NamedTemporaryFile( with tempfile.NamedTemporaryFile(
dir=systemlogic.path, dir=systemlogic.path,
prefix='%s-%s-' % (dbname, product.code or product.id), prefix='%s-' % (dbname),
suffix='.xml', delete=False) as temp: suffix='.xml', delete=False) as temp:
temp.write(xml) temp.write(xml.encode('utf-8'))
logging.getLogger('systemlogics-modula').info( logging.getLogger('systemlogics-modula').info(
'Generated XML %s' % (temp.name)) 'Generated XML %s' % (temp.name))
temp.close() temp.close()

View file

@ -5,12 +5,19 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<data> <data>
<!-- Groups --> <!-- Groups -->
<record model="res.group" id="group_systemlogics_modula_admin"> <record model="res.group" id="group_systemlogics_modula_admin">
<field name="name">SystemLogics Administration</field> <field name="name">SystemLogics Modula Administration</field>
</record> </record>
<record model="res.user-res.group" id="user_admin_group_systemlogics_modula_admin"> <record model="res.user-res.group" id="user_admin_group_systemlogics_modula_admin">
<field name="user" ref="res.user_admin"/> <field name="user" ref="res.user_admin"/>
<field name="group" ref="group_systemlogics_modula_admin"/> <field name="group" ref="group_systemlogics_modula_admin"/>
</record> </record>
<record model="res.group" id="group_systemlogics_modula">
<field name="name">SystemLogics Modula</field>
</record>
<record model="res.user-res.group" id="user_group_systemlogics_modula">
<field name="user" ref="res.user_admin"/>
<field name="group" ref="group_systemlogics_modula"/>
</record>
<!-- Menu Top --> <!-- Menu Top -->
<menuitem parent="stock.menu_configuration" <menuitem parent="stock.menu_configuration"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<SYSTORE_ARTICOLI xmlns:py="http://genshi.edgewall.org/"> <SYSTORE_ARTICOLI xmlns:py="http://genshi.edgewall.org/">
<IMP_ARTICOLI> <IMP_ARTICOLI py:for="product in products">
<ART_ARTICOLO>${product.code}</ART_ARTICOLO> <ART_ARTICOLO>${product.code}</ART_ARTICOLO>
<ART_DES>${product.rec_name[:100]}</ART_DES> <ART_DES>${product.rec_name[:100]}</ART_DES>
<ART_UMI>${product.default_uom.symbol}</ART_UMI> <ART_UMI>${product.default_uom.symbol}</ART_UMI>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<SYSTORE_ORDINI xmlns:py="http://genshi.edgewall.org/"> <SYSTORE_ORDINI xmlns:py="http://genshi.edgewall.org/">
<IMP_ORDINI> <IMP_ORDINI py:for="shipment in shipments">
<ORD_ORDINE>${shipment.code}</ORD_ORDINE> <ORD_ORDINE>${shipment.code}</ORD_ORDINE>
<ORD_DES>${shipment.reference and shipment.reference[:50]}</ORD_DES> <ORD_DES>${shipment.reference and shipment.reference[:50]}</ORD_DES>
<ORD_TIPOOP>${type_}</ORD_TIPOOP> <!-- P: Extracion / V: Deposito --> <ORD_TIPOOP>${type_}</ORD_TIPOOP> <!-- P: Extracion / V: Deposito -->

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<SYSTORE_ORDINI xmlns:py="http://genshi.edgewall.org/"> <SYSTORE_ORDINI xmlns:py="http://genshi.edgewall.org/">
<IMP_ORDINI> <IMP_ORDINI py:for="shipment in shipments">
<ORD_ORDINE>${shipment.code}</ORD_ORDINE> <ORD_ORDINE>${shipment.code}</ORD_ORDINE>
<ORD_DES>${shipment.reference and shipment.reference[:50]}</ORD_DES> <ORD_DES>${shipment.reference and shipment.reference[:50]}</ORD_DES>
<ORD_TIPOOP>${type_}</ORD_TIPOOP> <!-- P: Extracion / V: Deposito --> <ORD_TIPOOP>${type_}</ORD_TIPOOP> <!-- P: Extracion / V: Deposito -->

View file

@ -10,3 +10,4 @@ xml:
systemlogics.xml systemlogics.xml
systemlogics_data.xml systemlogics_data.xml
location.xml location.xml
product.xml

View file

@ -0,0 +1,6 @@
<?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="Export Product XML Modula">
<field name="info"/>
</form>