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,
Location,
Product,
ProductCode,
ShipmentOut,
ShipmentInternal,
SystemlogicsModulaArticoli,
SystemlogicsModulaArticoliResult,
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 full copyright notices and license terms.
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
@ -18,7 +21,7 @@ class Product:
systemlogics_products = []
for product in products:
if product.code and not product.codes:
if product.code:
systemlogics_products.append(product)
if systemlogics_products:
SystemLogicsModula.imp_articoli(systemlogics_products)
@ -33,43 +36,51 @@ class Product:
systemlogics_products = []
actions = iter(args)
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
if systemlogics_products:
SystemLogicsModula.imp_articoli(systemlogics_products)
class ProductCode:
__name__ = 'product.code'
class SystemlogicsModulaArticoliResult(ModelView):
'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
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()
SystemLogicsModula = pool.get('systemlogics.modula')
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')
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], [])
systemlogics_products = set(c.product for c in codes)
if systemlogics_products:
products = Product.browse(list(systemlogics_products))
SystemLogicsModula.imp_articoli(products)
def default_result(self, fields):
info_ = self.result.info
return {
'info': info_,
}

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,3 +10,4 @@ xml:
systemlogics.xml
systemlogics_data.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>