Odoo Help

Welcome!

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.

0

How to filter a name field product.supplierinfo I added in sale.order.line compared to product_id?

By
tansadio
on 10/6/14, 4:24 AM 821 views

 I speak French, so I apologize more for the mistakes in English.

 

here is the code i wrote:

# I would like to display the field supplier_id of product_id

class sale_order_line(osv.Model):
    _name = 'sale.order.line'
    _inherit ='sale.order.line'
    
    _columns = {
         'supplier_id': fields.many2one('product.supplierinfo', 'Supplier',domain = [('product_id','=','product_tmpl_id')]),
    }

    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='', partner_id=False, lang=False, update_tax=True,
            date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
            
        product_obj = self.pool.get('product.product')
        partner_obj = self.pool.get('res.partner')
        partner = partner_obj.browse(cr, uid, partner_id)
        lang = partner.lang
        context_partner = {'lang': lang, 'partner_id': partner_id}
        
        res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name,
            partner_id=partner_id, lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)

        #Above lines are going to call the native function and 'res' is going to store the result, so you can change the value right there
        

        product_obj = product_obj.browse(cr, uid, product, context=context_partner)
        
        if not flag:
            res['value']['name'] = self.pool.get('product.product').name_get(cr, uid, [product_obj.id], context=context_partner)[0][1]
            if product_obj.description_sale:
                res['value']['name'] = product_obj.description_sale
        
        return res
    
sale_order_line()

 

Help me please

0
Anand Patel
On 10/6/14, 5:15 AM

Please Explain it more.

Here I selected the supplier(supplier_id) before the product(product_id). Now I would like to choose the supplier before the product. help me please

tansadio
on 10/7/14, 5:10 AM
0

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 10/6/14, 4:58 AM

This questions needs to be broadened with a lot more information. Now it makes no sense.

Here I selected the supplier(supplier_id) before the product(product_id). Now I would like to choose the supplier before the product. help me please

tansadio
on 10/7/14, 5:11 AM
0
tansadio
On 10/6/14, 8:48 AM

I just found an answer to my question

from openerp.osv import osv, fields
from openerp.tools.translate import _

class sale_order_line(osv.Model):
    _inherit = 'sale.order.line'
    _columns = {
        'supplier_id': fields.many2one('res.partner', 'Supplier',domain = [('supplier','=',True)]),
    }
    
    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}
    
sale_order_line()

## In the file xml ##

<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="supplier_id" context="{'default_customer':0,'search_default_supplier':1,'default_supplier':1}" on_change="onchange_supp(supplier_id)"/>
                </xpath>
            </field>
        </record>

Here I selected the supplier(supplier_id) before the product(product_id). Now I would like to choose the supplier before the product. help me please

tansadio
on 10/7/14, 5:10 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

2 follower(s)

Stats

Asked: 10/6/14, 4:24 AM
Seen: 821 times
Last updated: 3/16/15, 8:10 AM