Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
How to add supplier field in Sales order form? [Closed]
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...
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)"/>
</xpath>
</field>
</record>
I tried this code and is working for me.
Hope this will fulfil your requirement.
Thanks.
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?
Then this code will work. I have updated it. You just try it.
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):
product_ids.append(supplier_info_id.product_id.id)
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?
About This Community
This platform 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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 4/8/13, 3:24 AM |
Seen: 4585 times |
Last updated: 9/26/17, 12:18 AM |
How can you relate products with supplier? I mean how can we come to know which are suppliers corresponding products?
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....
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)
Are you directly changing in core modules? You should create your own custom module rather than making changes in core modules.
Is it not possible to change the sale module?
With this code can i create a custom module?
If you don't want to create custom module then paste the
onchange_supp
insidesale.order.line
in sale.py and paste the<field name="x_supplier_id ...."
insale.order
form view beforeorder_line/tree/product_id
Yes you can create custom module. Right now where you are changing?
Ok. Then follow what I said in my earlier comment.
ok. in onchange_supp(supplier_id) how should i mention it? supplier_id or x_supplier_id?
It doesn't matter what variable name you use in method but it should be meaningful. You can either use
supplier_id
orx_supplier_id
. It doesn't matter.Hi Sudhir, Very Thanks to You. Error Cleared. And it is working Fine. Thanks a Lot.
My pleasure that my efforts have solved your problem.
Did you know how to create a new report of my custom module?
Yes, I do.
I want to implement it in Openerp7.0. How can I?
You can create report same way as v6.0 and v6.1
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.
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.
I tried all these. But no output.
Then write post about your problem and post related code.
I already posted it. "Doubt about report in openerp7.0"
So what is your doubt?
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)
Did you get my doubt?
Sorry. I don't have any idea about windows.
Did u try it with ubuntu? Then please help me.
See my answer for your question about convert sxw to rml.
Yes, Answer is fine. But my requirement is in windows.
Ok. I never developed reports in windows environment.
Ok. Very very Thanks for your help.