Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How do I call a function within a template which having an inherit id?

By
Krishna
on 7/5/16, 2:15 AM 169 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)

0
ayman mohammed adam
On 7/10/16, 8:14 AM

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.

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' "

Krishna
on 7/11/16, 12:51 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/5/16, 2:15 AM
Seen: 169 times
Last updated: 7/10/16, 8:14 AM