跳至內容
選單
此問題已被標幟
2 回覆
13820 瀏覽次數

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

頭像
捨棄
最佳答案
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"/>

頭像
捨棄
作者

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

最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
4
12月 22
12087
1
11月 16
4288
4
4月 23
4314
1
10月 22
5588
0
12月 21
3052