Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3734 Lượt xem

Hi I am using odoo 14 community version, i have downloaded and used the free module for images in purchase order lines https://apps.odoo.com/apps/modules/15.0/purchase_order_line_product_image/ 

it works really well i am facing one issue like if there is no data in image column it still shows a blank column in pdf report in purchase i want to display that image column only if there is an image otherwise it should be like normal pdf report , how is this possible ? what changes should i make in xml to achieve this goal 

Thank you for your time

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can achieve it using an if condition, first check at least one of the line in the one2many line contains the image and set this true or false to a variable and based on it, add an if condition in the report template.

Sample code of t if condition is below:

<t t-if="field.translate">
<td>image</td>
</t>

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Sir this is the phython code :
from odoo import api, fields, models, _

class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

image_128 = fields.Image(string="Image")

@api.onchange('product_id')
def onchange_purchase_product_image(self):
for product in self:
product.image_128 = product.product_id.image_128

This is the xml code :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="purchase_report_inherit_id" inherit_id="purchase.report_purchaseorder_document">
<xpath expr="//table[1]/thead/tr[1]/th[1]" position="after">
<th class="text-right">Image</th>
</xpath>
<xpath expr="//table[1]/tbody/t[2]/tr[1]/t[1]/td[1]" position="after">
<td class="text-right">
<img t-if="line.image_128" t-att-src="'data:image/png;base64,%s' % to_text(line.image_128)"
style="width: 150px;height: 150px"/>
</td>
</xpath>
</template>

<template id="purchase_quotation_report_inherit_id" inherit_id="purchase.report_purchasequotation_document">
<xpath expr="//table[1]/thead/tr[1]/th[1]" position="after">
<th class="text-right">Image</th>
</xpath>
<xpath expr="//table[1]/tbody/t[1]/tr[1]/t[1]/td[1]" position="after">
<td class="text-right">
<img t-if="order_line.image_128" t-att-src="'data:image/png;base64,%s' % to_text(order_line.image_128)"
style="width: 150px;height: 150px"/>
</td>
</xpath>
</template>

</odoo>

Can you please tell me what changes i should make here so i can achieve this

add your td inside this if condition:

<t t-if="any(line.image_128 for line in o.order_line)">
</t>

Tác giả

Thank you so much sir it worked perfectly

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 22
2531
1
thg 3 15
5660
1
thg 3 15
5546
3
thg 5 23
3939
0
thg 6 21
2985