← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~oihanecruce/avanzosc/nayar_mrp_production_report into lp:~avanzosc-security-team/avanzosc/72horas

 

Review: Needs Fixing code review

Tres cosillas de nada y para adelante.

Un saludo.

Diff comments:

> === modified file 'nayar_mrp_production_report/__init__.py'
> --- nayar_mrp_production_report/__init__.py	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/__init__.py	2014-07-04 11:14:12 +0000
> @@ -1,5 +1,5 @@
>  ##############################################################################
> -#    
> +#
>  #    OpenERP, Open Source Management Solution
>  #    Copyright (C) 2004-2012 DOS (<http://www.dos-sl.es>).
>  #
> @@ -14,12 +14,9 @@
>  #    GNU Affero General Public License for more details.
>  #
>  #    You should have received a copy of the GNU Affero General Public License
> -#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
>  #
>  ##############################################################################
>  
> -import report
> -import wizard
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> -
> +from . import report
> +from . import wizard
> 
> === modified file 'nayar_mrp_production_report/__openerp__.py'
> --- nayar_mrp_production_report/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/__openerp__.py	2014-07-04 11:14:12 +0000
> @@ -19,21 +19,21 @@
>  ##############################################################################
>  
>  {
> -	"name" : "Nayar MRP Production Report",
> -	"version" : "1.0",
> -	"author" : "Nayar Systems",
> -	"category" : "Enterprise Specific Modules",
> -	"description":"""Module to print labels from order productions with custom format.
> -	""",
> -	"depends" : ["mrp"],
> -	"init_xml" : [],
> -	"demo_xml" : [],
> -	"update_xml" : [
> -		'mrp_production_report.xml',
> -		'mrp_production_wizard.xml',
> -	],
> -	"website": 'http://www.72horas.net',
> -	"active": False,
> -	"installable": True,
> +    "name": "Nayar MRP Production Report",
> +    "version": "1.0",
> +    "author": "Nayar Systems",
> +    "category": "Enterprise Specific Modules",
> +    "description": """
> +    Module to print labels from order productions with custom format.
> +    """,
> +    "depends": [
> +        "mrp",
> +    ],
> +    "data": [
> +        'report/mrp_production_report.xml',
> +        'wizard/mrp_production_wizard.xml',
> +    ],
> +    "website": 'http://www.72horas.net',
> +    "active": False,
> +    "installable": True,
>  }
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === modified file 'nayar_mrp_production_report/report/__init__.py'
> --- nayar_mrp_production_report/report/__init__.py	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/report/__init__.py	2014-07-04 11:14:12 +0000
> @@ -1,5 +1,5 @@
>  ##############################################################################
> -#    
> +#
>  #    OpenERP, Open Source Management Solution
>  #    Copyright (C) 2004-2012 DOS (<http://www.dos-sl.es>).
>  #
> @@ -14,11 +14,8 @@
>  #    GNU Affero General Public License for more details.
>  #
>  #    You should have received a copy of the GNU Affero General Public License
> -#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
>  #
>  ##############################################################################
>  
> -import mrp_production_label
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> -
> +from . import mrp_production_label
> 
> === modified file 'nayar_mrp_production_report/report/mrp_production_label.py'
> --- nayar_mrp_production_report/report/mrp_production_label.py	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/report/mrp_production_label.py	2014-07-04 11:14:12 +0000
> @@ -20,134 +20,146 @@
>  ##############################################################################
>  
>  import time
> -from datetime import datetime
>  from report import report_sxw
> -from osv import osv
> -from tools.translate import _
> -import pooler
> -
> -class mrp_production_label_report_zebra(report_sxw.rml_parse):
> -	def __init__(self, cr, uid, name, context):
> -		super(mrp_production_label_report_zebra, self).__init__(cr, uid, name, context=context)
> -		self.localcontext.update({
> -			'time': time,
> -			'get_company_address': self.get_company_address,
> -			'get_phone_info': self.get_phone_info,
> -			'get_production_order_lines': self.get_production_order_lines,
> -                        'get_prints': self.get_prints,
> -		})
> -		self.context = context
> -		user = self.pool.get('res.users').browse(cr, uid, uid)
> -		self.company = user.company_id
> -
> -	
> -	   
> -	def get_company_address (self, order):
> -		
> -		res = []
> -		
> -		company = order.company_id or self.company or None
> -		
> -		if company and company.partner_id:
> -			
> -			partner = company.partner_id
> -			addr_ids = self.pool.get('res.partner').address_get(self.cr, self.uid, [partner.id], ['default'])
> -			addr_id = addr_ids['default']
> -			addr = self.pool.get('res.partner.address').browse(self.cr, self.uid, addr_id)
> -			
> -			phone = addr and addr.phone or ''
> -			format_phone = phone[0:3] + ' ' + phone[3:6] + ' ' + phone[6:9]
> -			
> -			res.append(partner and partner.name or "")
> -			res.append(addr and addr.street or '')
> -			res.append(addr and addr.city or '')
> -			res.append(addr and addr.zip or '')
> -			res.append(addr and addr.state_id and addr.state_id.name or '')
> -			res.append(phone)
> -			res.append(format_phone)
> -			res.append(addr and addr.email or '')
> -			
> -		else:
> -			
> -			res.append(" ")
> -			res.append(" ")
> -			res.append(" ")
> -			res.append(" ")
> -			res.append(" ")
> -			res.append(" ")
> -			res.append(" ")
> -			res.append(" ")
> -			
> -		return res
> -				
> -	def get_phone_info (self, order):
> -		
> -		product_obj = self.pool.get('product.product')
> -		product = {}
> -		move_lines = order.move_lines2 or order.move_lines or []
> -	 
> -		for move_line in move_lines:
> -
> -			if move_line.product_id and product_obj._is_sim(move_line.product_id.categ_id):
> -				company = move_line.prodlot_id and move_line.prodlot_id.operador or False
> -				if not company:
> -					company = move_line.product_id.name and move_line.product_id.name.replace('Tarjeta SIM ', '') or ''
> -			
> -				product["phone"] = move_line.prodlot_id and move_line.prodlot_id.telefono or ''
> -				product["company"] = company
> -				
> -		return product
> -        
> -        def get_stock_production_lot(self, lot):
> -                res = []
> -                product = {}
> -                product["name"] = lot.imei or ""
> -                product["phone"] = lot.telefono or ""
> -                product["company"] = lot.operador or ""
> +
> +
> +class MrpProductionLabelReportZebra(report_sxw.rml_parse):
> +    def __init__(self, cr, uid, name, context):
> +        super(MrpProductionLabelReportZebra, self).__init__(cr, uid, name,
> +                                                            context=context)
> +        self.localcontext.update({
> +            'time': time,
> +            'get_company_address': self.get_company_address,
> +            'get_phone_info': self.get_phone_info,
> +            'get_production_order_lines': self.get_production_order_lines,
> +            'get_prints': self.get_prints,
> +        })
> +        self.context = context
> +        user = self.pool.get('res.users').browse(cr, uid, uid)

self.pool[] y propagar context

> +        self.company = user.company_id
> +
> +    def get_company_address(self, order):
> +        partner_obj = self.pool['res.partner']
> +        res = []
> +
> +        company = order.company_id or self.company or None
> +
> +        if company and company.partner_id:
> +            partner = company.partner_id
> +            addr_ids = partner_obj.address_get(self.cr, self.uid, [partner.id],
> +                                               ['default'])
> +            addr_id = addr_ids['default']
> +            addr = partner_obj.browse(self.cr, self.uid, addr_id)
> +
> +            phone = addr and addr.phone or ''
> +            format_phone = phone[0:3] + ' ' + phone[3:6] + ' ' + phone[6:9]
> +
> +            res.append(partner and partner.name or "")
> +            res.append(addr and addr.street or '')
> +            res.append(addr and addr.city or '')
> +            res.append(addr and addr.zip or '')
> +            res.append(addr and addr.state_id and addr.state_id.name or '')
> +            res.append(phone)
> +            res.append(format_phone)
> +            res.append(addr and addr.email or '')
> +
> +        else:
> +            res.append(" ")

poner:

for i in range(8):
    res.append(" ")

> +            res.append(" ")
> +            res.append(" ")
> +            res.append(" ")
> +            res.append(" ")
> +            res.append(" ")
> +            res.append(" ")
> +            res.append(" ")
> +
> +        return res
> +
> +    def get_phone_info(self, order):
> +        product_obj = self.pool['product.product']
> +        product = {}
> +        move_lines = order.move_lines2 or order.move_lines or []
> +
> +        for move_line in move_lines:
> +
> +            if (move_line.product_id and
> +                    product_obj._is_sim(move_line.product_id.categ_id)):
> +                company = (move_line.prodlot_id and
> +                           move_line.prodlot_id.operador or False)
> +                if not company:
> +                    company = (
> +                        move_line.product_id.name and
> +                        move_line.product_id.name.replace('Tarjeta SIM ', '')
> +                        or '')
> +
> +                product["phone"] = (move_line.prodlot_id and
> +                                    move_line.prodlot_id.telefono or '')
> +                product["company"] = company
> +
> +        return product
> +
> +    def get_stock_production_lot(self, lot):
> +        res = []
> +        product = {}
> +        product["name"] = lot.imei or ""
> +        product["phone"] = lot.telefono or ""
> +        product["company"] = lot.operador or ""
> +        res.append(product)
> +        return res
> +
> +    def get_prints(self, order_or_lot):
> +        # Es una orden de producción
> +        if order_or_lot._name == "mrp.production":
> +            return self.get_production_order_lines(order_or_lot)
> +        # Es un lote de producción (PACK)
> +        elif order_or_lot._name == "stock.production.lot":
> +            return self.get_stock_production_lot(order_or_lot)
> +
> +    def get_production_order_lines(self, order):
> +        product_obj = self.pool['product.product']
> +        res = []
> +        move_lines = order.move_lines2 or order.move_lines or []
> +
> +        move_finished_lines = (order.move_created_ids2 or
> +                               order.move_created_ids or [])
> +        pack_lot = ""
> +
> +        # Obtenemos lote de produccion del producto finalizado (pack)
> +        for move_line in move_finished_lines:
> +            if (move_line.product_id and
> +                    product_obj._is_pack(move_line.product_id.categ_id)):
> +                pack_lot = (move_line.prodlot_id and
> +                            move_line.prodlot_id.name or '')
> +                break
> +
> +        # Obtenemos lineas de teléfono que compones el pack
> +        for move_line in move_lines:
> +            product = {}
> +
> +            if (move_line.product_id and
> +                    product_obj._is_sim(move_line.product_id.categ_id)):
> +                company = (move_line.prodlot_id and
> +                           move_line.prodlot_id.operador or False)
> +                if not company:
> +                    company = (
> +                        move_line.product_id.name and
> +                        move_line.product_id.name.replace('Tarjeta SIM ', '')
> +                        or '')
> +
> +                product["name"] = pack_lot
> +                product["phone"] = (move_line.prodlot_id and
> +                                    move_line.prodlot_id.telefono or '')
> +                product["company"] = company
> +
>                  res.append(product)
> -                return res
> -
> -
> -        def get_prints(self, order_or_lot):
> -                if order_or_lot._name == "mrp.production": #Es una orden de production
> -                    return self.get_production_order_lines(order_or_lot)
> -                elif order_or_lot._name == "stock.production.lot": #Es un lote de produccion (PACK)
> -                    return self.get_stock_production_lot(order_or_lot)
> -								
> -	def get_production_order_lines(self, order):
> -		
> -		product_obj = self.pool.get('product.product')
> -		res = []
> -		move_lines = order.move_lines2 or order.move_lines or []
> -		
> -		move_finished_lines = order.move_created_ids2 or order.move_created_ids or []
> -		pack_lot = ""
> -		
> -		# Obtenemos lote de produccion del producto finalizado (pack)
> -		for move_line in move_finished_lines:
> -			if move_line.product_id and product_obj._is_pack(move_line.product_id.categ_id):
> -				pack_lot = move_line.prodlot_id and move_line.prodlot_id.name or ''
> -				break
> -				
> -		# Obtenemos lineas de teléfono que compones el pack
> -		for move_line in move_lines:
> -			product = {}
> -			
> -			if move_line.product_id and product_obj._is_sim(move_line.product_id.categ_id):
> -				company = move_line.prodlot_id and move_line.prodlot_id.operador or False
> -				if not company:
> -					company = move_line.product_id.name and move_line.product_id.name.replace('Tarjeta SIM ', '') or ''
> -			
> -				product["name"] = pack_lot
> -				product["phone"] = move_line.prodlot_id and move_line.prodlot_id.telefono or ''
> -				product["company"] = company
> -				
> -				res.append(product)
> -			
> -		return res
> -		
> -report_sxw.report_sxw('report.mrp.production.label.report.zebra','mrp.production','addons/nayar_mrp_production_report/report/mrp_production_label.rml',parser=mrp_production_label_report_zebra)
> -report_sxw.report_sxw('report.stock.production.lot.label.report.zebra','stock.production.lot','addons/nayar_mrp_production_report/report/mrp_production_label.rml',parser=mrp_production_label_report_zebra)
> -
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> +
> +        return res
> +
> +report_sxw.report_sxw('report.mrp.production.label.report.zebra',
> +                      'mrp.production',
> +                      'addons/nayar_mrp_production_report/report/mrp_production_label.rml',
> +                      parser=MrpProductionLabelReportZebra)
> +report_sxw.report_sxw('report.stock.production.lot.label.report.zebra',
> +                      'stock.production.lot',
> +                      'addons/nayar_mrp_production_report/report/mrp_production_label.rml',
> +                      parser=MrpProductionLabelReportZebra)
> 
> === renamed file 'nayar_mrp_production_report/mrp_production_report.xml' => 'nayar_mrp_production_report/report/mrp_production_report.xml'
> --- nayar_mrp_production_report/mrp_production_report.xml	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/report/mrp_production_report.xml	2014-07-04 11:14:12 +0000
> @@ -1,19 +1,13 @@
>  <?xml version="1.0"?>
>  <openerp>
> -	<data>
> -		<report id="mrp_production_label_report_zebra"
> -				string="Production Label Zebra"
> -				model="mrp.production"
> -				name="mrp.production.label.report.zebra"
> -				rml="nayar_mrp_production_report/report/mrp_production_label.rml"
> -				header="False"
> -				auto="False" />
> -		<report id="stock_production_lot_report_zebra"
> -				string="Production Label Zebra"
> -				model="stock.production.lot"
> -				name="stock.production.lot.label.report.zebra"
> -				rml="nayar_mrp_production_report/report/mrp_production_label.rml"
> -				header="False"
> -				auto="False" />
> -</data>
> +    <data>
> +        <report id="mrp_production_label_report_zebra" string="Production Label Zebra"
> +            model="mrp.production" name="mrp.production.label.report.zebra"
> +            rml="nayar_mrp_production_report/report/mrp_production_label.rml"
> +            header="False" auto="False" />
> +        <report id="stock_production_lot_report_zebra" string="Production Label Zebra"
> +            model="stock.production.lot" name="stock.production.lot.label.report.zebra"
> +            rml="nayar_mrp_production_report/report/mrp_production_label.rml"
> +            header="False" auto="False" />
> +    </data>
>  </openerp>
> 
> === modified file 'nayar_mrp_production_report/wizard/__init__.py'
> --- nayar_mrp_production_report/wizard/__init__.py	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/wizard/__init__.py	2014-07-04 11:14:12 +0000
> @@ -2,9 +2,9 @@
>  ##############################################################################
>  #
>  #    OpenERP, Open Source Management Solution
> -#    Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
> +#    Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com)
> +#                                        All Rights Reserved.
>  #                       Jordi Esteve <jesteve@xxxxxxxxxxxxxxx>
> -#    $Id$
>  #
>  #    This program is free software: you can redistribute it and/or modify
>  #    it under the terms of the GNU General Public License as published by
> @@ -21,4 +21,4 @@
>  #
>  ##############################################################################
>  
> -import wizard_mrp_production_print
> \ No newline at end of file
> +from . import wizard_mrp_production_print
> 
> === renamed file 'nayar_mrp_production_report/mrp_production_wizard.xml' => 'nayar_mrp_production_report/wizard/mrp_production_wizard.xml'
> --- nayar_mrp_production_report/mrp_production_wizard.xml	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/wizard/mrp_production_wizard.xml	2014-07-04 11:14:12 +0000
> @@ -1,14 +1,45 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <openerp>
>      <data>
> -        <wizard string="Print Production Labels Zebra"
> -        		model="mrp.production"
> -        		name="mrp.production.print_labels_zebra" 
> -        		id="mrp_production_print_labels_zebra"/>
> -        <wizard string="Print Production Labels Zebra"
> -        		model="stock.production.lot"
> -        		name="mrp.production.print_lot_labels_zebra" 
> -        		id="mrp_lot_print_labels_zebra"/>
> - 
> +        <record model="ir.ui.views" id="print_production_zebra_labels_view">
> +            <field name="name">wizard.print.production.labels</field>
> +            <field name="model">wizard.print.zebra.labels.mrp</field>
> +            <field name="arch" type="xml">
> +                <form string="Print Production Labels">
> +                    <separator
> +                        string="The following production labels will be print:"
> +                        colspan="4" />
> +                    <field name="text_print" nolabel="1" colspan="4"
> +                        width="600" height="250" />
> +                    <newline />
> +                </form>
> +            </field>
> +        </record>
> +
> +        <record model="ir.ui.views" id="print_production_zebra_labels_done_view">
> +            <field name="name">wizard.print.production.labels.done
> +            </field>
> +            <field name="model">wizard.print.zebra.labels.mrp</field>
> +            <field name="arch" type="xml">
> +                <form string="Print Production Labels">
> +                    <separator
> +                        string="Production labels have been successfully sent to print"
> +                        colspan="4" />
> +                    <field name="qty_labels" />
> +                </form>
> +            </field>
> +        </record>
> +
> +        <act_window id="mrp_production_print_zebra_labels" name="Print Production Labels"
> +            res_model="wizard.print.zebra.labels.mrp" src_model="mrp.production"
> +            key2="client_action_multi" view_id="print_production_zebra_labels_view"
> +            target="new" />
> +
> +        <act_window id="production_lot_print_zebra_labels" name="Print Production Labels"
> +            res_model="wizard.print.zebra.labels.mrp" src_model="stock.production.lot"
> +            key2="client_action_multi" view_id="print_production_zebra_labels_view"
> +            target="new" />
> +
> +
>      </data>
>  </openerp>
> 
> === modified file 'nayar_mrp_production_report/wizard/wizard_mrp_production_print.py'
> --- nayar_mrp_production_report/wizard/wizard_mrp_production_print.py	2014-06-11 10:23:47 +0000
> +++ nayar_mrp_production_report/wizard/wizard_mrp_production_print.py	2014-07-04 11:14:12 +0000
> @@ -18,152 +18,103 @@
>  #
>  ##############################################################################
>  
> -import wizard
> -import pooler
> -import tools
> -
> -from tools.translate import _
> -from osv import fields,osv
> -import time
> -import netsvc
> -from tools.misc import UpdateableStr, UpdateableDict
> +from openerp.tools.translate import _
> +from openerp.osv import fields, orm
> +from openerp import netsvc
>  import base64
>  
> -print_init_form = '''<?xml version="1.0" encoding="utf-8"?>
> -<form string="Print Production Labels">
> -	<separator string="The following production labels will be print:" colspan="4"/>
> -	<field name="text_print" nolabel="1" colspan="4" width="600" height="250" />
> -	<newline />
> -</form>'''
> -
> -print_init_fields = {
> -	'text_print': {'string':'Message', 'type':'text', 'readonly':True},
> -}
> -
> -print_done_form = '''<?xml version="1.0" encoding="utf-8"?>
> -<form string="Print Production Labels">
> -	<separator string="Production labels have been successfully sent to print" colspan="4"/>
> -	<field name="qty_labels"/>
> -</form>'''
> -
> -print_done_fields = {
> -	'qty_labels': {'string':'Printed Labels', 'type':'integer', 'readonly': True},
> -}
> -
> -
> -def _get_defaults(self, cr, uid, data, context):
> -	p = pooler.get_pool(cr.dbname)
> -	user = p.get('res.users').browse(cr, uid, uid, context)
> -	
> -	text_print = ''
> -	i = 0
> -	
> -	mrp_productions = p.get(data['model']).browse(cr, uid, data['ids'], context)
> - 
> -	for mrp in mrp_productions:
> -
> -		i += 1
> -		name = mrp.name or ''
> -		product_name = mrp.product_id and mrp.product_id.name or ''
> -			
> -		text_print += str(i) + '. ' + name + ' - ' + product_name + '\n'
> -			
> -	return {'text_print': text_print}
> -
> -
> -def create_report(cr, uid, res_ids, report_name=False, context={}):
> -	if not report_name or not res_ids:
> -		raise osv.except_osv(_('Error !'),_('Report name and Resources ids are required !!!'))
> -	
> -	try:
> -		service = netsvc.LocalService("report."+report_name);
> -		result, format = service.create(cr, uid, res_ids, {}, context)
> -		
> -	except Exception,e:
> -		print 'Exception in create report:',e
> -		raise osv.except_osv(_('Error !'),_('Exception in create report.'))
> -	
> -	return result, format
> -
> -
> -def _print_labels(self, cr, uid, data, context):
> -	import re
> -	p = pooler.get_pool(cr.dbname)
> -	user = p.get('res.users').browse(cr, uid, uid, context)
> -	
> -	report_obj = p.get('ir.actions.report.xml')
> -	printer_obj = p.get('printing.printer')
> -	
> -	qty_labels = 0
> -	
> -	# Obtenemos la impresora Brother-QL-1060N-62x29
> -	default_printer = printer_obj.search(cr, uid, [('system_name', '=', 'Zebra_Technologies_ZTC_GK420t')])
> -
> -	if default_printer:
> -		default_printer = default_printer[0]
> -		printer = printer_obj.browse(cr, uid, default_printer, context).system_name
> -	else:
> -		raise osv.except_osv(_('Error !'),_('Not found any default printer. Please set the default printer.')) 
> -	
> -	
> -	mrp_productions = p.get(data['model']).browse(cr, uid, data['ids'], context)
> -
> -	for mrp in mrp_productions:
> -		
> -		# Creamos informe
> -                if mrp._name == "mrp.production":
> -		    result, format = create_report(cr, uid, [mrp.id], 'mrp.production.label.report.zebra', context={})
> -                elif mrp._name == "stock.production.lot":
> -                    result, format = create_report(cr, uid, [mrp.id], 'stock.production.lot.label.report.zebra', context={})
> - 
> -	
> -		# Imprimimos informe (solo una etiqueta)
> -		report_obj.print_direct(cr, uid, base64.encodestring(result), format, printer)
> -		#report_obj.print_direct(cr, uid, base64.encodestring(result), format, printer)
> -
> -		qty_labels += 1
> -		
> -	
> -	return {'qty_labels': qty_labels}
> -	
> -	
> -class print_labels_zebra(wizard.interface):
> -	states = {
> -		'init': {
> -			'actions': [_get_defaults],
> -			'result': {'type': 'form', 'arch': print_init_form, 'fields': print_init_fields, 'state':[('end','Cancel'), ('done','Print')]}
> -		},
> -		'done': {
> -			'actions': [_print_labels],
> -			'result': {'type': 'form', 'arch': print_done_form, 'fields': print_done_fields, 'state': [('end', 'Close')] }
> -		}
> -	}
> -
> -
> -class print_labels_zebra(wizard.interface):
> -	states = {
> -		'init': {
> -			'actions': [_get_defaults],
> -			'result': {'type': 'form', 'arch': print_init_form, 'fields': print_init_fields, 'state':[('end','Cancel'), ('done','Print')]}
> -		},
> -		'done': {
> -			'actions': [_print_labels],
> -			'result': {'type': 'form', 'arch': print_done_form, 'fields': print_done_fields, 'state': [('end', 'Close')] }
> -		}
> -	}
> -
> -class print_lot_labels_zebra(wizard.interface):
> -	states = {
> -		'init': {
> -			'actions': [_get_defaults],
> -			'result': {'type': 'form', 'arch': print_init_form, 'fields': print_init_fields, 'state':[('end','Cancel'), ('done','Print')]}
> -		},
> -		'done': {
> -			'actions': [_print_labels],
> -			'result': {'type': 'form', 'arch': print_done_form, 'fields': print_done_fields, 'state': [('end', 'Close')] }
> -		}
> -	}
> -	
> -		
> -print_labels_zebra('mrp.production.print_labels_zebra')
> -print_lot_labels_zebra('mrp.production.print_lot_labels_zebra')
> +
> +class PrintLabelsZebra(orm.TransientModel):
> +    _name = 'wizard.print.zebra.labels.mrp'
> +
> +    def _get_default_text(self, cr, uid, context):
> +        res = {}
> +        if 'active_model' in context and 'active_ids' in context:
> +            model = context['active_model']
> +            ids = context['active_ids']
> +            text_print = ''
> +            i = 0
> +            mrp_productions = self.pool[model].browse(cr, uid, ids, context)
> +            for mrp in mrp_productions:
> +                i += 1
> +                name = mrp.name or ''
> +                product_name = mrp.product_id and mrp.product_id.name or ''
> +                text_print += (str(i) + '. ' + name +
> +                               ' - ' + product_name + '\n')
> +            res = text_print
> +        return res
> +
> +    _columns = {
> +        'text_print': fields.text('Message', readonly=True),
> +        'qty_labels': fields.integer('Printed Labels', readonly=True),
> +    }
> +
> +    _defaults = {
> +        'text_print': _get_default_text,
> +    }
> +
> +    def create_report(cr, uid, res_ids, report_name=False, context={}):

Mejor context=None

> +        if not report_name or not res_ids:
> +            raise orm.except_orm(_('Error !'),
> +                                 _('Report name and Resources ids'
> +                                   ' are required !!!'))
> +        try:
> +            service = netsvc.LocalService("report." + report_name)
> +            result, format = service.create(cr, uid, res_ids, {}, context)
> +        except Exception:
> +            raise orm.except_orm(_('Error !'),
> +                                 _('Exception in create report.'))
> +        return result, format
> +
> +    def print_labels(self, cr, uid, data, context):
> +        report_obj = self.pool['ir.actions.report.xml']
> +        printer_obj = self.pool['printing.printer']
> +        qty_labels = 0
> +        # Obtenemos la impresora Zebra Technologies ZTC GK420t
> +        # TODO revisar impresion
> +        default_printer = printer_obj.search(
> +            cr, uid, [('system_name', '=', 'Zebra_Technologies_ZTC_GK420t')])
> +        if default_printer:
> +            default_printer = default_printer[0]
> +            printer = printer_obj.browse(cr, uid, default_printer,
> +                                         context).system_name
> +        else:
> +            raise orm.except_orm(_('Error !'),
> +                                 _('Not found any default printer. '
> +                                   'Please set the default printer.'))
> +        mrp_productions = self.pool[data['model']].browse(cr, uid,
> +                                                          data['ids'],
> +                                                          context)
> +        for mrp in mrp_productions:
> +            # Creamos informe
> +            if mrp._name == "mrp.production":
> +                result, format = self.create_report(
> +                    cr, uid, [mrp.id],
> +                    'mrp.production.label.report.zebra',
> +                    context={})
> +            elif mrp._name == "stock.production.lot":
> +                result, format = self.create_report(
> +                    cr, uid, [mrp.id],
> +                    'stock.production.lot.label.report.zebra',
> +                    context={})
> +            # Imprimimos informe
> +            report_obj.print_direct(cr, uid, base64.encodestring(result),
> +                                    format, printer)
> +            qty_labels += 1
> +
> +        data_obj = self.pool['ir.model.data']
> +        id2 = data_obj._get_id(cr, uid, 'nayar_mrp_production_report',
> +                               'print_production_zebra_labels_done_view')
> +        if id2:
> +            id2 = data_obj.browse(cr, uid, id2, context=context).res_id
> +            context['qty_labels'] = qty_labels
> +        return {
> +            'view_type': 'form',
> +            'view_mode': 'form',
> +            'res_model': 'wizard.print.labels',
> +            'views': [(id2, 'form')],
> +            'view_id': False,
> +            'type': 'ir.actions.act_window',
> +            'target': 'new',
> +            'context': context
> +        }
> 


-- 
https://code.launchpad.net/~oihanecruce/avanzosc/nayar_mrp_production_report/+merge/225639
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.


References