How to make a many2many field sortable in odoo 9? - odoo

I have a many2many field , but I'm unable to sort it . Can anyone help?

I don't think there is any way to sort a many2many field if it is many2many_tags or any display widget other than the default many2many widget.
With that default many2many widget, it should display like a list in the form. You may be able to define the tree view and set a default_order attribute. Something like this:
<field name="your_m2m_field">
<tree default_order="sub_field1, sub_field2 desc">
<field name="sub_field1/>
<field name="sub_field2/>
<field name="sub_field3/>
</tree>
</field>

Related

Odoo 10 Filter for One2Many field not working

I have a question about the possibility to use a One2Many field in the search view for filter purposes.
Lets say I have this field here:
class AccountInvoice(models.Model):
_inherit= 'account.invoice'
custom_field_ids = fields.One2Many(
comodel_name='account.payment.order',
compute='some_method',
readonly=True,
)
Now I want to go ahead and insert a filter into the search view
<record id="view_payment_order_filter" model="ir.ui.view">
<field name="name">view.payment.order.filter</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.view_account_invoice_filter"/>
<field name="arch" type="xml">
<xpath expr="//filter[#name='refunds']" position="after">
<filter string="In Payment Orders" domain="[('payment_order_ids', '!=', False)]" />
</xpath>
</field>
</record>
When I update the module then it doesnt give me any error. But the filter is not working. I did some research on this but there is no real "best practise" solution for this. What would be a good approach to enable the filter for this field. I basicaly want to show all invoices where this One2Many field is not empty.
You can't filter with fields that are not stored. An workaround for this is to make a bool field stored based on your condition. Than add this field to search view as filter.

How to remove add a line in the notebook of a many2many field? odoo 12

Actually i created a many2many field and add that in the field in a notebook.i've tried giving the options="{'no_create': True,'no_create_edit':True}" in the xml file.But the add a line button is still showing.
If you want to remove the add line button/link on one2many or many2many list views you have to add create="0" to the tree node, for example:
<field name="my_x2many_field">
<tree create="0">
<field name="my_field" />
</tree>
</field>

How can I add required columns in odoo Many2many form view?

I am having a Many2many field on a form view, field is supposed to show 5 columns but it shows only 3 in my case. All 5 fields are available there on other model. but still not able to get the solution. Help appreciated. I am using Odoo v-10.
Here it shows 3 columns, and I want 5.
Edit its form view and where you defined the field add its view there
<field name="my_many2many_field">
<tree>
<field name="first_field"/>
<field name="second_field"/>
<field name="third_field"/>
<field name="fourth_field"/>
<field name="fifth_field"/>
</tree>
</field>

Openerp hide some rows of one2many field

I have a one2many field named line_ids in my view:
i want to display some rows and not others but i need them all in a calculation.
the question is how to hide some rows in one2many
because i need all the rows for the calculation and i don't want to bother the user with all of the rows
I need to display just the rows with a field "display" value as True.
<field name="line_ids" >
<tree string="Lignes de Rubriques" editable="bottom">
<field name="category_id"/>
<field name="code" invisible="1"/>
<field name="a_afficher" />
<field name="sequence" />
<field name="display" />
<field name="total" invisible="1" />
<field name="soumise_CNSS" string="CNSS" invisible="1"/>
<field name="soumise_AMO" string="AMO" invisible="1"/>
<field name="soumise_IR" string="IR" invisible="1"/>
</tree>
</field>
How do I achieve this? Thank you :)
If you don't want the one2many tree to be editable, just create a functional field of type one2many to return the rows you want and use that in your tree.
If you do want the one2many editable, as you have above, it gets much harder. Basically you will need another child model that you populate with the rows to edit and then keep this and the main child model synchronised.
A simpler solution is to use attrs to make the fields on the row you don't want to edit readonly. They will still show but at least they can't be changed.

How to change the base fields label in openerp 6.1

researchorial but indeed i have done all the google around what i want o achieve in openerp that how to change those fields label ,i don't wanna play with fields and i know how to create new fields but what about base fields i am not able to edit them they throw some error that you cannot change the base fields from here so objective is clear that those label like Company, SSNID in hr module i want them changed according to them nothing else!!
please do not post links of already same question cause they had not been answered !!
Thank You
You can change the label of a field in two ways.
1. Python code
Inherit the model where that field is defined, then inside _columns add the same field name with new label.
For example, if you want to change SSNID to Employee ID, assume that in the base module the field is defined as 'ssnid' and the field is in hr.employee model.
from osv import osv, fields
class hr_employee(osv.osv):
_inherit = 'hr.employee'
_columns = {'ssnid': fields.integer('Employee ID')
}
hr_employee()
2. XML code(change the view)
Inherit your view and add the attribute for the field 'ssnid'. For example in base module the field view is like <field name="ssnid"/> .To change it inherit its corresponding form and tree view and you can change the field by using position="attribute" and also position="replace". Add the attribute string="Employee ID".
<field name="ssnid" position="replace">
<field name="ssnid" string="Employee ID"/>
</field>
Create New Hr employee Inherited view By this way.
<record model="ir.ui.view" id="updated_hr_form_view">
<field name="name">updated.hr.form</field>
<field name="model">hr.employee</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<xpath expr="//form/notebook/page[#string='Personal Information'/group/field[#name='ssnid']]" position="replace">
<field name="ssnid" string="Your New Label"/>
</xpath>
</field>
</record>