Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
13798 Weergaven

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..

Avatar
Annuleer
Beste antwoord
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"/>

Avatar
Annuleer
Auteur

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

Beste antwoord

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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
4
dec. 22
12083
1
nov. 16
4278
4
apr. 23
4313
1
okt. 22
5579
0
dec. 21
3044