Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
3755 Tampilan

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

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Penulis

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>

Penulis

Thank you so much sir it worked perfectly

Post Terkait Replies Tampilan Aktivitas
1
Jan 22
2540
1
Mar 15
5674
1
Mar 15
5556
3
Mei 23
3954
0
Jun 21
3007