I have this field
<field name="date" />
and
date = fields.Date('Order Date')
How to make it readonly and can not be edited when there is value in it?
<field name="date" attrs="{'readonly': [('date', '!=', False)]}" />
That should be enough.
Related
The below code should apply search by name, contact, and email. but it's not working as expected. I would like to know.
in the image attached, the only search is applicable for the name. but not email and contact.
<record id="merchant_search" model="ir.ui.view">
<field name="name">ecommece_advance.merchant.search</field>
<field name="model">ecommece_advance.merchant</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Merchants">
<field name="name" string="Merchant Name"/>
<field name="contact"/>
<field name="email" string="Email" filter_domain="[('email', 'ilike', self)]"/>
<separator/>
<group expand="0" string="Group By">
<filter string="Name" name="Name" domain="[]" context="{'group_by': 'name'}"/>
</group>
</search>
</field>
</record>
//model fields
name = fields.Char( required=True)
email = fields.Char(required=True)
address = fields.Char()
website = fields.Char()
latitude = fields.Float(digits=(3,6))
longitude = fields.Float(digits=(3,6))
contact = fields.Char(required=True)
alternative_contact = fields.Char()
Let's add these filters to check that your xml file is loaded :
<filter string="Name" name="Name" domain="[]" context="{'group_by': 'name'}"/>
<filter string="Email" name="Email" domain="[]" context="{'group_by': 'email'}"/>
<filter string="Contact" name="Contact" domain="[]" context="{'group_by': 'contact'}"/>
If these filters are not added, you should check that your xml file is called in the data section in your manifest.py file of your module :
'data': [
'view/merchants.xml',
Otherwise, if this record was already existing, consider inherit it from its original module and use xpath to insert your new fields in :
<record id="merchant_search" model="ir.ui.view">
<field name="inherit_id" ref="original_module.merchant_search" />
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<field name="email">email</field>
<field name="contact">contact</field>
</xpath>
</record>
I have a form view and the breadcrumb is reading False. i am not sure where to set this but I would like the Partners name instead of False.
Below is my form view
<record id="view_ds_repair_form" model="ir.ui.view">
<field name="name">ds.repair.form</field>
<field name="model">ds.repair</field>
<field name="arch" type="xml">
<form string="Repairs">
<sheet>
<label for="name" class="oe_edit_only"/>
<group>
<group>
<field name="x_partner_id" placeholder="Customer Name"/>
<field name="computer_make"/>
<field name="password" />
<field name="items" widget="many2many_tags"/>
</group>
<group>
<field name="create_date"/>
<field name="status" />
<field name="priority"/>
<field name="estimatedrepair_cost"/>
</group>
</group>
It seems name field or rec_name field value is empty. So you have to provide value of it. Afterwards, it will display correct information.
I have a question about SOLR response fields when JSON response format is obtained.
I have a Web service returning more than 20 fields and they are ordered by default as first the fields having data and after that all other fields.
My question is there a way to precise the order of the fields list, so that we obtain them always in same order ?
Example if I have the fields FIELD 1, FIELD 2, etc, I want that I preserve exactly this order and not FIELD 2, FIELD 1.
Thanks
yes you can precise the order editing the "data-config.xml" , here as you can see are declared all fields and on top are are the corresponding query , delta imports and full import . try to change the fields order in query and declaration in bottom,
example :
<dataConfig>
<dataSource type="HttpDataSource" />
<document>
<entity name="slashdot"
pk="link"
url="http://rss.slashdot.org/Slashdot/slashdot"
processor="XPathEntityProcessor"
forEach="/RDF/channel | /RDF/item"
transformer="DateFormatTransformer">
<field column="source" xpath="/RDF/channel/title" commonField="true" />
<field column="source-link" xpath="/RDF/channel/link" commonField="true" />
<field column="subject" xpath="/RDF/channel/subject" commonField="true" />
<field column="title" xpath="/RDF/item/title" />
<field column="link" xpath="/RDF/item/link" />
<field column="description" xpath="/RDF/item/description" />
<field column="creator" xpath="/RDF/item/creator" />
<field column="item-subject" xpath="/RDF/item/subject" />
<field column="slash-department" xpath="/RDF/item/department" />
<field column="slash-section" xpath="/RDF/item/section" />
<field column="slash-comments" xpath="/RDF/item/comments" />
<field column="date" xpath="/RDF/item/date" dateTimeFormat="yyyy-MM-dd'T'hh:mm:ss" />
</entity>
</document>
I'm using Odoo 9 community version.
In Sale order form has following buttons:
<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary" type="object" context="{'show_sale': True}"/>
<button name="action_confirm" states="draft" string="Confirm Sale" type="object" context="{'show_sale': True}"/>
I'm trying to hide both button from the view. So I have tried with following code.
<record model="ir.ui.view" id="hide_so_confirm_button_form">
<field name="name">hide.so.confirm.button.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="action_confirm" position="attributes">
<attribute name="invisible">1</attribute>
</button>
</field>
</record>
I have also tried following attribute:
<attribute name="states"></attribute>
With above code, it's only hide/affect first button.
Question:
How to hide both Confirm Sale button?
The mechanism without xpath only influences the first hit. That's why you have to use xpath here.
Another good example (maybe not for Odoo 9 anymore) is setting a new sale.order.line field behind the name field on sale.order form view.
The form view is something like this:
<form>
<field name="name" /> <!-- sale.order name field -->
<!-- other fields -->
<field name="order_line">
<form> <!-- embedded sale.order.line form view -->
<field name="name" />
<!-- other fields -->
</form>
<tree> <!-- embedded sale.order.line tree view -->
<field name="name" />
<!-- other fields -->
</tree>
</field>
<form>
Using your way could try setting the new field behind sale.order name field (in this example). Using xpath will lead to the goal.
<xpath expr="//form//tree//field[#name='name']" position="after">
<field name="new_field" />
</xpath>
<xpath expr="//form//form//field[#name='name']" position="after">
<field name="new_field" />
</xpath>
So to answer your question directly (EDIT):
<xpath expr="//button[#name='action_confirm' and #states='sent']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
<xpath expr="//button[#name='action_confirm' and #states='draft']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
you can use xpath ...
button[#name='action_confirm'][1]
xpath ...
button[#name='action_confirm'][2]
Hope it helps
**For Odoo 12
In addition to #CZoellner's answer, For Odoo 12, its definition on view_order_form is changed to
<button name="action_confirm" id="action_confirm"
string="Confirm" class="btn-primary" type="object"
attrs="{'invisible': [('state', 'not in', ['sent'])]}"/>
<button name="action_confirm"
string="Confirm" type="object"
attrs="{'invisible': [('state', 'not in', ['draft'])]}"/>
Please note, that in this change, there are no states attribute anymore. So, to hide these two button, we can use
<xpath expr="//button[#name='action_confirm'][1]" position="attributes">
<attribute name="attrs"></attribute>
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//button[#name='action_confirm'][2]" position="attributes">
<attribute name="attrs"></attribute>
<attribute name="invisible">1</attribute>
</xpath>
I have 2 one2many fields that are represented by one2many_list widget. The fields are:
documents_applicant_1 = fields.One2many(comodel_name='application.documents',
documents_applicant_2 = fields.One2many(comodel_name='application.documents',
inverse_name='application_id')
<group>
<field name="documents_applicant_1" widget="one2many_list"
nolabel="1">
<tree string="Variants" editable="bottom">
<field name="name" />
<field name="document_raw_data" id="document_raw_data_applicant_1" />
<!-- <field name="category" /> -->
</tree>
</field>
</group>
<group>
<field name="documents_applicant_2" widget="one2many_list"
nolabel="1">
<tree string="Variants" editable="bottom">
<field name="name" />
<field name="document_raw_data" id="document_raw_data_applicant_2" />
<!-- <field name="category" /> -->
</tree>
</field>
</group>
When the user adds records using those fields, depending on the list he uses to add a record, I want to pass a context. My layout is the following:
Now besides wanting to pass a different context when my user adds records to the left list and the right one, I want to apply a dynamic filter on the records shown on both the lists.
How can the above be achieved?
I do not wish to write javascript rather than use existing funtionality
You can add the domain you want to the One2many fields in Python code (in XML that is not going to work). And then, in XML, you can add the context using the prefix default_.
I put you an example:
Suppose you want documents_applicant_1 field for adding records
whose category is 'A', and documents_applicant_2 field for adding
records whose category is 'B'.
Then you can write:
Python code
documents_applicant_1 = fields.One2many(
comodel_name='application.documents',
inverse_name='application_id',
domain=[('category' '=', 'A')],
)
documents_applicant_2 = fields.One2many(
comodel_name='application.documents',
inverse_name='application_id',
domain=[('category' '=', 'B')],
)
XML code
<group>
<field name="documents_applicant_1" widget="one2many_list"
nolabel="1" context={'default_category': 'A', }>
<tree string="Variants" editable="bottom">
<field name="name" />
<field name="document_raw_data" id="document_raw_data_applicant_1" />
<field name="category" />
</tree>
</field>
</group>
<group>
<field name="documents_applicant_2" widget="one2many_list"
nolabel="1" context={'default_category': 'B', }>
<tree string="Variants" editable="bottom">
<field name="name" />
<field name="document_raw_data" id="document_raw_data_applicant_2" />
<field name="category" />
</tree>
</field>
</group>
I do not know if this is what you were looking for, I hope it helps you.