This question has been flagged
6 Replies
16860 Views

My goal is to make the "Description" (name) field in Sale Order lines to only show the products "Sales Description"(description_sale)....and NOT the products "Name"+"Sales Description" as per default.

I have already accomplished what I want by editing the "/addons/sale/sale.py" file directly:

by simply modifying this code in class sale_order_line:

    if product_obj.description_sale:
        result['name'] += '\n'+product_obj.description_sale

to

    if product_obj.description_sale:
        result['name'] = product_obj.description_sale

And now I want to add this modification to a module I have created with different modifications for my company so it survives future OpenERP updates. What is the correct way to inherit the class and modify that line of code from a custom module?

Thanks in advance for any help! ...i think it should be pretty easy for any experienced python programmer

Note1: My custom module is already up and running with other modifications, so I don't need help with that, I just need help with the python code necessary to accomplish my request above through inheritance. Note2: Before anyone recommends it to me, i'm aware there's already a module (sale_line_description) which accomplishes something similar, but INCORRECTLY....when the module is installed, when I add a product to the Sale Order line it does not use the product translation if it's a foreign partner.

Avatar
Discard
Best Answer

Hi, Try this, it's work here :

 

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

class sale_order_line(osv.osv):
    _inherit='sale.order.line'

    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):
        
        #Appeler la fonction native
        res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
            uom, qty_uos, uos, name, partner_id,
            lang, update_tax, date_order, packaging, fiscal_position, flag, context)
        
        product_obj = self.pool.get('product.product')
        partner_obj = self.pool.get('res.partner')
        partner = partner_obj.browse(cr, uid, partner_id)
        context_partner = {'lang': partner.lang, 'partner_id': partner_id}
        product_obj = product_obj.browse(cr, uid, product, context=context_partner)
        
        if not flag:
            if product_obj.description_sale:
                res['value']['name'] = product_obj.description_sale
        
        return res

sale_order_line()

Avatar
Discard
Author

Thanks! this piece of code did the trick, finally!

Author

Thanks! this piece of code did the trick, finally!

Best Answer

There is no way to modify only that line of code through inheritance, but you can override name doing this on your own module:

class sale_order_line(osv.osv)
    _inherit='sale.order.line'

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):

    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

    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

Well I'm just doing the code that you've modified. But functions can be inherited like this.

Hope that this can help you

Avatar
Discard
Author

Thanks for your quick answer Grover!

I've applied your suggested code (with two small corrections: class sale_order_line(osv.osv): and sale_order_line() ) and then restarted OpenERP server, but it doesn't change anything in the product description.

Author

Can you take a second look at your code and see if there's anything wrong?

you've to check your own module. If you can post it everything here. Maybe you didn't added 'sale' ro depends on __openerp__, or maybe you are not calling the file on __init__.py

Author

OK, I've posted it below. Before I had it in a larger module together with other fixes and modifications, but I've decided to create a separate module just for this fix, to sort out any problems...

Author

...any other suggestions?

Best Answer
Avatar
Discard
Best Answer

im trying this module in v8, but dont work for me.

Avatar
Discard
Author Best Answer

These are the different components of the simple module and their code:

Code in __init__.py:

import ti_order_lines_description

Code in __openerp__.py:

{
    "name": 'Modifications for XXX',
    "version": '1.0',
    "description": """XXX""",
    "author": 'XXX',
    "website": 'XXX',
    "depends": [
        'base',
        'sale',
    ],
    "demo": [],
    "data": [],
    "installable": True,
    "active": True,
    "category" : "",
}

Code in ti_modifications.py:

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


###Fix: Remove "Product Name" from Sale Order product lines

class sale_order_line(osv.osv):
    _inherit='sale.order.line'

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):

    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

    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()
Avatar
Discard

im trying this module in v8, but dont work for me.

Best Answer

 make the "Description" (name) field in Sale Order lines to only show the products "Sales Description"(description_sale)....and NOT the products "Name"+"Sales Description" as per default. I think this code can help you.

 

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

class sale_order_line(osv.Model):
    _name = 'sale.order.line'
    _inherit ='sale.order.line'

    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()

Avatar
Discard