Can I set default view mode of a field inside Notebook/Page - odoo-11

I have overriden account.invoice_supplier_form and I have added kanban view
<record id="invoice_supplier_form_inherit" model="ir.ui.view">
<field name="name">account.invoice.supplier.form.inherit</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field[#name='invoice_line_ids']" position="attributes">
<attribute name="mode">tree,kanban</attribute>
</xpath>
<xpath expr="//notebook/page/field[#name='invoice_line_ids']" position="inside">
<kanban class="o_kanban_mobile">
...
So now page inside notebook supports two views - tree and kanban for invoice_line_ids. I want to set kanban as default view. How do I do that?
...

Did you try this:
<xpath expr="//notebook/page/field[#name='invoice_line_ids']" position="attributes">
<!-- reverse the order here -->
<attribute name="mode">kanban,tree</attribute>
</xpath>
<!-- and here make sure the kanban is the first tag inside the field tag -->
<xpath expr="//notebook/page/field[#name='invoice_line_ids']/tree" position="before">
<kanban class="o_kanban_mobile">
....
....

Related

Problem with adding a custom field to existing view

[![enter image description here][1]][1]I have a problem with adding a new field to the sale order view of odoo12. I have created a new module. I hope that you can help me.
Below the code of my view form
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml"></field>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</record>
</odoo>```
when i try to install the new module i have the following error:
File "src\lxml\etree.pyx", line 3557, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: record, line 3
[1]: https://i.stack.imgur.com/e1DOw.png
The problem is in the <field name="arch" type="xml"></field> line: the <field> tag is closed, and your additional_note field is declared outside of it.
Try this code instead:
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<!-- Leave the 'arch' field open -->
<field name="arch" type="xml">
<!-- Put your custom field and its position inside the 'arch' field.
Use 'xpath' tag to create a more precise positioning -->
<xpath expr="//group/group/field[#name='payment_term_id']" position="after">
<field name="additional_note"/>
</xpath>
<!-- Now, close the 'arch' field -->
</field>
</record>
</odoo>
The view is not correctly defined, you can refer to account_analytic_view.
The view definition should be (according to the provided link):
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</data>
</field>
</record>
</odoo>

How to correctly inherit an inherited view in odoo?

I have been trying to target an inherited element in the view, but it's not working for me.
So I have a view that inherits from the form view of hr.contract as shown here:
<record id="hr_contract_view_form_cayor" model="ir.ui.view">
<field name="name">name</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<!-- more elements define with xpath -->
<xpath expr="//field[#name='job_id']" position="after">
<field name="retirement_age"/>
</xpath>
...
<xpath expr="//page[#name='information']" position="after">
<page string="Allowances" groups="hr_payroll.group_hr_payroll_user">
<group>
<group name="allowances_group1">
...
<field name="car_allowance"/>
...
</group>
<group name="allowances_group2">
...
</group>
</group>
</page>
</xpath>
</data>
</field>
</record>
I have defined a new file to inherit from this form view, which adds a new field to it, as follows:
<record id="hr_contract.hr_contract_view_form_inherited" model="ir.ui.view">
<field name="name">hr.contract.grade.rank.form.inherit</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="module.hr_contract_view_form_cayor"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[#name='allowances_group1']" position="inside">
<field name="medical_allowance" />
</xpath>
</data>
</field>
</record>
But when I upgrade my module, I get the following error:
Field `retirement_age` does not exist
How can I correctly inherit from the first one, and add my new field?
Any help will be greatly appreciated, thanks in advance.
Please try this code :
Python :
class HrContract(models.Model):
_inherit = 'hr.contract'
retirement_age = fields.Char(string="Retirement Age:")
XML :
<record id="hr_contract_view_form_cayor" model="ir.ui.view">
<field name="name">name</field>
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<!-- more elements define with xpath -->
<xpath expr="//field[#name='job_id']" position="after">
<field name="retirement_age"/>
</xpath>
</data>
</field>
</record>

Make a delete button invisible using attrs. I am using Odoo 10

I need to make a delete button invisible using attrs.
my code here.
in this code i want to put invisible delete button.
<record id="calender_event_form_id1" model="ir.ui.view">
<field name="name">calender_event</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form_popup"/>
<field name="arch" type="xml" delete="false">
<xpath expr="//field[#name='partner_ids']" position="after">
<field name="c_is_meeting_done" string="Is Meeting Done?" readonly="1"/>
<field name="description"/>
</xpath>
<xpath expr="//field[#name='alarm_ids']" position="after">
<div name="buttons">
<button name="%(ouc_meeting_wizard_action)d" string="Close Meeting" attrs="{'invisible':[('c_is_meeting_done', '=', True)]}" type="action" class="oe_highlight" />
</div>
</xpath>
</field>
</record>
You can give "delete=1" to your particular view from xml. Like this:
<form string="Custom" delete="1"/>

Error while showing button for specific user (Admin) odoo 8

I've inherited a form view and made some modifications using xpath. I need a button in the header of form view to show only to admin user. But when I'm putting the groups, its giving following error :
Error details:
error_details
My code is:
<record id="wms_stock_view_move_form" model="ir.ui.view">
<field name="name">wms.stock.view.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<field name="location_dest_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<xpath expr='//form[#string="Stock Moves"]' position='attributes'>
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
<attribute name="delete">false</attribute>
</xpath>
<xpath expr='//button[#name="action_cancel"]' position='attributes'>
<attribute name="invisible">True</attribute>
</xpath>
<button name="action_done" states="draft,assigned,confirmed" string="Process Entirely" type="object" class="oe_highlight" position="replace" groups="base.group_no_one"/>
</field>
</record>
I have to guess which button you want to set new groups to, because your error relates to action_done but your own answer to action_cancel. So let me do this abstractly. You already have the answer in your question. Use XPath to "find" the button and use position="attributes":
<xpath expr="//button[#name='button_name']" position="attributes">
<attribute name="groups">module_name.group_id</attribute>
</xpath>
I eventually solved my own question, the solution is:
<xpath expr='//button[#name="action_done"]' position='replace'>
<button name="action_done" states="draft,assigned,confirmed" string="Process Entirely" type="object" class="oe_highlight" position="replace" groups="base.group_no_one"/>
</xpath>

Odoo use both inherited Tree View and Parent Tree View

I created a special tree view for res.partner that help me modify records on the fly.
I put this view in a special Menu: test Configuration / Modification Rapide / Modification Contacts.
Everything is working fine expect that whenever there's a res.partner tree it's my tree view that is used.
Is there a way to use my custom tree view only from my Custom menu.
and every place else is the default tree view that is used ?
<record model="ir.ui.view" id="view_test_contact_tree">
<field name="name">res.partner.tree.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<field name="email" position="replace" />
<field name="phone" position="replace" />
<xpath expr="//tree[#string='Contacts']" position="attributes">
<attribute name="editable">bottom</attribute>
</xpath>
<xpath expr="/tree/field[#name='display_name']" position="before">
<field name="isBuyer" string="A"/>
<field name="isSeller" string="V"/>
<field name="isSupplier" string="F"/>
<field name="isMiddle" string="I"/>
<field name="isBackOffice" string="B"/>
</xpath>
<xpath expr="/tree/field[#name='display_name']" position="after">
<field name="mobile"/>
<field name="phone"/>
<field name="email"/>
</xpath>
</field>
</record>
<record model="ir.actions.act_window" id="action_res_partner_rel10">
<field name="name">Menu</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree</field>
</record>
<menuitem name="test Configuration" id="test_config_id" sequence="450"/>
<menuitem name="Modification Rapide" id="modif_id" parent="test_contact.test_config_id" sequence="20" />
<menuitem name="Modification Contacts" id="sub_gestion_modif_id" parent="modif_id" sequence="11" action="action_res_partner_rel10"/>
As I understand you want to show your own created tree view in this menu.
So for this you have to pass your create tree view in ref of action to open your tree view
Like:
<record id="action_quotations" model="ir.actions.act_window">
<field name="name">Quotations</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_quotation_tree"/> <======= your tree view id
<field name="view_mode">tree,form,calendar,graph</field>
<field name="context">{'search_default_my_sale_orders_filter': 1}</field>
<field name="domain">[('state','in',('draft','sent','cancel'))]</field>
</record>
you have not have to inherit exits view and change in this, instead of create new tree view and pass in actions
Hope this help

Resources