This question has been flagged
1 Reply
4265 Views

Can i able to check like this?

<record id="shop_click" inherit_id="website_sale.menu_shop" name="is_shop_clicked">

    <xpath expr="//field[@url='/shop']" position="replace">

        <template id="login" inherit_id="auth_signup.signup" name="Sign up login">

            <t t-esc="Shop_click()">

            <xpath expr="//input[@name='redirect']" position="replace">

                <input type="hidden" name="redirect" t-att-value="redirect + '&amp;redirect=/shop' "/>

           </xpath>

      </template>

     </xpath>

</record>

Avatar
Discard
Best Answer

If what you wanna accomplish is to make sure that the user is logged in before use the shop checkout you could find this helpful

https://www.odoo.com/es_ES/forum/ayuda-1/question/login-feature-in-odoo-104396#answer-104427

*** Update: how to be able to make a function call inside a template ***

To be able to call a function in a template you are saying that you need to enhance the template generated code by calling a function, for that you have basically 2 ways:

1- You need to put that function inside the context of the template to be rendered. For example(taken from the controller of the module website_sale):

def get_attribute_value_ids(self, product):

...

attribute_value_ids = []

...

return attribute_value_ids

@http.route([

'/shop',

'/shop/page/<int:page>',

'/shop/category/<model("product.public.category"):category>',

'/shop/category/<model("product.public.category"):category>/page/<int:page>'

], type='http', auth="public", website=True)

def shop(self, page=0, category=None, search='', **post):

...

compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)

values = {

...

'compute_currency': compute_currency,

...

'get_attribute_value_ids': self.get_attribute_value_ids

}

return request.website.render("website_sale.product", values)

2- Put the function in a model that is available already as a record value in the context of the template to be rendered so you just need to do for example:

<t t-raw="product.function_name"/>

There are others scenarios when you wanna execute some code into js or make a call to the server to execute the code in a server side controller.


Avatar
Discard
Author

Heartily thank you for your replay, can you please tell me that how to call a function inside a template

see my answer update for more

Author

Hi Mendoza can you please tell me that what is product stands in "product.function_name"

something like this:

<pre>

from openerp import models, fields

class solt_product_template(model.Model):

_inherit = 'product.template'

@api.multi

def get_function_name(self):

for el in self:

el.function_name = '<h1>Hello</h1>'

function_name = fields.Html('Description for the website footer', compute='get_function_name')

</pre>

Author

I didnt mean that code me just want to know that if it is something like that a variable or module.