How to hide/show fields on selecting option in openerp - openerp-7

I have a selection field and text field
'work': fields.selection([('tax', 'Tax Audit'), ('statutary',
'Statutary'), ('certificate', 'Certificate'), ('projection',
'Projections'), ('acount', 'Accounting'), ('others', 'Others'),
('roc', 'ROC Reg'), ('vat', 'VAT')], 'Nature Of Work'),
'details':fields.text('Details'),
<field name="work" select="0"/>
<field name="details" select="0"/>
Details field must be visible only on selection of 'roc' and 'vat'
how can I get this please help me

Try following:
<field name="details" attrs="{'invisible':[('work','not in',['roc','vat'])]}"/>

Related

How to keep the order of the records added in a many2many field the way I wrote them?

I want to keep the order of the records in the many2many field, the way I added them using the write method, but Odoo use the alphanumerical order by default and overwrote the order I put them in. How can I keep it in the same order when I wrote them, is that possible ?
Here is the model code:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class projet_richat(models.Model):
_inherit = 'project.task'
competence_ids = fields.Many2many('competence.competence',string='Compétences')
consultants=fields.Many2many('hr.employee', string="Consultants")
def search_comp(self):
if len(self.competence_ids) != 0:
consults=self.env['hr.employee'].sudo().search([])
list=[]
for cmp in self.competence_ids:
print(cmp.competence)
for cons in consults:
print(cons.name)
for c in cons.competences:
if c.competence.competence==cmp.competence:
list.append((cons.id,c.competence.competence,c.niveau))
sorted_by_level = sorted(list, key=lambda tup: tup[2], reverse=True)
print(sorted_by_level)
for sorted_cons in sorted_by_level:
self.write({'consultants': [[4, sorted_cons[0]]]})
and here is the view code:
<odoo>
<data>
<record model="ir.ui.view" id="project_inherit_form">
<field name="name">project.inherit.form</field>
<field name="model">project.task</field>
<field name="type">form</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<field name="user_ids" position="before">
<field name="competence_ids" widget="many2many_tags"/>
</field>
<field name="parent_id" position="after">
<field name="consultants">
<tree>
<field name="name"/>
</tree>
</field>
</field>
<button name="action_assign_to_me" position="after">
<button name="search_comp" string="Test" class="btn-primary"
type="object"
/>
</button>
</field>
</record>
</data>
</odoo>
Thanks in advance.
The many2many field will use the list view to show its content, the default order is defined by the _order attribute on the related model.
You can alter the default ordering by setting the default_order parameter on the tree tag
From the List view documentation:
default_orderoverrides the ordering of the view, replacing the model’s order (_order model attribute). The value is a comma-separated list of fields, postfixed by desc to sort in reverse order:
<tree default_order="sequence,name desc">
To keep the order you want, you can add an integer field sequence and use it to order records (_order='sequence') then in search_comp function set the sequence field value for each line

Add attachment on mas mailing

So this is my mass mailing code for sale orders. But I just missing here one thing. it's that it should add a sale order report that I created to each of SO I'm generating e-mail for. any suggestions how can I make this work?
<data>
<act_window name="Mass Sale Order Email"
res_model="mail.compose.message"
src_model="sale.order"
view_mode="form"
multi="True"
target="new"
key2="client_action_multi"
id="action_send_mass_sale_order"
context="{
'default_composition_mode': 'mass_mail',
'default_email_to': '{($object.email or \'\')|safe}',
'mass_mark_sale_order_as_sent': True,
'default_model': 'sale.order',
}"
/>
</data>
class MailComposeMessage(models.TransientModel):
_inherit = 'mail.compose.message'
#api.multi
def send_mail(self, auto_commit=False):
context = self._context
sale_order = self.env['sale.order']
sale_order_ids = context.get('active_ids')
if context.get('mass_mark_sale_order_as_sent') and \
context.get('default_model') == 'sale.order':
for order in sale_order.browse(sale_order_ids):
order.sent = True
return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)
<report
id="report_htp_sale_order"
string="Htp Sale Order"
model="sale.order"
name="config_htp.htp_sale_order"
rml="config_htp/report/htp_sale_order.ods"
menu="True"
/>
<record model="ir.actions.report.xml" id="report_htp_sale_order">
<field name="report_type">aeroo</field>
<field name="parser_loc">config_htp/report/htp_sale_order.pyc</field>
<field name="tml_Source">file</field>
<field name="parser_state">loc</field>
<field name="out_format" ref="report_aeroo.report_mimetypes_ods_ods"/>
<field name="in_format">oo-ods</field>
<field name="auto" eval="True" />
</record>
In context, we need to add a default template and in that template, we can choose what report we want to attach to it.
'default_use_template': True,
'default_template_id': ref('sale.email_template_edi_sale'),

XQuery SQL Extract text value from a child element of a specific node

I'm struggling with the following situation: I need to extract that '10000' after
...name="stateid"> <from>10000</from>
I've managed to extract some that I need from the first node audittrail
SELECT ref.value ('#datetime', 'nvarchar(364)') as [LastTimeActioned],
ref.value ('#changedby', 'nvarchar(364)') as [Actioned_By]
FROM Audit
CROSS APPLY audit.Xml.nodes ('/audittrail') R(ref)
<audittrail id="137943" datetime="29-Feb-2016 15:42:06" changedby="quality" type="update">
<fields>
<field id="10022" name="Content Control">
<mergedValue>dsad</mergedValue>
<from />
<to>dsad</to>
</field>
<field id="10027" name="Document Controller">
<mergedValue>quality</mergedValue>
<from />
<to>quality</to>
</field>
<field id="10028" name="Document Owner">
<mergedValue>quality</mergedValue>
<from />
<to>quality</to>
</field>
<field id="10029" name="Document Type">
<mergedValue>Contract/Agreement</mergedValue>
<from />
<to>Contract/Agreement</to>
</field>
<field id="10067" name="StateId">
<from>10000</from>
<to>10000</to>
</field>
....
</fields>
</audittrail>
You're looking for the Xpath:
(fields/field[#name="StateId"]/from)[1]
i.e. Find me the "fields/field" element with the attribute name of value StateId, and select the contents of the immediate child from element:
SELECT
ref.value ('#datetime', 'nvarchar(364)') as [LastTimeActioned],
ref.value ('#changedby', 'nvarchar(364)') as [Actioned_By],
ref.value ('(fields/field[#name="StateId"]/from)[1]', 'integer') as StateIdFrom
FROM Audit
CROSS APPLY audit.Xml.nodes ('/audittrail') R(ref)
SqlFiddle Here
Note that you need to explicitly select the first text element result in XQuery (hence the extra parenthesis() and [1])
More technically correctly, you could also restrict the selection to the text() of the child from, i.e.:
(fields/field[#name="StateId"]/from/text())[1]

Populate other field with value

I have a test many2one field. When it is populated I want the partner_id field to use the partner associated with that field. Following is not working:
<field name="partner_id" required="1"/>
<field name="x_test" context="{'partner_id': parent.partner_id}" />
you should try this :
<field name="x_test" context="{'default_partner_id': partner_id}" />
I don't know what you mean by parent.partner_id this works if you have a field named parent in the same view.
i assume you wanna put same value of partner_id in x_test field, then use related field
partner_id = fields.Many2one('res.partner', string="partner")
x_test = fields.Many2one('res.partner',related='partner_id', string="X Test")
in XML
<field name="partner_id" required="1"/>
<field name="x_test" />

What determines which More button an option shows in?

In OpenERP there is the More button in the tree view, and the More button in the form view. Sometimes options show in one, or the other, or both -- what determines which one an option shows in?
Which <More> button an option is available in is determined by the table:field ir.actions.act_window:multi and ir.values:key2 pair.
The <act_window> shortcut (which makes the option available only in the form view More) looks like this:
<act_window
name="My Custom Name Here"
id="model_table_whatever_name"
res_model="model.table"
src_model="another_model.table"
/>
which, by default, also sets:
multi = False
key2 = 'client_action_relate'
view_type = 'form'
view_mode = 'tree,form'
target = 'current'
The value combinations/results of multi/key2are:
multi / key2 --> tree More / form More
0 / client_action_relate --> No / Yes
1 / client_action_relate --> Yes / No
1 / client_action_multi --> Yes / No
0 / client_action_multi --> Yes / Yes
If you need/want more control over all the fields created in the two tables that the shortcut effects:
<record id="action_model_table_whatever_name" model="ir.actions.act_window">
<field name="name">My Custom Name Here</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">model.table</field>
<field name="src_model">another_model.table</field>
<field name="multi" eval="0"/>
... more fields here ...
</record>
<record id="model_table_whatever_name" model="ir.values">
<field name="name">My Custom Name Here</field>
<field name="model">sample.request</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_model_table_whatever_name'))"/>
<field name="key2">client_action_relate</field>
... more fields here ...
</record>
Note: While the default key2 value in the act_window shortcut is 'client_action_relate', the default value for key2 when using the record format is 'tree_but_open' -- so you can omit it when using the shortcut, but you must include it when using the record style.