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 inherit and modify "Name" in Sale Order lines

By
Santi
on 2/3/14, 10:28 AM 5,766 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.

1
Cyrare
On 3/2/15, 2:14 PM

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

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

Santi
on 3/15/15, 2:32 PM

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

Santi
on 3/15/15, 2:33 PM
1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 2/3/14, 11:21 AM

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

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.

Santi
on 2/3/14, 12:00 PM

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

Santi
on 2/3/14, 12:07 PM

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

GH Mediacloud, Grover Menacho
on 2/5/14, 12:00 PM

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...

Santi
on 2/7/14, 6:43 PM

...any other suggestions?

Santi
on 2/27/14, 11:46 AM
0
tansadio
On 10/3/14, 3:31 AM
0
tansadio
On 10/3/14, 3:59 AM

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

0
Santi
On 2/7/14, 6:40 PM

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

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

Miguel Machado
on 9/4/14, 8:26 AM
0
Miguel Machado
On 9/4/14, 8:25 AM

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

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

1 follower(s)

Stats

Asked: 2/3/14, 10:28 AM
Seen: 5766 times
Last updated: 3/16/15, 8:10 AM