Skip to Content
Menu
This question has been flagged
1 Reply
3979 Views

Can you please help me to solve my problem. The following is my xml code and  "user_type" it is my class function.

<template id="user_type" inherit_id="website_sale.products_item" name="Products item standard">

    <xpath expr="//span[@itemprop='price']" position="replace"> 

        <span itemprop="price" style="display:none;" t-esc="cost_cp"/>

        <span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>  

    </xpath>

</template>


def user_type(self):

    if self.env.user.premium_user == True:

        cPrice = self.env['product.product'].browse()

        cost_cp = cPrice.standard_price 

        return cost_cp 

    else :

        return self.env['sale.order'].browse(product.price)

Avatar
Discard
Best Answer

hello,

try this 

 <template id="user_type" inherit_id="website_sale.products_item" name="Products item standard">

    <xpath expr="//span[@itemprop='price']" position="replace"> 

        <span itemprop="price" style="display:none;" t-esc="cost_cp"/>

        <span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>  

         <span t-field="user_type()"/>

    </xpath>

</template> 


and then use dot notation to return any think from.

Avatar
Discard
Author

I tried out your suggestion but I get an error which is "need more than 1 value to unpack" and I tried like the following method too

<template id="user_type" inherit_id="website_sale.products_item" name="Products item standard">

<xpath expr="//span[@itemprop='price']" position="replace">

<t t-foreach= "cPrice" t-as="cost_cPriceS">

<!-- <t t-raw="a.user_type"> -->

<span itemprop="price" style="display:none;" t-esc="cost_cPriceS.standard_price"/>

<span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>

<span t-field="user_type()"/>

</t>

</xpath>

</template>

I get this error "foreach enumerator 'cPrice' is not defined while rendering template 'website_sale.products_item' "