跳至內容
選單
此問題已被標幟
1 回覆
3728 瀏覽次數

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

頭像
捨棄
最佳答案

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

頭像
捨棄
作者

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>

作者

Thank you so much sir it worked perfectly

相關帖文 回覆 瀏覽次數 活動
1
1月 22
2531
1
3月 15
5660
1
3月 15
5545
3
5月 23
3939
0
6月 21
2985