Odoo duplicate many2many fields - odoo-8

A model [m] with a many2many field [m2m]
Field [m2m] have attribute [copy=False]
A form view [v] display the [m] and the field [m2m] with widget [many2many_tags]
I have tested that the python object did return a with False on field [m2m]
but the javascript, keep render the tags on web.
model.py
class model(models.Model):
_name = "m"
m2m = fields.Many2many('sale.order', string="SO", copy=False)
XML File
<record ...>
<form>
<group>
<field name="name"/>
<field name="ref"/>
<field name="so_m2m" widget="many2many_tags" options="{'no_create_edit': True}"/>
</group>
</form>
</record>
When I duplicate the current record, the field [m2m] is keeps the old tag from old record which is not expected.
After clicking the save button, the old tag will disappear.

Try one thing here :
Whatever your third table is there, both fields used in many2many relation, from third table keep them as a copy false.
i.e.
m2m = fields.Many2many('sale.order','sale_order_another_table_rel', 'sale_order_field','antother_table_field', string="SO", copy=False)
Into new table :
_name = 'sale.order.another.table.rel'
sale_order_field_id = // copy=false
another_table_field_id = //copy = false
Hopefully work.

Related

Add total label to tree footer odoo 12

I need to add a Total label on the last row from a tree, the last row is for sum values, how can I edit a tree footer?
view.xml
<xpath expr="//field[#name='field_list']/tree/field[#name='name']" position="after">
<field name="field1" sum="Total Field 1"/>
<field name="field2" sum="Total Field 2"/>
<field name="field3" sum="Total Field 3"/>
</xpath>
screenshot
Is there a way to edit the tree footer?
The list footer is used to show aggregates (sum, avg), it is rendered in _renderFooter of the ListRenderer.
The method docstring:
/**
* Render the footer. It is a <tfoot> with a single row, containing all
* aggregates, if applicable.
*
* #private
* #returns {jQueryElement} a <tfoot> element
*/
The method that computes aggregates will check for the field type, the computation will be ignored if the field type is not one of the following integer, float or monetary.
You can alter the _renderFooter to be able to provide a static text to display in the footer using a field attribute.
Example:
var ListRenderer = require("web.ListRenderer");
ListRenderer.include({
_renderFooter: function () {
var res = this._super();
_.each(this.columns, function (column) {
if(!('aggregate' in column) && column.attrs.text) {
res.find('.'+column.attrs.name).text(column.attrs.text);
}
});
return res;
},
});
To add the above code, check the Assets Management documentation.
To display the text in the footer of the corresponding column, set the text attribute in the field tag ( if the field contain an aggregate, the text will be ignored).
<field name="total" text="Total"/>

How to invisible a field based on complex condition in odoo10?

I add a field in account.payment.
bank_id = fields.Many2one('res.bank', string="Bank")
when i clicked the register payment button in account.invoice then it is opened a register payment wizard.
I want to invisible the bank_id based on the condition
journal_id.type not in bank
How it is possible in odoo??
in xml I add a condition like this.
attrs="{'invisible': [('journal_id.type', 'not in', ['bank'])]}"
How to correct the condition??
in this situation you can not apply direct attrs so you have to take one compute boolean field to check the journal type and based on that field make bank_id visible or invisible
in account.payment
from odoo import models, fields, api, _
class account_payment(models.Model):
_inherit = "account.payment"
bank_id = fields.Many2one('res.bank', string="Bank")
check_journal = fields.Boolean(string="Journal Type", compute='_check_journal_type')
#api.depends('journal_id')
def _check_journal_type(self):
if self.journal_id.type == 'bank':
self.check_journal = False
else:
self.check_journal = True
in account.payment view
<field name="check_journal" invisible="1"/>
<field name="bank_id" attrs="{'invisible': [('check_journal', '=', True)]}"/>

Odoo 9.0 C How to add a new many2one field from an inherited view?

Could you guy please show me what is the right steps to follow when we want to add a new many2one field to an inherited view like account.invoice.order.
It's like the same :
<template id="new_id" inherit_id="module_name.qweb_template_id" name="Template name as you want">
<!-- specify the target that you want to add the many2one field
than the place after,before or inside -->
<xpath expr="//target_where_you_want_to_add" position="after/before/inside">
<field name="your_one_to_many_field_name" />
</xpath>
</template>
the hard part is targeting the write place
like if you want to add the the field to a div tag inside a div with id ="div_id" and the div contain a class="class_name"
<xpath expr="//div[#id='div_id']/div[#class='class_name']" position="inside">
or a after a field inside that div named field1
<xpath expr="//div[#id='div_id']/div[#class='class_name']/field[#name='field1']" position="after">
or after a field that named field1
<!-- // is like a shortcut -->
<xpath expr="//field[#name='field1']" position="after">
so see who can you target the place that you want to put the field using tag names and properties like id,class,... (string is not supported in odoo 9)

Unable to use related field in domain filter

Field declaration in odoo v8, team_manager is a new class:
class team_manager(osv.osv):
_name = "team.manager"
_columns = {
'is_manager': fields.related('manager_id', 'manager', type='boolean', relation="hr.employee", string='Managers', readonly=True, store=True)
}
The xml file code for 'Form View'
<separator string="Team Work" attrs="{'invisible':[('is_manager','=',False)]}"/>
<field name="child_line" context="{'manager_id':id}" attrs="{'invisible':[('is_manager','=',False)]}">
<tree editable="=top">
<field name="employee_id"/>...
</tree>
</field>
While opening the form I am getting the error like
Odoo Client Error
Error: Unknown field is_manager in domain [["is_manager","=",false]]
http://localhost:8069/web/static/src/js/view_form.js:1702
Can't we use related filed in domain? or Does my syntax need changes?
You need to add is_manager field to the form view.
Add the following line before child_line field:
<field name="is_manager" invisible="True"/>

How to Display linqxml list data to datatable

I have an xml like this
<?xml version="1.0" encoding="utf-8"?>
<content>
<field title="Year">
<description>Numeric data</description>
<comment>1234</comment>
</field>
<field title="mail">
<description>Numeric data</description>
<comment>ABCD</comment>
</field>
<field title="Year">
<description>AlphNumeric Data</description>
<comment>ABCD1234</comment>
</field>
</content>
i tried below linq query to extract data based on the title attribute.
var Data = XDocument.Load(Xmlpath).Root
.Descendants("field")
.Where(element => element.Attribute("title").Value.Contains("Year"))
.Descendants()
.Where(element => element.Name == "description" || element.Name == "comment")
.Select(element => new { element.Name, element.Value }).ToList();
for eg i want to show all datas that comes under title "year", the output should be displayed into a datatable like this
Description Comment
numeric data 1234
Alphanumeric Data ABCD1234
But i dont know how to convert var data to datatable or iterarte though var data .Can somebody help me? is it possible to display the result from linq query by modifying the query itself?
DataTable's have a method (ReadXml) that reads XML. Have you tried using that?

Resources