← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~dani-ds/avanzosc/dos_mrp_production_report into lp:~avanzosc-security-team/avanzosc/72horas

 

He puesto un comentario porque he visto que hay una línea de tipo en una de las vistas... el dos_contracts tiene las mismas vista ;)

Diff comments:

> === modified file 'dos_mrp_production_report/__init__.py'
> --- dos_mrp_production_report/__init__.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/__init__.py	2014-06-20 12:40:26 +0000
> @@ -1,5 +1,5 @@
>  ##############################################################################
> -#    
> +#
>  #    OpenERP, Open Source Management Solution
>  #    Copyright (C) 2004-2012 DOS (<http://www.dos-sl.es>).
>  #
> @@ -14,12 +14,11 @@
>  #    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
> +from . import reports
> +from . import wizard
>  
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> -
> 
> === modified file 'dos_mrp_production_report/__openerp__.py'
> --- dos_mrp_production_report/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/__openerp__.py	2014-06-20 12:40:26 +0000
> @@ -19,21 +19,18 @@
>  ##############################################################################
>  
>  {
> -	"name" : "DOS MRP Production Report",
> -	"version" : "1.0",
> -	"author" : "DOS",
> -	"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.dos-sl.es',
> -	"active": False,
> -	"installable": True,
> +    "name": "DOS MRP Production Report",
> +    "version": "1.0",
> +    "author": "DOS",
> +    "category": "Enterprise Specific Modules",
> +    "description": """Module to print labels from order productions with custom format.
> +    """,
> +    "depends": ["mrp"],
> +    "data": ['reports/mrp_production_report.xml',
> +             'wizard/mrp_production_wizard.xml',
> +             ],
> +    "demo": [],
> +    "website": 'http://www.dos-sl.es',
> +    "installable": True,
>  }
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === renamed directory 'dos_mrp_production_report/report' => 'dos_mrp_production_report/reports'
> === modified file 'dos_mrp_production_report/reports/__init__.py'
> --- dos_mrp_production_report/report/__init__.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/reports/__init__.py	2014-06-20 12:40:26 +0000
> @@ -18,8 +18,8 @@
>  #
>  ##############################################################################
>  
> -import mrp_production_label
> -import mrp_production_track_label
> +from . import mrp_production_label
> +from . import mrp_production_track_label
>  
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
>  
> 
> === modified file 'dos_mrp_production_report/reports/mrp_production_label.py'
> --- dos_mrp_production_report/report/mrp_production_label.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/reports/mrp_production_label.py	2014-06-20 12:40:26 +0000
> @@ -20,113 +20,96 @@
>  ##############################################################################
>  
>  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(report_sxw.rml_parse):
> -	def __init__(self, cr, uid, name, context):
> -		super(mrp_production_label_report, 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,
> -		})
> -		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_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','mrp.production','addons/dos_mrp_production_report/report/mrp_production_label.rml',parser=mrp_production_label_report)
> +
> +
> +class MrpProductionLabelReport(report_sxw.rml_parse):
> +
> +    def __init__(self, cr, uid, name, context):
> +        super(MrpProductionLabelReport, self).__init__(cr, uid, name,
> +                                                       context=context)
> +        vals = {'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,
> +                }
> +        self.localcontext.update(vals)
> +        self.context = context
> +        user = self.pool['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
> +            phone = partner  and partner.phone or ''
> +            format_phone = phone[0:3] + ' ' + phone[3:6] + ' ' + phone[6:9]
> +            res.append(partner and partner.name or "")
> +            res.append(partner and partner.street or '')
> +            res.append(partner and partner.city or '')
> +            res.append(partner and partner.zip or '')
> +            res.append(partner and partner.state_id and partner.state_id.name or '')
> +            res.append(phone)
> +            res.append(format_phone)
> +            res.append(partner and partner.email or '')
> +        else:
> +            for i in range(0, 7):
> +                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:
> +                    p_name = move_line.product_id.name
> +                    company = (p_name and p_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_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:
> +                    p_name = move_line.product_id.name
> +                    company = (p_name and p_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', 'mrp.production',
> +                      'addons/dos_mrp_production_report'
> +                      '/report/mrp_production_label.rml',
> +                      parser=MrpProductionLabelReport)
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === renamed file 'dos_mrp_production_report/mrp_production_report.xml' => 'dos_mrp_production_report/reports/mrp_production_report.xml'
> --- dos_mrp_production_report/mrp_production_report.xml	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/reports/mrp_production_report.xml	2014-06-20 12:40:26 +0000
> @@ -5,14 +5,14 @@
>  				string="Production Label"
>  				model="mrp.production"
>  				name="mrp.production.label.report"
> -				rml="dos_mrp_production_report/report/mrp_production_label.rml"
> +				rml="dos_mrp_production_report/reports/mrp_production_label.rml"
>  				header="False"
>  				auto="False" />
>  		<report id="mrp_production_track_label_report"
>  				string="Etiqueta de Enlace"
>  				model="mrp.production"
>  				name="mrp.production.track.label.report"
> -				rml="dos_mrp_production_report/report/mrp_production_track_label.rml"
> +				rml="dos_mrp_production_report/reports/mrp_production_track_label.rml"
>  				header="False"
>  				auto="False" />
>  	</data>
> 
> === modified file 'dos_mrp_production_report/reports/mrp_production_track_label.py'
> --- dos_mrp_production_report/report/mrp_production_track_label.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/reports/mrp_production_track_label.py	2014-06-20 12:40:26 +0000
> @@ -20,87 +20,68 @@
>  ##############################################################################
>  
>  import time
> -from datetime import datetime
>  from report import report_sxw
> -from osv import osv
> -from tools.translate import _
> -import pooler
> -
> -class mrp_production_track_label_report(report_sxw.rml_parse):
> -	def __init__(self, cr, uid, name, context):
> -		super(mrp_production_track_label_report, self).__init__(cr, uid, name, context=context)
> -		self.localcontext.update({
> -			'time': time,
> -			'get_company_address': self.get_company_address,
> -			'get_production_order_lines': self.get_production_order_lines,
> -		})
> -		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_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 enlaces que componen el pack
> -		for move_line in move_lines:
> -			product = {}
> -			
> -			if move_line.product_id and product_obj._is_link(move_line.product_id.categ_id):
> -				product["name"] = pack_lot
> -				res.append(product)
> -			
> -		return res
> -		
> -report_sxw.report_sxw('report.mrp.production.track.label.report','mrp.production','addons/dos_mrp_production_report/report/mrp_production_track_label.rml',parser=mrp_production_track_label_report)
> +
> +
> +class MrpProductionTrackLabelReport(report_sxw.rml_parse):
> +    def __init__(self, cr, uid, name, context):
> +        super(MrpProductionTrackLabelReport, self).__init__(cr, uid, name,
> +                                                            context=context)
> +        vals = {'time': time,
> +                'get_company_address': self.get_company_address,
> +                'get_production_order_lines': self.get_production_order_lines,
> +                }
> +        self.localcontext.update(vals)
> +        self.context = context
> +        user = self.pool['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
> +            phone = partner and partner.phone or ''
> +            format_phone = phone[0:3] + ' ' + phone[3:6] + ' ' + phone[6:9]
> +            res.append(partner and partner.name or "")
> +            res.append(partner and partner.street or '')
> +            res.append(partner and partner.city or '')
> +            res.append(partner and partner.zip or '')
> +            res.append(partner and partner.state_id and
> +                       partner.state_id.name or '')
> +            res.append(phone)
> +            res.append(format_phone)
> +            res.append(partner and partner.email or '')
> +        else:
> +            for i in range(0, 7):
> +                res.append(" ")
> +        return res
> +
> +    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 enlaces que componen el pack
> +        for move_line in move_lines:
> +            product = {}
> +            if (move_line.product_id and
> +                    product_obj._is_link(move_line.product_id.categ_id)):
> +                product["name"] = pack_lot
> +                res.append(product)
> +        return res
> +
> +report_sxw.report_sxw('report.mrp.production.track.label.report',
> +                      'mrp.production', 'addons/dos_mrp_production_report'
> +                      '/report/mrp_production_track_label.rml',
> +                      parser=MrpProductionTrackLabelReport)
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === modified file 'dos_mrp_production_report/wizard/__init__.py'
> --- dos_mrp_production_report/wizard/__init__.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/wizard/__init__.py	2014-06-20 12:40:26 +0000
> @@ -21,4 +21,4 @@
>  #
>  ##############################################################################
>  
> -import wizard_mrp_production_print
> \ No newline at end of file
> +from . import wizard_mrp_production_print
> \ No newline at end of file
> 
> === renamed file 'dos_mrp_production_report/mrp_production_wizard.xml' => 'dos_mrp_production_report/wizard/mrp_production_wizard.xml'
> --- dos_mrp_production_report/mrp_production_wizard.xml	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/wizard/mrp_production_wizard.xml	2014-06-20 12:40:26 +0000
> @@ -1,9 +1,44 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <openerp>
> -    <data>
> -        <wizard string="Print Production Labels" 
> -        		model="mrp.production"
> -        		name="mrp.production.print_labels" 
> -        		id="mrp_production_print_labels"/>
> -    </data>
> +	<data>
> +	
> +	<record id="view_print_production_labels" model="ir.ui.view">
> +		<field name="name">view.print.production.labels</field>
> +		<field name="model">wizard.print.labels</field>
> +		<field name="arch" type="xml">
> +			<form string="Print Production Labels" version="7.0">
> +				<separator string="The following production labels will be print:" colspan="4"/>
> +				<field name="text_print" nolabel="1" colspan="4" width="600" height="250" />
> +				<footer>
> +					<button class="oe_link" special="cancel" string="Cancel"/>
> +					<button  icon="gtk-ok" name="print_labels" string="Print" type="object"/>
> +				</footer>
> +				<newline />
> +			</form>
> +		</field>
> +	</record>
> +	
> +	<record id="view_done_form" model="ir.ui.view">
> +		<field name="name">view.done.form</field>
> +		<field name="model">wizard.print.labels</field>
> +		<field name="type">form</field>

Este form sobra, no?

> +		<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" readonly="1"/>
> +			<button class="oe_link" special="cancel" string="Done"/>
> +		</form>
> +		</field>
> +	</record>
> +
> +	<act_window 
> +		id= "mrp_production_print_labels"
> +		name= "Print Production Labels" 
> +		res_model= "wizard.print.labels"
> +		src_model= "mrp.production"
> +		key2= "client_action_multi"
> +		view_id = "view_print_production_labels"
> +		target ="new" />
> +
> +	</data>
>  </openerp>
> 
> === modified file 'dos_mrp_production_report/wizard/wizard_mrp_production_print.py'
> --- dos_mrp_production_report/wizard/wizard_mrp_production_print.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production_report/wizard/wizard_mrp_production_print.py	2014-06-20 12:40:26 +0000
> @@ -18,127 +18,115 @@
>  #
>  ##############################################################################
>  
> -import wizard
> -import pooler
> -import tools
>  
> -from tools.translate import _
> -from osv import fields,osv
> -import time
> +from openerp.tools.translate import _
> +from openerp.osv import fields, orm
>  import netsvc
> -from tools.misc import UpdateableStr, UpdateableDict
>  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', '=', 'Brother-QL-1060N-62x29')])
> -
> -	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
> -		result, format = create_report(cr, uid, [mrp.id], 'mrp.production.label.report', context={})
> -	
> -		# Imprimimos informe (dos etiquetas de sim)
> -		report_obj.print_direct(cr, uid, base64.encodestring(result), format, printer)
> -		report_obj.print_direct(cr, uid, base64.encodestring(result), format, printer)
> -
> -		qty_labels += 2
> -		
> -		# Etiqueta de enlace para 3bymesa
> -		move_lines = mrp.move_lines2 or mrp.move_lines or []
> -		if move_lines[0].product_id.id == 58 or move_lines[1].product_id.id == 58:
> -			result, format = create_report(cr, uid, [mrp.id], 'mrp.production.track.label.report', context={})
> -			report_obj.print_direct(cr, uid, base64.encodestring(result), format, printer)
> -			qty_labels += 1
> -		
> -	return {'qty_labels': qty_labels}
> -	
> -	
> -class print_labels(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('mrp.production.print_labels')
> +
> +class WizardPrintLabels(orm.TransientModel):
> +    _name = "wizard.print.labels"
> +    _description = "Module to print labels with custom format."
> +
> +    def _get_defaults(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'),
> +    }
> +
> +    _defaults = {
> +        'text_print': _get_defaults,
> +        'qty_labels': lambda self, cr, uid,
> +        context: context.get('qty_labels', 0)
> +    }
> +
> +    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 Brother-QL-1060N-62x29
> +        # TODO revisar impresion
> +        default_printer = printer_obj.search(cr, uid,
> +                                             [('system_name', '=',
> +                                               'Brother-QL-1060N-62x29')])
> +        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
> +            result, format = self.create_report(cr, uid, [mrp.id],
> +                                                'mrp.production.label.report',
> +                                                context={})
> +            # Imprimimos informe (dos etiquetas de sim)
> +            report_obj.print_direct(cr, uid, base64.encodestring(result),
> +                                    format, printer)
> +            report_obj.print_direct(cr, uid, base64.encodestring(result),
> +                                    format, printer)
> +            qty_labels += 2
> +            # Etiqueta de enlace para 3bymesa
> +            move_lines = mrp.move_lines2 or mrp.move_lines or []
> +            move_line1 = move_lines[0].product_id.id
> +            move_line2 = move_lines[1].product_id.id
> +            # TODO ids hardcode comparison
> +            if move_line1 == 58 or move_line2 == 58:
> +                res = self.create_report(cr, uid, [mrp.id],
> +                                         'mrp.production.track.label.report',
> +                                         context={})
> +                report_obj.print_direct(cr, uid, base64.encodestring(res),
> +                                        res, printer)
> +                qty_labels += 1
> +        data_obj = self.pool['ir.model.data']
> +        id2 = data_obj._get_id(cr, uid, 'dos_mrp_production_report',
> +                               'view_done_form')
> +        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
> +            }
> +
> +        def create_report(cr, uid, res_ids, report_name=False, context={}):
> +            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, e:
> +                print 'Exception in create report:', e
> +                raise orm.except_orm(_('Error !'),
> +                                     _('Exception in create report.'))
> +            return result, format
> 


-- 
https://code.launchpad.net/~dani-ds/avanzosc/dos_mrp_production_report/+merge/223603
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.


References