Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3729 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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>

Autore

Thank you so much sir it worked perfectly

Post correlati Risposte Visualizzazioni Attività
1
gen 22
2531
1
mar 15
5660
1
mar 15
5545
3
mag 23
3939
0
giu 21
2985