Odoo - hide a website menu base on website fields - web

I have a website menu defined by this code:
<record id="website_menu_apps" model="website.menu">
<field name="name">Apps</field>
<field name="url">/apps</field>
<field name="parent_id" ref="website.main_menu" />
<field name="sequence" type="int">19</field>
</record>
and a field defined by this code:
class Website(models.Model):
_inherit = 'website'
dedicate_apps_store = fields.Boolean(string='Dedicated Apps Store', default=True)
How can I make website menu disappear when user set website.dedicate_apps_store to False?

<template id="custom_layout" inherit_id="website.layout" name="custom layout">
<xpath expr="//ul[#id='top_menu']/t/t" position="attributes">
<attribute name="t-if">submenu.name != 'Apps' or website.dedicate_apps_store</attribute>
</xpath>
</template>
You inherit webiste.layout and set position="attributes" then you can write your condition inside the attribute tag.

Related

Why my code doesn't work to changing attributes on button odoo 15

i'm using odoo 15, and i want to change attributes button on stock.quant tree view editable. for code like this:
<xpath expr="//button[#name='action_apply_inventory']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('inventory_quantity_set', '=', False), ('is_approved', '=', False)]}</attribute>
<attribute name="groups">base.group_system,pitik_base_farm.group_finance_head</attribute>
<attribute name="string">Submit</attribute>
</xpath>
But this code doesn't work, not effect on view.
enter image description here
enter image description here
You are using is_approved field in domain of the invisible attrs but this field does not exist in the view. You need to add it to the view to be able to use it in the domain.
<record id="view_stock_quant_tree_inventory_editable_inherit_custom" model="ir.ui.view">
<field name="name">stock.quant.inventory.tree.editable.inherit.custom</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_inventory_editable"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='inventory_quantity_set']" position="after">
<field name="is_approved" invisible="1"/>
</xpath>
<xpath expr="//button[#name='action_apply_inventory']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('inventory_quantity_set', '=', False), ('is_approved', '=',
False)]}
</attribute>
<attribute name="groups">base.group_system,pitik_base_farm.group_finance_head</attribute>
<attribute name="string">Submit</attribute>
</xpath>
</field>
</record>

How to change string of Purchase Status(purchase_state) that is in Purchase Request? (ODOO)

So I want to change the string of "Purchase Order" inside Purchase Status(Inside Purchase Request) to something like "PO Created" when the purchase_state is in [purchase] but I don't know how I can do it. I want to create fresh module as well.
Here' s what I tried so far. I've created an XML and inherit the view.
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="purchase_request_form_inherit" model="ir.ui.view">
<field name="name">purchase.request.inherit</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field name="purchase_state" position="attributes">
<attribute name="attrs" string="PO Created" attrs="{'readonly': [('po_line.state','=', 'purchase')]}"/>
</field>
</field>
</record>
</odoo>
I prefer use xpath:
<record id="purchase_request_form_inherit" model="ir.ui.view">
<field name="name">purchase.request.inherit</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field expr="field[#name='purchase_state']" position="attributes">
<!-- To change the String -->
<attribute name="string">PO Created</attribute>
<!-- To change the attrs -->
<attribute name="attrs">{'readonly': [('po_line.state','=', 'purchase')]}</attribute>
</field>
</field>
</record>
I hope this answer could be helpful for you.

Odoo Inherit view can't set invisible attribute

I am odor newer.
I want to use the sale.order field and value to create a custom report by select some specific
field from sale.order.
I have created a custom model to inherit sale.order model.
And create a view to inherit view of sale.order.
Here is my code:
class SaleOrder(models.Model):
_inherit = 'sale.order'
<field name="name">Custom Sale Report</field>
<field name="res_model">sale.order</field>
<field name="view_mode">tree,form</field>
<field name="name">sale.order.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath> </field> </record>
But I don't know why the invisible attribute is not working.
Please Help. Thanks.
Try this.
<field name="name">sale.order.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="replace">
<field name="name" optional="hide"/>
</xpath>
</field>
</record>

Where is src_model in ir.actions.act_window?

I have this code in odoo 12 that I want to migrate to odoo 13. But I don't know what is the equivalent of src_model in Odoo 13.
<record model="ir.actions.act_window" id="complete_pieces_jointes">
<field name="name">Complete Pieces Jointes</field>
<field name="view_id" ref="view_id_3"/>
<field name="res_model">ir.attachment.moveto.subscription</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="src_model">ir.attachment</field>
<field name="type">ir.actions.act_window</field>
</record>
Can you help me?
You can look at this example from the SMS module. The src_model has been changed to binding_model.
<!-- Add action entry in the Action Menu for Partners -->
<act_window id="res_partner_act_window_sms_composer_multi"
name="Send SMS Text Message"
binding_model="res.partner"
res_model="sms.composer"
binding_views="list"
view_mode="form"
target="new"
context="{
'default_composition_mode': 'mass',
'default_mass_keep_log': True,
'default_res_ids': active_ids
}"
/>
<act_window id="res_partner_act_window_sms_composer_single"
name="Send SMS Text Message"
binding_model="res.partner"
res_model="sms.composer"
binding_views="form"
view_mode="form"
target="new"
context="{
'default_composition_mode': 'comment',
'default_res_id': active_id,
}"
/>

Manage webservice from odoo

I am new to Odoo 11, I have created a module called 'coupon', for this module I have created a security group and a default user that is added to this group:
<record id="default_coupon_user" model="res.users">
<field name="login">couponuser</field>
<field name="password">couponuser</field>
<field name="password_crypt">couponuser</field>
<field name="name">Default User Coupon</field>
<field name="display_name">Default Coupon User</field>
<field name="customer">False</field>
</record>
<record id="coupon_managers_group" model="res.groups" >
<field name="name">Coupon Managers Group</field>
<field name="comment">Coupon Managers Group that will be used in the Coupon microservice.</field>
<field name="category_id" ref="base.module_category_coupon"/>
<field name="users" eval="[(4, ref('coupon.default_coupon_user'))]"/>
</record>
My module depends on website because I need to create a website, for that site I created an index page:
<!-- === Coupon Page === -->
<template id="index_template">
<t t-call="website.layout">
<div id="wrap">
<div class="container">
<h1>Coupons</h1>
<a href="/payum_coupon/create" class="btn btn-primary btn-lg">
Add
</a>
<p>paginas:
<t t-esc="coupons['pg']"/>
</p>
<p>total:
<t t-esc="coupons['total']"/>
</p>
<ul class="clientes">
<t t-foreach="coupons['items']" t-as="i">
<li>
<a t-attf-href="/payum_coupon/{{i['email']}}">
<t t-esc="i['firstName']"/>
<t t-esc="i['lastName']"/>
-
<t t-esc="i['email']"/>
</a>
</li>
</t>
</ul>
</div>
</div>
</t>
</template>
<record id="coupon_page" model="website.page">
<field name="name">Index Coupon page</field>
<field name="website_published">True</field>
<field name="url">/coupon</field>
<field name="view_id" ref="index_template"/>
<field name="groups">coupon.coupon_managers_group</field>
</record>
and website.menu with the following code:
<record id="coupon_page_link" model="website.menu">
<field name="name">Coupon</field>
<field name="page_id" ref="coupon_page"/>
<field name="parent_id" ref="website.main_menu"/>
</record>
the python code in the controller that will be executed by said menu is this:
#http.route('/coupon', auth='user', website=True)
def index(self, **kw):
#<<my code here>>
I need several things:
when the 'index' page is displayed if the user in session is not in the 'coupon.coupon_managers_group' group then the menu is not shown
And that when the controller method '/coupon' is executed it is verified that the user in session is in the group 'coupon.coupon_managers_group'
This site has a particularity and that my module does not have models, since it is to manage the data of an api rest application, that is, in odoo I have to create the views of list, create, etc., but the data is written and they are read from a remote web service.
I have searched many sites on the internet but I have not found anything, as they always refer to local cases in odoo.
To hide the website menu based on the user group you could do something like this:
from odoo import api, models
class Menu(models.Model):
_inherit = "website.menu"
#api.one
def _compute_visible(self):
if self.clean_url() == '/coupon' and not self.env.user.has_group('coupon.coupon_managers_group'):
return False
return super(Menu, self)._compute_visible()
In the controller of the route /coupon you could check the user group like:
request.env.user.has_group('coupon.coupon_managers_group')

Resources