Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to add supplier field in Sales order form? [Closed]

on 4/8/13, 3:24 AM 3,337 views

The Question has been closed

Sudhir Arya (SA)
on 04/18/2013 05:18:05

I am using openerp v7.

Mainly in openerp-->In sales order form, first we choose customer name and then choose products.

But my requirement is little different. In my sales order form i want to add a supplier (dropdown)field. And I added supplier field with below code.

<field name="x_supplier" context="{'default_customer':0,'search_default_supplier':1,'default_supplier':1}"/>

Thus I added supplier field.

Next I want to select products on the on_change of the supplier. ie, When I choose a supplier, its corresponding products must be shown in the dropdown list. How can I implement it?

Thanks in Advance...

How can you relate products with supplier? I mean how can we come to know which are suppliers corresponding products?

Sudhir Arya (SA)
on 4/8/13, 3:59 AM

I have add Supplier in each products. In product form, there is a Procurement Tab here we can add supplier of the corresponding product. Can we connect this product and supplier? Awaiting your reply...And Thanks for your fast reply....

on 4/8/13, 4:27 AM

Shall i ask you 2 questions? 1. Where should i paste the class sale_order_line(osv.Model): in sale.py?(I pasted last of that .py file) 2. Where should i paste the <record model="ir.ui.view" id="view_sale_order_inherit_form"> in sale_view.xml? (I pasted last of that .xml file)

on 4/10/13, 4:13 AM

Are you directly changing in core modules? You should create your own custom module rather than making changes in core modules.

Sudhir Arya (SA)
on 4/10/13, 4:20 AM

Is it not possible to change the sale module?

on 4/10/13, 4:26 AM

With this code can i create a custom module?

on 4/10/13, 4:27 AM

If you don't want to create custom module then paste the onchange_supp inside sale.order.line in sale.py and paste the &lt;field name="x_supplier_id ...." in sale.order form view before order_line/tree/product_id

Sudhir Arya (SA)
on 4/10/13, 4:31 AM

Yes you can create custom module. Right now where you are changing?

Sudhir Arya (SA)
on 4/10/13, 4:31 AM

Ok. Then follow what I said in my earlier comment.

Sudhir Arya (SA)
on 4/10/13, 4:35 AM

ok. in onchange_supp(supplier_id) how should i mention it? supplier_id or x_supplier_id?

on 4/10/13, 4:38 AM

It doesn't matter what variable name you use in method but it should be meaningful. You can either use supplier_id or x_supplier_id. It doesn't matter.

Sudhir Arya (SA)
on 4/10/13, 4:42 AM

Hi Sudhir, Very Thanks to You. Error Cleared. And it is working Fine. Thanks a Lot.

on 4/10/13, 6:57 AM

My pleasure that my efforts have solved your problem.

Sudhir Arya (SA)
on 4/10/13, 6:59 AM

Did you know how to create a new report of my custom module?

on 4/10/13, 7:11 AM

Yes, I do.

Sudhir Arya (SA)
on 4/11/13, 2:51 AM

I want to implement it in Openerp7.0. How can I?

on 4/11/13, 3:39 AM

You can create report same way as v6.0 and v6.1

Sudhir Arya (SA)
on 4/11/13, 3:49 AM

I didnt create any report in v6.0 & v6.1. I had edited the existing report in v7.0 using openoffice3.2. But dont know to create a new report for a custom module.

on 4/11/13, 3:55 AM

I used to create sxw file first, then convert it in rml file and then create parser.py file. You can refer http://doc.openerp.com/v6.1/developer/05_reports.html#openerp-server-pdf-output.

Sudhir Arya (SA)
on 4/11/13, 4:16 AM

I tried all these. But no output.

on 4/11/13, 4:36 AM

Then write post about your problem and post related code.

Sudhir Arya (SA)
on 4/11/13, 4:43 AM

I already posted it. "Doubt about report in openerp7.0"

on 4/11/13, 4:55 AM

So what is your doubt?

Sudhir Arya (SA)
on 4/11/13, 4:59 AM

other two posts 1."Doubt to export .rml file from .sxw file" , 2. Doubt about Report Generation in OpenERP.( i had tried in ubuntu, but when i implement it in windows7 errored as in the earlier post)

on 4/11/13, 5:16 AM

Did you get my doubt?

on 4/11/13, 6:44 AM

Sorry. I don't have any idea about windows.

Sudhir Arya (SA)
on 4/11/13, 6:50 AM

Did u try it with ubuntu? Then please help me.

on 4/11/13, 6:58 AM

See my answer for your question about convert sxw to rml.

Sudhir Arya (SA)
on 4/11/13, 8:08 AM

Yes, Answer is fine. But my requirement is in windows.

on 4/11/13, 8:23 AM

Ok. I never developed reports in windows environment.

Sudhir Arya (SA)
on 4/11/13, 8:29 AM

Ok. Very very Thanks for your help.

on 4/11/13, 8:30 AM

Sudhir Arya (SA)

--Sudhir Arya (SA)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow




Sudhir Arya (SA)
On 4/8/13, 5:37 AM
class sale_order_line(osv.Model):
    _inherit = 'sale.order.line'
    _columns = {
        'x_supplier': fields.many2one('res.partner', 'Supplier'),

    def onchange_supp(self, cr, uid, ids, supplier_id):
        res = []
        product_obj = self.pool.get('product.product')
        supp_info_obj = self.pool.get('product.supplierinfo')
        supp_info_ids = supp_info_obj.search(cr, uid, [('name', '=', supplier_id)])
        product_ids = product_obj.search(cr, uid, [('seller_ids', 'in', supp_info_ids)])
        domain = {
        'product_id':[('id', 'in', product_ids)],
    return {'domain': domain}

Add x_supplier in sale order line tree view:

<record model="ir.ui.view" id="view_sale_order_inherit_form">
    <field name="name">sale.order.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/tree/field[@name='product_id']" position="before">
            <field name="x_supplier_id" context="{'default_customer':0,'search_default_supplier':1,'default_supplier':1}" on_change="onchange_supp(x_supplier_id)"/>

I tried this code and is working for me.

Hope this will fulfil your requirement.


Oh. So you want to put supplier field in sale.order.line? And you want to add products related to selected supplier? Am I right?

Sudhir Arya (SA)
on 4/8/13, 10:16 AM

Yes you are right. I am looking the same. Can you help me?

on 4/10/13, 2:18 AM

Then this code will work. I have updated it. You just try it.

Sudhir Arya (SA)
on 4/10/13, 2:21 AM

Priyesh Solanki (pso)

--Priyesh Solanki (pso)--
Tiny ERP Pvt Ltd
| 2 2 4
--Priyesh Solanki (pso)--
Priyesh Solanki (pso)
On 4/8/13, 5:19 AM

You can try this:

supplier_info_obj = self.pool.get('product.supplierinfo')
supplier_info_ids = supplier_info_obj.search(cr, uid, [('name','=',x_supplier)],context=context)
product_ids = []
for supplier_info_id in supplier_info_obj.browse(cr, uid, supplier_info_ids, context=context):
print product_ids

As I don't know exactly regarding x_supplier field definition, I use it by considering many2one(return type integer). Table for Supplier in product is referring this object 'product.supplierinfo'.

Thanks, Priyesh Solanki

Hi Priyesh, Where i have to add this code? In sale.py? Which line? Please reply... And x_supplier is custom field i added in sale.order model. I have also see supplier field in product.supplierinfo model. How can i connect it with sale.order model?

on 4/8/13, 5:28 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 4/8/13, 3:24 AM
Seen: 3337 times
Last updated: 3/16/15, 8:10 AM