Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4542 Lượt xem
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.

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 1 24
23249
Attrs attribute Đã xử lý
2
thg 1 24
2552
0
thg 8 23
2352
5
thg 9 21
17630
3
thg 1 21
16953