Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

[SOLVED] Webkit Parser seems doesn't parse and i don't understand why?

By
Jean-Baptiste Bernard
on 9/19/14, 3:24 AM 1,593 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

 

 

1

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 9/22/14, 10:30 AM

This is the error as the log says

get_barcode(product.ean13))

which is too many closing parentheses.

1
Jean-Baptiste Bernard
On 9/22/14, 10:18 AM

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

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

JC
on 10/3/14, 2:06 AM

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

Aldébarande, Jean-Baptiste Bernard
on 2/10/15, 8:56 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/19/14, 3:24 AM
Seen: 1593 times
Last updated: 3/16/15, 8:10 AM