Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4509 Lượt xem

Hi,

   I am trying to add a custom attribute to the product card. The problems seems to be the template relation.


   <t t-extend="Product">

      <t t-jquery=".product-name" t-operation="replace">

        <div class="product-name">

          <t t-esc="product.display_name"/> -

          <t t-if="product.product_tmpl_id">

            -- <t t-esc="product.product_tmpl_id.x_season"/>

          </t>

        </div>

      </t>

    </t>

    I also tried using


    <t t-extend="Product">

      <t t-jquery=".product-name" t-operation="replace">

        <div class="product-name">

          <t t-esc="product.display_name"/> -

          <t t-if="product.product_tmpl_id">

            -- <t t-esc="product.season"/>

          </t>

        </div>

      </t>

    </t>

    and extending this way.


        _inherit = 'product.product'


   season = fields.Char(compute='_season')


   @api.depends('product_tmpl_id')

   def _season(self):

     for record in self:

       record.season = record.product_tmpl_id.x_season

   any help would be greatly appreciated

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

Ho Mohammed,


    The "template" sintaxis is working because the "--" appears.

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

hi,

try to print product.name in template and check if it is showing.

Also check whether the product to be printed have value 'season' stored in database. Compute fields are triggered only when the view is loaded

Tác giả

I tried both product.name -> It appears

product. product_tmpl_id.name -> it doesn't but

product. product_tmpl_id -> Shows the ID

It seems that I dont have access to template attributes.

Many thanks

If product.product_tmpl_id returns id, it must be an integer field (not record) so you cannot access product. product_tmpl_id.name.

Try product.season. Make sure you have value stored for season in db

Tác giả

The thing is that the season is a temaplate field, not a variant one. So I don't know how to access template from product.product

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

Hi 

Try this

<t t-jquery="div.product-name" t-operation="replace">


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
2590
0
thg 4 22
2805
5
thg 9 20
32487
3
thg 8 20
27406
2
thg 2 17
3037