Skip to Content
Menu
This question has been flagged
3 Replies
3679 Views
I define an ir.ui.view as follows:

    <record id="product_view_extension" model="ir.ui.view">
      <field name="name">Product View Extension</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_form_view"/>
      <field name="arch" type="xml">
        ...

Inside the body of `arch`, I wish to iterate through a data structure generated on the server side. Here is a pseudo code of what I want on the server side:

p = the product.template being shown in ir.ui.view
result = []
for price_list in p.price_lists
result.append(price_list.do_some_calculation())
make result available for view

However, for the case of `ir.ui.view`, there is no controller involved, so I don't know how to make `result` available for the view. 

Ultimately I want to be able to do something like this in the view: 

<t t-foreach="result" t-as="dict">     
    <div>            
        <span t-field="dict.field" />      
    </div>
</t>

Whereas `result` is the array generated above, and `hash` is a plain old Python dictionary.

This type of stuff is very simple to do in frameworks like Rails and Laravel, however, I can't figure out how to do it in Odoo.

Avatar
Discard

Hmm, this feels unlogical. Why don't you simply create a field in the model which is computed on the moment the view opens?

Best Answer

Hello. Basically it is not possible to make it.

But you can defined a Many2many fields in your "product.template" model which will contain all your calculated prices. Then you can define a custom widget to display it in your view.

Avatar
Discard
Author Best Answer

For my specific use case, I have pricelists setup for product. I want to display a table of all prices calculated for a product based on pricelists. This is a completely user-facing calculation/display that shouldn't be stored in the model as a field. That is why I want to expose these variables so I can do the calculation server side and generate the table.

Avatar
Discard
Related Posts Replies Views Activity
4
Jan 24
20585
2
Jan 24
777
0
Aug 23
956
5
Sep 21
15453
3
Jan 21
12627