Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4544 มุมมอง
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.

อวตาร
ละทิ้ง

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

คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ม.ค. 24
23249
Attrs attribute แก้ไขแล้ว
2
ม.ค. 24
2552
0
ส.ค. 23
2352
Not displaying the form and tree view แก้ไขแล้ว
5
ก.ย. 21
17630
3
ม.ค. 21
16953