تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
30530 أدوات العرض

I'm using Odoo 8 and I've inherited account.invoice.line and added a new field:



class account_invoice_line(models.Model):
_inherit = "account.invoice.line"

price_unit_currency = fields.Float('Prix-Unitaire-Devise', store=False, readonly=True,
compute='_compute_pu_currency',
default=0.)

@api.one
def _compute_pu_currency(self):
self.price_unit_currency = line.price_unit * 1.28


In my report, I can print that field (first column) but doesn't show up in the second column:​


<tr t-foreach="o.invoice_line" t-as="l">
<td>
<span t-esc="l.price_unit_currency"/>
</td>
<td>
<span t-field="l.price_unit_currency"/>
</td>
</tr>


When I generate my report, I get this error in the log:

2019-12-30 20:09:09,820 329299 WARNING My_Super_Module openerp.addons.base.ir.ir_qweb: Could not get field price_unit_currency for model account.invoice.line


I'd just like to understand why it works with t-esc, and not with t-field. https://www.odoo.com/documentation/8.0/reference/qweb.html didn't really helped me understand the mechanism but I suspect t-field to only work on stored fields, is that the case ? Where can I learn more about that ?

Thanks in advance to the community :)

الصورة الرمزية
إهمال
أفضل إجابة

Hello Paraita Wohler,

Let us describe to you in more detail. 

QWeb has a primary output directive which automatically HTML-escape. es​c takes an expression, evaluates it and prints the content.

For example, if you want to get the data from a python dictionary.  

<t t-esc="dict['key']"/>

Simply, t-esc allows you to evaluate code runtime like python code and print it. 

Where t-field directive can only be used when performing field access (Only work on stored fields) and formatting data according to the field type. Also, t-field-options can be used to customize fields. See below example, 

<t-field="o.date" t-field-options='{"widget":"date"'}'/>
الصورة الرمزية
إهمال
أفضل إجابة

Hi,
For computed field if you want to called it in qweb you need to add store=true on your field definition on python file.

if not stored you should use t-esc

t-esc is for running python code on qweb you can call python function doing calculation using t-esc

t-field is for calling field from your model into qweb

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 22
6948
1
يوليو 25
1622
1
مايو 25
1580
1
أبريل 25
2217
1
فبراير 25
1502