Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How to inherit and modify "Name" in Sale Order lines

Subscriure's

Get notified when there's activity on this post

This question has been flagged
inheritancesale.order.line
6 Respostes
19522 Vistes
Avatar
Santi

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.

0
Avatar
Descartar
Avatar
Cyrare
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()

1
Avatar
Descartar
Santi
Autor

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

Santi
Autor

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

Avatar
Simplify it!
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

1
Avatar
Descartar
Santi
Autor

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
Autor

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

Simplify it!

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

Santi
Autor

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
Autor

...any other suggestions?

Avatar
tansadio
Best Answer
0
Avatar
Descartar
Avatar
Miguel Machado
Best Answer

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

0
Avatar
Descartar
Avatar
Santi
Autor 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()
0
Avatar
Descartar
Miguel Machado

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

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

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
odoo16 sale
sales inheritance sale.order.line
Avatar
Avatar
1
de març 23
2504
How to make a field from Sale Order form Line Item invisible by inheriting view_order_form in my custom module? Solved
views inheritance sale.order.line
Avatar
Avatar
2
de març 15
5508
Can't inherit base.view_partner_form of res.partner
inheritance
Avatar
Avatar
Avatar
Avatar
Avatar
4
de febr. 25
4149
How to add a sequence a field? Solved
sale.order.line
Avatar
Avatar
Avatar
2
de des. 24
22202
add product upon saving sales order
sale.order.line
Avatar
0
de set. 24
1507
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now