콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
13965 화면

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
12172
1
11월 16
4367
4
4월 23
4400
1
10월 22
5652
0
12월 21
3133