Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3514 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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>

Autor

Thank you so much sir it worked perfectly

Powiązane posty Odpowiedzi Widoki Czynność
1
sty 22
2211
1
mar 15
5380
1
mar 15
5242
3
maj 23
3526
0
cze 21
2543