This question has been flagged
2 Replies
6683 Views

I am trying to print multiple copies of a report depending on a fields value, (integer).


.py file 

http://pastebin.com/tW9YNHmA

import timefrom openerp.osv import osv, fieldsfrom openerp.report import report_sxw
import logging_logger = logging.getLogger(__name__)
class product_barcode_print(osv.osv_memory):
    _name = 'product.barcode.print' _description = 'Product Barcode Print'
    _columns = { #'date_start': fields.date('Date Start', required=True), #'date_end': fields.date('Date End', required=True), 'qty': fields.integer('Cantidad', help='Cantidad de unidades por palet'), 'lot_id': fields.many2one('stock.production.lot','Lote', help='Elegir el número de lote'), 'product_name': fields.related('lot_id', 'product_id', relation="product.product", type='many2one', string="Producto", store=True, readonly=True), 'medidas_op': fields.char('Medidas palets especiales', help='Opcional, para palets especiales'), 'ncopies': fields.integer('Nº de copias', help='Número de copias que se deben imprimir'), 'tipo_palet':fields.selection([('select_1', '1,2 x 0,8 x 2,1 metros - 54 kg'), ('select_2', '1,2 x 0,8 x 2,6 metros - 64 kg'), ('select_3', '1,2 x 1 x 2 metros - 215 kg'), ('select_4', '1,2 x 1 x 2,36 metros - 258 kg')], 'Medidas palet'),
    } #_defaults = { # 'date_start': lambda *a: time.strftime('%Y-%m-%d'), # 'date_end': lambda *a: time.strftime('%Y-%m-%d'), #} def onchange_lotid(self, cr, uid, ids, lot_id, context=None):
        value = {} product_product = self.pool.get('stock.production.lot') if lot_id:
            value = { 'product_name': product_product.browse(cr, uid, lot_id).product_id } return {'value': value}
    def print_report(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}
        data['form'] = self.read(cr, uid, ids, ['qty', 'lot_id','medidas_op','ncopies','tipo_palet','product_name'], context=context)[0] return self.pool['report'].get_action(cr, uid, [], 'product_barcode_qweb.report_product_barcode', data=data, context=context)
    def print_report_pdf(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}
        data['form'] = self.read(cr, uid, ids, ['qty', 'lot_id','medidas_op','ncopies','tipo_palet','product_name'], context=context)[0] return self.pool['report'].get_action(cr, uid, [], 'product_barcode_qweb.report_product_barcode', data=data, context=context)
    def get_copies(self):
        return self.env.context.get('ncopies')
class report_test1_parser(osv.AbstractModel):
    _name = 'report.product_barcode_qweb.report_product_barcode' _inherit = 'report.abstract_report' _template = 'product_barcode_qweb.report_product_barcode' _wrapped_report_class = report_parser


.xml file

http://pastebin.com/WAr0rRS0

<?xml version="1.0" encoding="utf-8"?><openerp>    <data>        <!--   product.barcode.print -->
        <record id="view_product_barcode_print" model="ir.ui.view"> <field name="name">product_barcode_print</field> <field name="model">product.barcode.print</field> <field name="arch" type="xml"> <form string="Imprimir pegatinas"> <group col="4" string="Imprimir pegatinas por lote"> <field name="lot_id" options='{"no_open": True, "no_create": True}' on_change="onchange_lotid(lot_id)"/>/> <field name="product_name"/> <field name="qty"/> <field name="ncopies"/> <field name="tipo_palet"/> <field name="medidas_op"/> </group> <group string="Información"> <p>&#9679; Botellones 4 plantas - (1,2 x 0,8 x 2,1 metros - 54 kg)<br/>&#9679; Botellones 5 plantas - (1,2 x 0,8 x 2,6 metros - 64 kg)<br/>&#9679; Tapones 5 plantas - (1,2 x 1 x 2 metros - 215 kg)<br/>&#9679; Tapones 6 plantas - (1,2 x 1 x 2,36 metros - 258 kg)</p> </group> <footer> <button name="print_report" type="object" string="IMPRIMIR PEGATINAS" class="oe_highlight"/> <button name="print_report_pdf" type="object" string="DESCARGAR PDF"/> <button string="Cancelar" class="oe_link" special="cancel"/> </footer> </form> </field> </record>
        <record id="action_report_product_barcode_print" model="ir.actions.act_window"> <field name="name">Product barcode print</field> <field name="type">ir.actions.act_window</field> <field name="res_model">product.barcode.print</field> <field name="view_type">form</field> <field name="view_mode">form</field> <field name="target">new</field> </record>
    </data></openerp>


report

http://pastebin.com/6nyGHSHw

<?xml version="1.0" encoding="utf-8"?><openerp><data><template id="report_product_barcode">    <t t-name="product_barcode_qweb.report_product_barcode">                <div class="page">      <t t-foreach="docs" t-as="o">          <t t-foreach="get_copies(0)" t-as="paltes">        <div style="float:left;width:500px;height:820px;margin:5px 5px 5px 5px;padding:3px;border:solid #434343 1px;">          <center>            <div style="font-size:12px">www.hods.eu</div>          </center>          <div style="float:center;width:100%;height:100%;overflow:hidden;padding-top:20px;text-align:left">            <div style="float:center;width:100%;height:140px;overflow:hidden;font-size:25px;">                 <img style="width:100%;height:28%;" t-att-src="'/report/barcode/Code128/%s' % o.product_name"/>              <br/>              <b>Ref: <span t-field="o.product_name"/></b>            </div>            <center>              <img src="http://hods.eu/uploads/pictogramas_fragil.png" width="365" height="360"/>            </center><br/>            <div style="font-size:15px;width:100%;float:center"><center><b>Lote:</b><span t-field="o.lot_id"/></center></div>          <center> <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', o.lot_id, 600, 100)" style="width:300px;height:50px"/></center><br/><br/><div style="font-size:16px;width:100%;float:left;height:300px">         <p><b>Cantidad:</b> <t t-esc="'{0:n}'.format(int(o.qty))" /></p>         <p><b>Dimensiones y peso</b></p>         <p><span t-field="o.tipo_palet"/></p></div>                    </div>          </div>       </t>      </t>    </div>  </t></template></data></openerp>


I cant make it work, I want to get that report "N" times to be printed, depending on field "ncopies".


Right now, I get this error:

QWebException: "'NoneType' object is not callable" while evaluating'get_copies(0)'



Thanks

Avatar
Discard
Best Answer

This part is wrong:

<div class="page">      <t t-foreach="docs" t-as="o">          <t t-foreach="get_copies(0)" t-as="paltes"> 

For that case you need to use range:

<t t-foreach="docs" t-as="o">
<t t-foreach="range(o.ncopies)" t-as="n">
<t t-call="module_document"/>
</t>
</t>

Hope it helps.

PS: If this helped you please mark the answer as correct.

Avatar
Discard