How can I make the Odoo delivery address show inline on the order? - odoo

The partner_id has a context
{'show_address': 1}
Which I thought made the address show inline, but setting the context doesn't seem to accomplish the same thing on partner_shipping_id
<field name="partner_shipping_id" position="attributes">
<attribute name="context">{'show_address':1,'default_type':'delivery'}</attribute>
</field>
What am I missing?

Seems like I also need to make it always reload as the address is pulled in dynamically.
<field name="partner_shipping_id" position="attributes">
<attribute name="context">{'show_address':1,'default_type':'delivery'}</attribute>
<attribute name="options">{"always_reload": True}</attribute>
</field>

Yes you are right you missed
always_reload
Since the web client has already sent the record with a value it will not call name_get method. so the always_reload option in Many2one field forces to call name_get method explicitly

Related

How to not allow Many2many to be able to remove its element in form view?

I have a many2many field that represents a list of student. I want to only add student to that list but not remove any students from that list (in form view). Is it possible to implement that?
I think it's possible to do it. You need to override the #write method. Each time that an update will be made on your object, you need the compare the actual length of your many2many field current_length and the new length of students made by the update new_length.
If new_length > current_length, it's means that the update is an adding, so you can consider the changes. Otherwise, it's means that the update is a removing, so you just need to ignore the changes.
Please find below, an exemple of implementation :
#api.multi
def write(self, values):
current_length = len(self.student_list)
new_length = len(values['student_list'])
if current_length > new_length:
\* Removing of students *\
values['student_list'] = self.student_list
res = super(Object, self).write(values)
return res
Note that you can go further by making another comparaison between the ids of the current and new list, in order to be sure that the students are the same.
It s not possible using the many2many_tags widget, but using the xml tree view as part of your Form view, you can add the delete-attribute on the tree-node inside the scope of your own field:
<form>
<notebook>
<sheet>
<page string="Graduated" name="gratuated_students">
<field name="students_ids" >
<tree string="Students" editable="bottom" delete="0" >
<field name="name"/>
<field name="birthday"/>
<field name="score" readonly="1"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
If this view comes from an odoo's module (no custom module): you'd rather inherit this view and add the attribute "delete=0" to the existing student_ids field:
<xpath expr="//form[1]/sheet[1]/notebook[1]/page[1]/field[#name='students_ids']/tree[1]" position="attributes">
<attribute name="delete">0</attribute>
</xpath>
Otherwise, if you really want to use the many2many_tags widget and if your are experienced with odoo's js-framework, you could develop your own option "no_delete" on the basis of the following OCA module:
https://odoo-community.org/shop/web-m2x-options-2661#attr=10772

Need to change field name in account form in odoo 11

I need to change a field name in Odoo 11 installed on Windows.
In the customer credit notes field name (Taxes), I need to change that to (Pat).
How can I change it? Is it possible to change in XML through overriding and is it the correct way?
Yes you can do this through the xml using either one of below method.
<xpath expr="//field[#name='your_field_name']" position="attributes">
<attribute name="string">Pat</attribute>
</xpath>
OR
<field name="your_field_name" position="attributes">
<attribute name="string">Pat</attribute>
</field>
I hope it will help you.
You can do in XML if you want to do it only in that view. If you want to do it for all views, add string option in your Python code:
tax_ids = fields.Many2many('taxes.taxes',string = 'Pat' )
So in your dB and code references it will be called tax_ids but the user will see 'Pat'

Invisible two buttons using xpath in Odoo 10

In sale.order form view, there are two buttons Send by Email. One for draft state and another for sent, sale. I need to hide both buttons. I tried below code:
<xpath expr="//button[#name='action_quotation_send']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
The result is: The button in draft state become invisible, another button is still visible.
How can I hide that button too?
Use below code how it is, to hide both buttons by replacing with nothing.
<xpath expr="//button[#name='action_quotation_send']" position="replace"/>
<xpath expr="//button[#name='action_quotation_send']" position="replace"/>
I know it looks weird cause its exactly the same code twice but it worked for me.
We have to set attribute for both buttons.
Try with following code:
<xpath expr="//button[#name='action_quotation_send' 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_quotation_send' and #states='draft']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath>
I know it's late, but might help someone in future.
<xpath expr="(//button[#name='action_quotation_send'])[1]" position="attributes">
...
</xpath>
<xpath expr="(//button[#name='action_quotation_send'])[2]" position="attributes">
...
</xpath>
Refer How can you identify multiple elements with the same name in XPath?

Hide fields in odoo9 openerp

I want hide fields for user in odoo 9. For example, hide Deadline in Project > Task module.
Only administrator can see this fields.
Any solution how create group etc. hide_only_admin_see and in field add this line.
<field name="date_deadline" groups="hide_only_admin_see" />
I'm find in source groups="base.group_no_one", groups="base.group_user"
but don't understand is it possible create my own group, when add to fiels that only Manager can see this...
Here is my solution:
https://postimg.org/image/rvxi74f51/
https://postimg.org/image/b87h1dlhv/
https://postimg.org/image/5mzst1wtz/
ID from file add to field etc: groups="export.res_groups_84"
On odoo 8, you forbid access to a field to all users (except configuration permissions) in that way:
<field name="date_deadline" position="attributes">
<attribute name="groups">base.group_system</attribute>
</field>
To create new group of permissions,
on odoo 8, you can create record for new category like:
<record model="ir.module.category" id="xxx">
<field name="name">Name of new category of permissions</field>
<field name="sequence">200</field>
</record>
You can create new records for groups permission on res_groups:
<record model="res.groups" id="hide_only_admin_see">
<field name="category_id" ref="XXXX"/>
<field name="name">Usuario</field>
</record>
On category_id you must write the ir_module_category you are creating / overridiing.
After this, you have to create a line on your ir.model.access.csv to give correct permissions to the model you want, something like:
"access_project.issue","project_issue access","model_project_issue","hide_only_admin_see",1,0,0,0
Finally, go to the line and override like:
<field name="date_deadline" groups="your_custom_module.hide_only_admin_see" />

make a page tab dynamic invisible with domain in inherited view

I try to make a page tab in a view dynamicly visible based on the value of a field of the model. A field that is availble on the screen.
I need to change this is an inherited view
I tried:
<xpath expr="//page[#string='Functions']" position="attributes">
<attribute name="invisible">[('org_type_id','!=',0)]</attribute>
</xpath>
But now the page tab function is always hidden. even for the org_type_id that are 0.
Is it not possible to use xpath to add a dynamic invisible attritbute?
You are totally going on wrong way to do that job.
Just you can do with the the following way to do your job
some thing like this.
<xpath expr="//page[#string='Functions']" position="attributes">
<attribute name="attrs">{'invisible':[('org_type_id','!=',0)]}</attribute>
I hope this should helpful for you :)
You should also try this,
<page string="Functions" position="attributes">
<attribute name="attrs">{'invisible':[('org_type_id','!=',0)]}</attribute>
</page>