How to restrict/disable the form view, while click tree view of one2many field in Odoo - treeview

How to restrict/disable the form view, while click the tree view of one2many field in Odoo.

Use style:
<field name="your_o2m" style="pointer-events:none;" />

Try this on your field XML definition :
<field name="your_o2m" mode="tree" />

I think that no_open attribute set on the <tree> might work
<field name="o2m_field" widget="one2many" mode="tree">
<tree no_open="1">
<field name="name"/>
</tree>
</field>

Related

How to add "Group By" to Tree View in Odoo V11?

I am new in odoo.
I have a tree view , i want to show it by default with grouped by according to my stage_id.
Any one help me.
Thanks
<field name="name">dmr.search.view</field>
<field name="model">model.name</field>
<field name="arch" type="xml">
<search string="DMR">
<filter name="group_customer_id" string="Customer" icon="terp-partner" context="{'group_by':'field_name'}"/>
</search>
</field>
After adding search record, you need to add search_view_id in action.
For Ex :-
In action
<field name="search_view_id" ref="dmr_search_view"/>
I hope it works for you

add many2one field in inherited view

I want to display my Many2one field.
I inherited from the hr_timesheet_sheet.sheet model like this:
class list_activity_sheet(models.Model):
_inherit = 'hr_timesheet_sheet.sheet'
activity_id = fields.Many2one('list_activity_sheet.activity')
class List_activity(models.Model):
_name='list_activity_sheet.activity'
name= fields.Char('Description',required=True)
And for the View:
<openerp>
<data>
<record id="List_activity_form" model="ir.ui.view">
<field name="name">hr_timesheet_sheet.sheet.form.inherit</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page[#string='Details']/field/tree/field[#name='name']" position="after">
<field name="activity_id"></field>
</xpath>
</field>
</record>
</data>
When i install my addon , i got that message:
field activity_id doesn't exist in the view.
Does anyone know how to solve that?
You're working on the wrong model. If i understand your view definition correctly, you want to choose an activity on the sheet lines.
You have to inherit hr.analytic.timesheet for that instead of hr_timesheet_sheet.sheet. In Odoo 9+ you have to inherit account.analytic.line, because hr.analytic.timesheet was kicked out.

How to group or nest a tree view by a field in Odoo?

I want to create a nested tree view grouping by fields like the following image.
I did not find any source code within Odoo. How to do it?
When you create a search view with a group_by you can see the lines like that
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">account.invoice.select</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<search string="Search Invoice">
<filter string="Period" context="{'group_by':'period_id'}"/>
</search>
</field>
</record>
You must select it in the search view

inheritance view and adding fields

i have candidat model inherit the hr.emplyee model
i want to display the form view of hr.employee and add fields of my child model candidat
class hr_candidat(models.Model):
_name='hr_recrutement.candidat'
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
.
.
.
<record id="hr_recrutement_candidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr_recrutement.candidat</field>
<field name="arch" type="xml">
<form string="Candidat">
<sheet>
<group>
<field name="situation" />
.
.
</group>
</sheet>
</form>
</field>
</record>
I dont know how to display fields of hr.employee + my fields of candidat in view
Just we should set the below code from the view xml file and also
add the depended module as hr in your openerp.py and set the view xml file path as well.
Add below code in your .py file
class hr_employee(models.Model):
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
Add below code in your .xml file
<record id="hr_recrutement_caindidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<xpath expr="field[#name='work_location']" position="after">
<field name="situation" />
</xpath>
</field>
</record>
Hear We have to set the position of your element based on xpath using before,after,inside,replace Attributes of xpath tag.
I hope my answer may helpful for you :)

How to show currency symbol instead of currency name?

I created a module to show related Purchase Orders from projects:
After clicking the Compras (Purchases) button a custom tree view is shown with the currency_id field:
Is there a way to show the symbol of the currency instead of the name? Something like you would do for example using Django: currency_id.symbol. Even better, I want to drop the currency_id field and prepend the currency symbol in the total amount, is that possible? Something like S/. 336.30 in the amount_total field.
Here's my tree view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
....
....
<record id="purchase_order_project_tree" model="ir.ui.view">
<field name="name">purchase.order.tree</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<tree string="Compras"
colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')">
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="currency_id" />
<field name="amount_total" />
<field name="state"/>
</tree>
</field>
</record>
....
....
</data>
</openerp>
You can add a field called currency_symbol in your module (py) that gets the currency symbol when the currency changues with an on_changue to the currency. So you bring that field to the view, you cant directly do it from the XML.
When you click on the that button to get the tree get listed, you can override the "name_get" method of "Currency" and fetch the "currency symbol" instead of name. For this you can pass a flag in the context to limit this modification specific to your module only.
Hope this helps!!.

Resources