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
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • 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

onchange method not working

Subscriure's

Get notified when there's activity on this post

This question has been flagged
v7sale.order.formonchange
3 Respostes
15045 Vistes
Avatar
Sam path

Hi all,

I've created a masters for a terms and conditions. My-module.py

class tc_name(osv.osv): _name = 'tc.name'

def name_get(self, cr, uid, ids, context=None):
  res = []
  for code_obj in self.browse(cr, uid, ids, context=context):
      tc_name = code_obj.tc_name
      res.append((code_obj.id, tc_name))
  return res

_columns = {
            'tc_name': fields.char('Terms & Condition', size=150),
            'tc_desc': fields.text('Description')
            }

tc_name()

my_module.xml

<record id="view_tc_name_form" model="ir.ui.view">
    <field name="name">view.tc.name.form</field>
    <field name="model">tc.name</field>
    <field name="arch" type="xml">
        <form string="Terms and Conditions" version="7.0">
            <sheet>
                <group>
                    <group>
                        <field name="tc_name" strin="Terms and Condition" required="True"/>
                        <field name="tc_desc" required="True"/>
                    </group>
                </group>
            </sheet>
        </form>
    </field>
</record>

<record id="view_tc_name_tree" model="ir.ui.view">
    <field name="name">view.tc.name.tree</field>
    <field name="model">tc.name</field>
    <field name="arch" type="xml">
        <tree string="Terms and Conditions" version="7.0">
            <field name="tc_name" string="Terms and conditions"/>
        </tree>
    </field>
</record>

<record id="action_tc_name" model="ir.actions.act_window">
    <field name="name">Terms and Conditions</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">tc.name</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="view_id" ref="view_tc_name_tree"/>
</record>

<menuitem id="menu_tc_name_config" action="action_tc_name" name="Terms and Conditions" parent="base.menu_base_config" sequence="6"/>

this is working fine.

  • my_module.py

class extra_fields(osv.osv):

_inherit = "sale.order"
_columns = {
    'tc_name': fields.many2one('tc.name','Terms and Condition'),
    'tc_desc': fields.text('Description')
    }

def onchange_tc_name(self, cr, uid, ids, tc_name):
    v={}
    if tc_name:
        tc = self.pool.get('tc.name').browse(cr, uid, tc_name)
        v['tc_desc'] = tc.tc_desc
        return{'value':v}

my_module.xml

<record model="ir.ui.view" id="extra_fields_sale_order">
    <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">
        <group name='sale_total' position='after'>
            <group string="Terms and Conditions">
                <field name="tc_name" string="T & C" widget="selection" onchange="onchange_tc_name(tc_name, tc_desc, context)"/>
                <field name="tc_desc" string="Description"/>
            </group>
        </group>
    </field>
</record>

The master wosks fine and even it pull downs in sale order view but the onchange method does'nt work. I need the description of the terms and condition master to populate one the description field in sale order on change of terms and condition selected. Can anyone help me out?

0
Avatar
Descartar
Sam path
Autor

Sorry i forgot to mention another thing can I edit the description field on sale order view after the onchange method executes

Avatar
René Schuster
Best Answer

In your .xml file use on_change="..." attribute instead of onchange="...".

Also, follow the advise of senthil and double check your function parameters.

Regards.

post scriptum: Yes, you can change the description field. But whenever you change tc_name the on_change method will be triggered and replace the description.

3
Avatar
Descartar
Sam path
Autor

Thanks a lot Rene it worked for me..!

Sam path
Autor

Hi Rene, I have an another issue can you please help me out in that. The link is http://help.openerp.com/question/51091/filter-on-many2many-fields

Avatar
Jagdish Panchal
Best Answer

HI,

Try this code

def onchange_tc_name(self, cr, uid, ids, tc_name):
    v={}
    if tc_name:
        tc_name_id = self.pool.get('tc.name').search(cr, uid,[('tc_name','=',tc_name)])
        for tc_name_data in self.pool.get('tc.name').browse(cr, uid, c_name_id):
            v = { 'tc_desc': tc_name_data.tc_desc}

    return{'value':v}
1
Avatar
Descartar
Senthilnathan

i think both v['tc_desc'] = tc.tc_desc & v = { 'tc_desc': tc.tc_desc}

Sam path
Autor

It doesn't work i tried both your answer but the data doesn't fetches.

Jagdish Panchal

I have update answer pls try it.

Avatar
Senthilnathan
Best Answer

I think parameter problem

def onchange_tc_name(self, cr, uid, ids, tc_name):

See you have only one paramter in the py file

and try to pass three parameters

<field name="tc_name" string="T & C" widget="selection" on_change="onchange_tc_name(tc_name, tc_desc, context)"/>

Change it like this and check

<field name="tc_name" string="T & C" widget="selection" on_change="onchange_tc_name(tc_name)"/>

If there is problem again check ur server log post it here

1
Avatar
Descartar
Sam path
Autor

this doesn't work but there is no error displayed

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
Preventing On change recursion
v7 onchange
Avatar
1
de març 15
6252
In the onchange function the readonly fields are not working
v7 readonly onchange
Avatar
Avatar
1
de març 15
8892
on_change inside linked one2many class
one2many v7 onchange
Avatar
Avatar
1
de març 15
5261
How to trigger function on object write? Solved
addon v7 orm onchange
Avatar
Avatar
Avatar
Avatar
4
de juny 20
27987
How to edit sales.order.form to work with inline editing in the product grid?
product v7 sale.order.form grid
Avatar
Avatar
1
de maig 17
10580
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