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

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>

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 make a many2many field sortable in odoo 9?

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>

odoo 9 how to add relational field to pivot view?

I'm customizing Project's pivot view to show timesheet description along with task's name.
here is my code below but when I click pivot view it shows an error
<!-- Insert Project Issue Pivot Field -->
<record id="project_task_custom_pivot" model="ir.ui.view">
<field name="name">project.task.custom.pivot</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_project_task_pivot"/>
<field name="arch" type="xml">
<field name="stage_id" position="after">
<field name="name" type="row"/>
<field name="timesheet_ids" type="row"/>
</field>
</field>
</record>
Error below
assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
Edit
I re-defined the field "timesheet_ids" as #George Daramouskas mentioned.
timesheet_ids = fields.One2many('account.analytic.line', 'task_id', string="Timesheetss", store=True)
But It didn't work.
So I took a look at the source code in Odoo Source
The function "One2many" has no such a parameter.
I guess the Store=True is for only regular field not related field.
Is there any other solution for this?
Thanks
Create your field with the attribute store=True in the constructor so that the field is stored in the database.

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.

OpenERP always displays inherited view instead of original

Original views:
<record id='view_1' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="17"/>
<field name="type">form</field>
<field name="arch" type="xml">
...
</field>
</record>
inherited view from the original:
<record id='view_2' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="10"/>
<field name="inherit_id" ref="view_1"/>
<field name="type">form</field>
<field name="arch" type="xml">
...
</field>
</record>
So what happens is OpenERP always displays the inherited view ignoring the priority value. Is this expected behaviour, or there's something else I am missing?
If this is the expected behaviour, then please read further :-)
I have my.second.object with many2one field to my.object, and when I want to create my.object from this field, I want to open a bit different form view of my.object. I am trying to create a different view just for that purpose, but as you see it doesn't work so easily (or does it?).
Any help is appreciated.
Yes it is the expected behavior. The priority of a view only serves to select the main view to use when no specific view was requested. Inherited views are "patch views" that act like children of the view they inherit from, and may never be selected as "main views". They always apply on top of their parent view when that view is displayed.
If you want an alternative view for a certain model you should define a new stand-alone view that does not inherit from any other. If that view is meant to be used only in the context of the view of my.second.object, there are two common tricks to make OpenERP use it:
Define it inline in the form view of my.second.object, as a child of the <field> element. This may not work in all OpenERP clients depending on the version, and works best for declaring inline form views for o2m lines, normally.
Declare it as a stand-alone view with a low priority (e.g. 32) and put a magic context key in the many2one field of the my.second.object view that should use it. The magic key is in the form <view_type>_view_ref, and the value must be the XML ID of the desired view. This should work everywhere.
<!-- Example 1: inline form view -->
<form string="My second object">
<field name="my_object_id">
<form string="My object inline view">
<field name="name"/>
</form>
</field>
</form>
<!-- Example 2: explicitly ask for special view using magic key -->
<form string="My second object">
<field name="my_object_id" context="{'form_view_ref': 'module.my_object_form2'}"/>
</form>
For reference, have a look at this page of the OpenERP documentation that explains most of the options for making and using context-specific views.
NOTE: If you have used form_view_ref and from form view if you have
any button which is opening another form view of some other model then
it will give you error . It will try to open the same form view you
have passed in form_view_ref for another model also.
What "position" you defined in <field name="field_from_original_view">?
<record id='view_2' model='ir.ui.view'>
<field name="name">view.name</field>
<field name="model">my.object</field>
<field name="priority" eval="10"/>
<field name="inherit_id" ref="view_1"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="field_from_original_view" position="after" (or before)>
<field name="inherit1" />
<field name="inherit2" />
<field name="inherit3" />
</field>
</field>
</record>
There may not be a possibility to make an inherited form the standard form of your model so that it will be presented automatically.
BUT If you look at a specific task --> open an inherited form view for a one2many field e.g.; there is. Set the context variable 'form_view_ref' to 'MODULE.VIEW_ID'.
<field name="myOne2ManyField" context="{'form_view_ref': 'myModule.myInheritedView'}/>
Still works with Odoo 9.0.