This question has been flagged
3 Replies
4151 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

Avatar
Discard
Best Answer

Please Explain it more.

Avatar
Discard
Author

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

Best Answer

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

Avatar
Discard
Author

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

Author Best Answer

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>

Avatar
Discard
Author

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