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

Hello there. I am at a loss here on Odoo 14. I've added some fields to the model res.partner like this one: 

some_terms = fields.Text(string='Some extra Terms')

and then inherited it on sale.order like this: 

some_terms = fields.Text(related='partner_id.some_terms', string='Some extra Terms', store=True)

and now I would like to display these terms on a sales order if this text field is not empty. I managed to show the text from that field on the sales.order.form, and put it in a t-if-condition like this:

<t t-if="some_terms">

​<div class="alert alert-info">

​ ​<strong>Some Terms:</strong><br/>

​ ​<field name="some_terms"/>

​</div>

</t>


But Odoo always displays the div and the text no matter what! I've tried things like: 

t-if="some_terms and some_terms.strip() != ''"
t-if="some_terms not none"
t-if="true != true"

Even with the last condition that should stop anything from being displayed it shows the div. 

I appreciate any help or hint.

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

Well, since t-if-conditions are seemingly ignored altogether, can it be that t-if statements only work in certain areas or inheritance... levels or something?

I mean, I tried to put a t-if="1 == 2" in different parts of my xml file AND the original one and the containing string has always been displayed. Is there a general thing I am missing?

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

Try this  

  t-if="doc.some_terms != ''"

or this 

t-if="doc.some_terms"

الصورة الرمزية
إهمال
الكاتب

Unfortunately this does not work, either.

Can you share the full code?

أفضل إجابة

Hi,

Try the below code 

 

Hope it helps!

الصورة الرمزية
إهمال
الكاتب

Unfortunately it does not. But thank you. The weird thin ist, that t-if="some_terms" AND t-if="not some_terms" AND t-if="some_terms == ''" are all handled as true and all show their content no matter what.

أفضل إجابة

if you want show this in qweb report, your code is right but in form view in odoo you should use attrs like: attrs="{'invisible': [('some_terms','=',False)]}"

الصورة الرمزية
إهمال
الكاتب

But doesn't that only works with already displayed fields? Or do you mean, I have to have the fields hidden in the form and then... make the actually fields to be shown dependent on the content of their hidden copies? You know what I mean? When I use the attrs="{'invisible': [('some_terms','=',False)]}" on the surounding element, Odoo says that this field does not exist...

Can you share the full code? If I know the answer, I'll help.

Because i don't know this qweb is inherited or this is your customize

أفضل إجابة

Without knowing what report you are inheriting exactly it is tough to troubleshoot but try something like:

t-if="doc.some_terms"

The main Sales Order report is setup so that it can be looped through with several other Sales Orders. i.e. Select multiple Sales Orders and print in one click, hence the need to specify doc.xxxx

Beyond that make sure you are inheriting the template correctly.

See: https://github.com/odoo/odoo/blob/14.0/addons/sale/report/sale_report_templates.xml

الصورة الرمزية
إهمال
الكاتب

Thank you, but I inherit <field name="inherit_id" ref="sale.view_order_form"/>.

المنشورات ذات الصلة الردود أدوات العرض النشاط
8
ديسمبر 23
124899
1
يوليو 25
1730
1
مايو 25
1736
1
أبريل 25
2298
1
فبراير 25
1575