Why my code doesn't work to changing attributes on button odoo 15 - python-3.x

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>

Related

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>

How do i customise product template views by inheritance in odoo 14?

I'm trying to add a custom field in product_templte_form_vieew by doing this :
<!-- product template -->
<record id="mymoduleproduct_view_form" model="ir.ui.view">
<field name="name">mymodule.product</field>
<field name="model">mymodule.product</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#name='general_information']/group[2]" position="attributes">
<field name="prixass"/>
<field name="taxes_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</xpath>
</field>
</record>
No error in excution but it seems to not work. Need help to detect or correct what is wrong.
I have already define ‘prixass’ fields like this :
class MyModuleProduct(models.Model):
_name = "mymodule.product"
_description = "table des articles"
_inherit = "product.template"
prixass = fields.Float(string='Prix Assurance')
taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)
Also i’ld like to remove the fields taxes_id from the view, how do i do ?
.
the resume of the question in image here
Thanks .
Try this.
class MyModuleProduct(models.Model):
_inherit = "product.template"
prixass = fields.Float(string='Prix Assurance')
taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)
<record id="product_inherit_view" model="ir.ui.view">
<field name="name">product.template</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#name='general_information']/field[#name='default_code']" position="after">
<field name="prixass"/>
</xpath>
<field name="taxes_id" position="replace">
<field name="taxes_id" invisible="1"/>
</field>
</field>
</record>
but this work for me now
//model
class MyModuleProduct(models.Model):
_inherit = "product.template"
prixass = fields.Float(string='Prix Assurance')
taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)
//views
<record id="product_inherit_view" model="ir.ui.view">
<field name="name">product.template</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#name='general_information']/group[1]" position="after">
<group>
<field name="prixass"/>
</group>
</xpath>
<field name="taxes_id" position="replace">
<field name="taxes_id" invisible="1"/>
</field>
</record>
thanks.

Inherit mail.activity on res.partner form

I cannot find the view which contain Activities on res.partner form view
I tried to inherit mail.mail_activity_type_view_form but it is not
<record id="mail_activity_view_inherit" model="ir.ui.view">
<field name="name">mail.activity.type.view.form.inherit</field>
<field name="model">mail.activity.type</field>
<field name="inherit_id" ref="mail.mail_activity_type_view_form" />
</record>
The XML-ID is:
mail.res_partner_view_form_inherit_mail
So, mail addon, res_partner_view_form_inherit_mail view.
The view is this one:
<record id="res_partner_view_form_inherit_mail" model="ir.ui.view">
<field name="name">res.partner.view.form.inherit.mail</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='email']" position="replace">
<field name="is_blacklisted" invisible="1"/>
<label for="email" class="oe_inline"/>
<div class="o_row o_row_readonly">
<i class="fa fa-ban" style="color: red;" role="img" title="This email is blacklisted for mass mailing" aria-label="Blacklisted" attrs="{'invisible': [('is_blacklisted', '=', False)]}" groups="base.group_user"></i>
<field name="email" widget="email" context="{'gravatar_image': True}" attrs="{'required': [('user_ids','!=', [])]}" />
</div>
</xpath>
<xpath expr="//sheet" position="after">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</xpath>
</field>
</record>
Let me try to help, you're trying to _inherit mail.activity view which is not possible by using xml, because it will not inherit from xml it is written in qweb, so for that you have to extend it like.
<t t-extend="idOfMailAvtivityQweb">
<t t-jquery='i[title="Mark as Todo"]' t-operation="before">
//Here in thread i will add something before title "Mark as Todo"
</t>
</t>

Odoo - hide a website menu base on website fields

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.

Resources