How to put product brand in sale order line? - 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>

Related

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.

Inheriting a model and adding new field to the model odoo 12

I'm trying to add a new field in the res.users model near the field named partned_id in that model.But im not getting the field in the view and i dont understand why.
I have tried below code:
*.py
class Users(models.Model):
_inherit = "res.users"
reporting_to = fields.Many2one('res.users',string="Reporting To")
*.xml
<record id="view_users_form_inherit" model="ir.ui.view">
<field name="name">res.users.form.inherit</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='partner_id']" position="after">
<field name="reporting_to"/>
</xpath>
</field>
</record>
Assuming you have registered your XML in the manifest file.
The partner_id field exists many times on the base view. It may find the wrong one. Use a more exact xpath.
There are two partner_id field tags inside view_users_form, To show the reporting_to field after the related partner field, trigger the partner field which is inside a group tag:
<xpath expr="//group/field[#name='partner_id']" position="after">
<field name="reporting_to"/>
</xpath>

Relational Fields within the same model (Odoo)

So, I'm pretty new to Odoo... and I'm having trouble with relational fields in 10. This seems like it should be an incredibly simple thing to do, but I can't figure it out...
I'm trying to populate my sale orders with the custom fields that I added to my products page and (obviously) have those fields on the sales order contain the information from the product page. This is all within the same module (sales)
For an example; one of the things my company does is grade the products we assess and repair for our customers. I'd like to be able to have that grade on the sale order.
Here is a screenshot of my product page:
http://imgur.com/a/vm1lI
Thanks!
In your module inherit the sale_order model, and add the related fields.
class sale_order(models.Model):
_inherit = 'sale.order'
# If your grade field is a CharField
grade = fields.CharField(related='product_id.grade', string='Grade')
Inherit the sale_order view, and insert the grade field where you like. In the example below we insert it before the state field.
<openerp>
<data>
<record id="sale_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="type">form</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='state']" position="before">
<field name="grade"/>
</xpath>
</field>
</record>
<data>
<openerp>
For changes to take effect you might need to upgrade your module.

Odoo tree view with create_date

Do you know how to insert the column create_date on the Odoo Customers Tree View? It would let me see the most recent clients created on the system.
Thank you,
Eduardo
for insert the column create_date on the Odoo Customers Tree View follow the following steps:-
1:- inherit in .py file
from openerp import models, fields, api, _
class ResPartner(models.Model):
_inherit = 'res.partner'
create_date = fields.Datetime("Date")
2:- extend res.partner tree view.
<record id="view_inherit_res_partner_tree" model="ir.ui.view">
<field name="name">res.partner</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='function']" position="before">
<field name="create_date"/>
</xpath>
</field>
</record>
I would advise against changing the _order attribute on the model as that changes the order in the database, which may not be what you are trying to achieve. Instead, add a default_order="create_date desc" attribute to the tree element of the list view. In the arch:
<tree position="attributes">
<attribute name="default_order">create_date desc</attribute>
</tree>
Follow this step
1/ Inherit res_partner class.
In your .py file, add this code.[redefine _order attribute]
class res_partner(osv.Model):
_inherit = "res.partner"
_order = "create_date desc"
res_partner()
2/ In your view file, inherit the partner's tree-view and add create_date field.
<record id="view_partner_tree_extended" model="ir.ui.view">
<field name="name">res.partner.extended</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='display_name']" position="before">
<field name="create_date"/>
</xpath>
</field>
</record>
Note : No need to add create_date field in python file because it comes from osv.model base class.
_order atttribute is used for sort the records as your requirement.
Restart server and update your module.
Hope It will work for you !!
Let me know if you have any query.
As create_date is Automatic fields in Odoo, you can directly access it in the tree view.
Example:-
<record id="customer_list_view" model="ir.ui.view">
<field name="name">customer.tree</field>
<field name="model">bank.customer</field>
<field name="arch" type="xml">
<tree string="Customer View">
<field name="name"/>
<field name="contact"/>
<field name="create_date"/> // Directly access from database(no need to declare in model)
</tree>
</field>
</record>
I'd suggest that you'll use xpath and inherit the tree view from the customers. The following xml should work:
<record id="inherit_customer_tree_view" model="ir.ui.view">
<field name="name">res.partner.tree.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='display_name']" position="before">
<field name="create_date" />
</xpath>
</field>
</record>
To insert create_date into the tree view
first create a field with the same name ['create_date'] in your .py file
'create_date':fields.datetime('Create Date')
then put it in your tree view. It will work.
Write code in your specific tree view
<record id="my_tree_view_id" model="ir.ui.view">
<field name="name">my.mode.view.tree</field>
<field name="model">my.model</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<tree string="My model tree view">
<field name="name" />
<field name="product_count" />
<field name="write_date" />
</tree>
</field>
</record>
Using the write_date in field tag then print date with time in specific tree view.
you can direct declare in xml. No need to define .py file. Because create_date is a odoo magic field. so, you can declare directly in tree view.
<data>
<xpath expr="//field[#name='display_name'][not(ancestor::field)]" position="after">
<field name="create_date"/>
</xpath>
<xpath expr="//field[#name='create_date'][not(ancestor::field)]" position="after">
<field name="create_uid"/>
</xpath>
</data>
Place this code in a view using the developers tool button in the partner tree
create_date = date
create_uid = the user that created the partner
In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.
The purpose of inheritance or why we need inheritance is given below:
To change attributes of some fields which exists on existing/custom
model (e.g. making fields readonly,invisible)
To add/modify/delete old or new fields in existing/custom model
(e.g. Product, Sales, HR, Fleet Management, Attendance modules model
etc)
We can also add buttons in already existing/custom model (form and
tree) view by using inheritance

How to change the base fields label in openerp 6.1

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>