How to change the base fields label in openerp 6.1 - odoo

researchorial but indeed i have done all the google around what i want o achieve in openerp that how to change those fields label ,i don't wanna play with fields and i know how to create new fields but what about base fields i am not able to edit them they throw some error that you cannot change the base fields from here so objective is clear that those label like Company, SSNID in hr module i want them changed according to them nothing else!!
please do not post links of already same question cause they had not been answered !!
Thank You

You can change the label of a field in two ways.
1. Python code
Inherit the model where that field is defined, then inside _columns add the same field name with new label.
For example, if you want to change SSNID to Employee ID, assume that in the base module the field is defined as 'ssnid' and the field is in hr.employee model.
from osv import osv, fields
class hr_employee(osv.osv):
_inherit = 'hr.employee'
_columns = {'ssnid': fields.integer('Employee ID')
}
hr_employee()
2. XML code(change the view)
Inherit your view and add the attribute for the field 'ssnid'. For example in base module the field view is like <field name="ssnid"/> .To change it inherit its corresponding form and tree view and you can change the field by using position="attribute" and also position="replace". Add the attribute string="Employee ID".
<field name="ssnid" position="replace">
<field name="ssnid" string="Employee ID"/>
</field>

Create New Hr employee Inherited view By this way.
<record model="ir.ui.view" id="updated_hr_form_view">
<field name="name">updated.hr.form</field>
<field name="model">hr.employee</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<xpath expr="//form/notebook/page[#string='Personal Information'/group/field[#name='ssnid']]" position="replace">
<field name="ssnid" string="Your New Label"/>
</xpath>
</field>
</record>

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

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.

Create custom search view to search based on two fields in one2many field along with the other fields present in the module

I created a module for managing employee resume in Odoo. Employees will fill their work_experience, education, technology-wise experience, etc. I wanted to make the search view search for all these parameters. The technology-wise Experience here is a One2Many field. I wanted to search this field based on both the parameter together (i.e experience and technology). Please help me find a way to do this.
In Model
technology_experience =
fields.One2many("hr.employee.work.technology.experience",
inverse_name='resume_id', string='Technology Experience')
In view
`<field name="technology_experience">
<tree editable="bottom" create="0">
<field name="name" required="1"/>
<field name="experience" required="1"/>
</tree>
</field>
`

Is it normal fields are not updated after installing modules?

I'm developping a module on OpenERP 7.
It is a very simple code : it has only 1 new field (or column) in python file, and an xpath in the xml. I know it works because one time it was succesfully installed
When I try to install/update my module with the module interface, sometimes the field is added/updated to OpenERP, but sometimes no.
I tried to start/stop and restart Openerp before and after installing my module, but I don't know if it has consequences. I don't have errors or useful thing in the logs.
So fields don't add/update but xml update everytime... Does anyone have an idea of what's going on and a solution ?
python code:
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
class StockPickingIn(osv.osv):
_name = "stock.picking.in"
_inherit = "stock.picking.in"
_columns = {
'adquat_ack_recep': fields.boolean('Accusé de réception'),
}
xml code:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_picking_in_form_adquat" model="ir.ui.view">
<field name="name">stock.picking.in.form.adquat</field>
<field name="model">stock.picking.in</field>
<field name="inherit_id" ref="stock.view_picking_in_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='stock_journal_id']" position="after">
<field name="adquat_ack_recep" />
</xpath>
</field>
</record>
<record id="view_picking_in_tree_adquat" model="ir.ui.view">
<field name="name">stock.picking.in.tree.adquat</field>
<field name="model">stock.picking.in</field>
<field name="inherit_id" ref="stock.view_picking_in_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='state']" position="after">
<field name="adquat_ack_recep" />
</xpath>
</field>
</record>
</data>
</openerp>
I think it works to update fields with Command line -u !
But my other problem is not solved : I dont have empty checkboxes in form view
And in form view i can't have this checkbox checked :
I click on edit, i check it and save : the checkbox come back to empty !
I saw in the database the value is saved as true or false, but it's not displayed on the interface
You should see the following error
ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!
Because adquat_ack_recep is defined in stock.picking and you add it to stock.picking.in form.
You need to inherit from stock.picking.in.
_inherit = "stock.picking.in"
Edit:
Add adquat_ack_recep field to both models stock.picking and stock.picking.in (stock.picking.in read method was overitten to read values from stock.picking model). Take a look at fields not saving problem
Problem may arises due two instances running at same time. make sure you run single instance. you can also update module through command line this may solve your issue
refer this link for module updation through command line.

How to put product brand in sale order line?

I installed the product_brand module for OpenERP 6.1.
Through web client, I managed to show the product brand in the product list page by inherited the product.product.tree view through debug (developer) mode by inserting the product_brand_id field.
Now I want the product brand name to show in the sale.order.line.tree view of a sales order.
I noticed they are different models, one is product.product, and the other is sale.order.line.
Is it possible to show fields of other models in OpenERP?
How to reference a field name across related (different) models?
Its possible using related fields. First you need to inherit the sale order model and add a related field for product brand id
For example:
from osv import osv, fields
class sale_order_line(osv.osv):
_inherit = 'sale.order.line'
_columns = {
'brand_id': fields.related('product_id','product_brand_id',string='Brand',type='many2one',relation='product.brand')
}
sale_order_line()
Then need to inherit the sale order view. Sale order line tree and form view is specified inside the sale order view. SO inherit the sale order form view using xpath.For example:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_inherited_brand">
<field name="name">sale.order.brand</field>
<field name="type">form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree/field[#name='name']" position="after">
<field name='brand_id'/>
</xpath>
</field>
</record>
</data>
</openerp>