This question has been flagged
2 Replies
4348 Views

Hello,

I have some problme to parwe my report in webkit, when i try to use some function i have this error :

(SyntaxError) invalid syntax (<unknown>, line 1) (u'get_barcode(product.ean13))') at line: 59 char: 19

(<class 'mako.exceptions.SyntaxException'>, SyntaxException("(SyntaxError) invalid syntax (<unknown>, line 1) (u'get_barcode(product.ean13))') at line: 59 char: 19",), <traceback object at 0xb5788ec>)

For me is the parser which doesn'tdo this work.

Below the arch of my module :

 

And now the different file to be sure:

In Root

__openerp__.py

{
    'name' : 'New webkit label for product',
    'description' : '''
       New product label in webkit with ean13 codebar and product image
    ''',
    'version' : '1',
    'depends' : [
        "product",
    ],
    'category': 'Tools',
    'author' : 'Aldebarande',
    'url': 'http://www.aldebarande.fr/',
    'website': 'http://www.aldebarande.fr/',
    'data': [],
    'update_xml': [
        'report/alde_data.xml',
        'report/alde_report.xml',
    ],
    'init_xml': [],
    "active": False,
    "installable": True,
    "application": True,

}

__init.py__

import report

in Report

alde_product_label.html.mako

<html>
<head>
    <style type="text/css">
            ${css}
        html,body{
            margin: 5;
            padding: 0;
            height: 100%;
        }
        .dest_table {
            width: 100%;
        }
        .sizes_table {
            width: 100%;
            border: solid 1px black;
        }
        .tablehead{
                font-weight: bold;
                border: 1px solid black;
                background-color: rgb(237, 237, 237);
                text-align: center;
                padding: 3px 5px;
                vertical-align: middle;
        }
        .table{
            text-align: center;
            padding: 3px 5px;
            vertical-align: middle;
            border: 1px solid black;
        }

        .container .total{
            width: 45%;
        }

        .container .total table{
            width: 85%;
            float: right;
        }
    </style>
</head>
<body>
    %for product in objects:
        <table>
            <tr>
                <td styme="vertical-align: middle;" width="33%">
                    ${product.name or ''}
                </td>
                <td width="33%">
                    %if product.product_image:
                        ${helper.embed_image("jpg",product.product_image, width=250, height=100)}
                    %endif
                </td>
                <td width="33%">
                    %if product.ean13:
                        <table>
                            <tr>
                                <td align="center"  style="padding: 7mm;">
                                    ${get_barcode(product.ean13))}
                                </td>
                            </tr>
                            <tr>
                                <td valign="center" align="center" style="font-size: 20px;" >
                                    ${product.ean13}
                                </td>
                            </tr>
                        </table>
                    %endif
                </td>
            </tr>
        </table>
        <br/>
    %endfor
</body>
</html>

alde_produc_label_report.py

from openerp.report import report_sxw
import base64
from osv import osv
from alde_ean13 import EanBarCode

class alde_product_label_report_parser(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(alde_product_label_report_parser, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'get_barcode': self.get_barcode,
        })

    #  ean13 picture generate
    def get_barcode(self, barcode_string):
        bar = EanBarCode()
        barcode_string = str(barcode_string)
        code = bar.getImage(barcode_string, 50, "png")
        output = StringIO.StringIO()
        code.save(output, format="PNG")
        data = base64.b64encode(output.getvalue())
        toreturn = '<img src="data:image/png;base64,%s" height="75" />' % (
            str(data))
        return toreturn

# Product_label Parse
report_sxw.report_sxw('report.alde.product.label', 'product.product', 'addons/alde_product_label/report/alde_product_label.html.mako', parser=alde_product_label_report_parser)

alde_report.xml

<?xml version="1.0"?>
<openerp>
    <data>

        <!--Label Product -->
        <!-- Remove old label Product report -->
        <delete model="ir.actions.report.xml" search="[('report_name','=','product.product.label')]" />

        <!-- New Label -->
        <report id="report_alde_product_label"  model="product.product"
                name="alde.product.label"
                string="Étiquettes de produits"
                file="alde_product_label/report/alde_product_label.html.mako"
                report_type="webkit"
                auto="False" />

        <record id="report_alde_product_label" model="ir.actions.report.xml">
            <field name="webkit_header" ref="label_header"/>
            <field name="no_multi_threading" eval="True"/>
        </record>

    </data>
</openerp>

__init.py__

import alde_product_label_report
import alde_ean13

I hope you can help me?

 

Thank you

regards

 

 

Avatar
Discard
Best Answer

This is the error as the log says

get_barcode(product.ean13))

which is too many closing parentheses.

Avatar
Discard
Author Best Answer

Yes it is.... Anyway thank you very much, it's maybe à little mistake but when you don't see it it's very annoying Thank you

Avatar
Discard

Jean did you get it working? can share your work?

Author

This is work, We didn't have git hub yet but maybe one day