Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
13554 Widoki

Hello All,

i want to generate barcode based on my record unique sequence that i am generating in record creation time. I want to create barcode for all record and display in report.

How to do this without custom module. Can odoo provides inbuilt feature?

Thanks in advance..

Awatar
Odrzuć
Najlepsza odpowiedź
hope this works
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', o.your_sequence, 600, 100)" style="width:300px;height:50px"/>

Awatar
Odrzuć
Autor

Thanks Rakesh,

It's working for report/Qweb side. But how to do this for backend side, means when i am creating new record and when i save that record then i am generating sequence and set to field and i have taken one image(Binary field) to store barcode for the generated sequence then how it is possible in backend side,

I know that when we run /report/barcode.. controller then it generate barcode and return. But for backend side? how to easily call that controller or any easier way??

Thank you for help.. :D

hope this helps

@api.model

def create(self, vals):

res = super(yourmodel, self).create(vals)

"""Contoller able to render barcode images thanks to reportlab.

Samples:

<img t-att-src="'/report/barcode/QR/%s' % o.name"/>

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' %

('QR', o.name, 200, 200)"/>

:param type: Accepted types: 'Codabar', 'Code11', 'Code128', 'EAN13', 'EAN8', 'Extended39',

'Extended93', 'FIM', 'I2of5', 'MSI', 'POSTNET', 'QR', 'Standard39', 'Standard93',

'UPCA', 'USPS_4State'

:param humanreadable: Accepted values: 0 (default) or 1. 1 will insert the readable value

at the bottom of the output image

"""

try:

barcode = self.env['ir.actions.report'].barcode(type= param_type, value='your_sequence_number', width=width, height=height,

humanreadable='param humanreadable')

except (ValueError, AttributeError):

raise UserWarning('Cannot convert into barcode.')

import base64

barcode = base64.b64encode(barcode)

self.your_binary_field = barcode

return

Najlepsza odpowiedź

Hi,

In .py file:

def generate_barcode(self):
data = {
'response': self.name,
}
return self.env.ref('module_name.action_generate_barcode').report_action(self,data=data)

In Button Xml:

<header>


            <button name="generate_barcode" string="Generate Barcode" type="object"/>


</header>

In barcode_action.xml:

<?xml version="1.0" encoding="utf-8"?>


 <odoo>


       <record id="action_generate_barcode" model="ir.actions.report">


            <field name="name"> Barcode</field>


            <field name="model">module.name</field>


            <field name="report_type">qweb-pdf</field>


            <field name="report_name">module_name.print_barcode</field>


            <field name="report_file">module_name.print_barcode</field>


      </record>


</odoo>


In barcode_template.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="print_barcode_custom">
<t t-call="web.basic_layout">
<div class="page">
<div class="col-md-6">
<img class="barcode"
t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;humanreadable=1&amp;quiet=0' % ('Code128',response, 205, 67)"
alt="Barcode"/>
</div>
</div>
</t>
</template>
</odoo>

Regards

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
gru 22
11946
1
lis 16
4065
4
kwi 23
4192
1
paź 22
5420
0
gru 21
2887