Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

update fields on write() method

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
createwrite
2 Risposte
36666 Visualizzazioni
Avatar
philip

Hi all,

Take a look at my error please... in my model I have create() method to concatenate my first_name and last_name and fill into my name field and it works. I have also write() method to update if I have any changes to first_name, last_name and fill into my name field, but I got an errors below. someone can help me figure out to work my write() method, Thanks for the effort and answers

errors------

Server Traceback (most recent call last): File "/home/jp/ws/openerp/web/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/home/jp/ws/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/jp/ws/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) TypeError: write() got multiple values for keyword argument 'context'

python -----


    def create(self, cr, uid, vals, context=None):
        name = str(vals['first_name'] or '') + ' ' +str(vals['last_name'] or '')
        vals['name'] = name.title()
        return super(hr_employee, self).create(cr, uid, vals, context=context)

    def write(self, cr, uid, vals, context=None):
        name = str(vals['first_name'] or '') + ' ' +str(vals['last_name'] or '')
        vals['name'] = name
        return super(hr_employee, self).write(cr, uid, vals, context=context)

    def onchange_first_name(self, cr, uid, ids, first_name, context=None):

        if first_name:
            return {'value': {'first_name': first_name.title()}}
        return {'value':{}}

    def onchange_last_name(self, cr, uid, ids, last_name, context=None):
        if last_name:
            return {'value': {'last_name': last_name.title()}}
        return {'value':{}}

    def onchange_name(self, cr, uid, ids, last_name, context=None):
        if last_name:
            return {'value': {'last_name': last_name.title()}}
        return {'value':{}}
            
    _columns = {
        'name': fields.char('First Name', size=32),
        'date_start': fields.date('Start Date', required=True),
        'date_end': fields.date('End Date'),
        'attendance_ids' : fields.one2many('philcode.test', 'calendar_id', 'Working Time'),
        'first_name': fields.char('First Name', size=32, required=True),
        'last_name': fields.char('Last Name', size=32, required=True),
    }

xml -----

                        <label for="first_name"/>
                        <div>
                            <h1><field name="first_name" style="width: 50%%" on_change="onchange_first_name(first_name)"/></h1><br/>
                        </div>
                        <label for="last_name"/>
                        <div>
                            <h1><field name="last_name" style="width: 50%%" on_change="onchange_last_name(last_name)"/></h1>
                        </div>
                        <label for="name" String="Full Name"/>
                        <div>
                            <h1><field name="name" on_change="onchange_name(name)" style="width: 50%%"/></h1>

0
Avatar
Abbandona
Avatar
Deepa Venkatesh
Risposta migliore

parameter specified for Write method are wrong

def write(self, cr, uid, ids, vals, context=None):

Ids was not specified...

2
Avatar
Abbandona
philip
Autore

Thanks for the response, so what's right for the write method
and how to specify the ids?

OdooBot

U need not pass anything for Ids ... it is exclusively passed by openerp .....
It is d necessary syntax for it ... as it is orm method...

Sent from Yahoo! Mail on Android



From: philip <johnpaul@ictsecuritygroup.org>;
To: deep <deepa4lok@yahoo.com>;
Subject: Re: False
Sent: Mon, Sep 8, 2014 12:29:54 PM

Thanks for the response, so what's right for the write method
and how to specify the ids?

--
philip
Sent by OpenERP S.A. using Odoo about Forum Post False
Avatar
Mariusz Mizgier
Risposta migliore

You don't provide additional parameter for the write method, which is ids of the written record. If OpenERP has to write, it needs to know to which record it should write to.

1
Avatar
Abbandona
philip
Autore

I tried to put ids in my function but I got error mesaage:
name = str(vals['first_name'] or '') + ' ' +str(vals['last_name'] or '') KeyError: 'last_name'
python code def write(self, cr, uid, vals, context=None): name = str(vals['first_name'] or '') + ' ' +str(vals['last_name'] or '') vals['name'] = name return super(hr_employee, self).write(cr, uid, vals, context=context)

philip
Autore

here is my python code

def write(self, cr, uid, ids, vals, context=None): name = str(vals['first_name'] or '') + ' ' +str(vals['last_name'] or '') vals['name'] = name return super(hr_employee, self).write(cr, uid, ids, vals, context=context)

can you point me to the right direction, I don't have any idea on write() method.

Thanks for the response

Mariusz Mizgier

It means, that you don't have key of 'last_name' in your vals dictionary - you should first do the check for whether first_name or last_name are the values that are changing on the current record and based on that then create name you want to put, ie. if 'first_name' in vals and 'last_name' in vals: name = str(vals['first_name'] + str(vals['last_name']) if 'first_name' in vals and 'last_name' not in vals: do something.... (like check if record has got already its last name and you have to do your text operation on new first name, but old last name)

philip
Autore

can you fix the code

def write(self, cr, uid, vals, context=None):
name = str(vals['first_name'] or '') + ' ' +str(vals['last_name'] or '')
vals['name'] = name
return super(hr_employee, self).write(cr, uid, vals, context=context)

Thank really appreciate all your help

Mariusz Mizgier

Try this: def write(self, cr, uid, ids, vals, context=None): employee_data = self.pool.get('hr.employee').browse(cr, uid, ids) if vals['first_name'] and vals['last_name']: name = str(vals['first_name']) + ' ' +str(vals['last_name']) vals['name'] = name return super(hr_employee, self).write(cr, uid, vals, context=context) if vals['first_name']: name = str(vals['first_name']) + ' ' +str(employee_data.last_name or '') vals['name'] = name return super(hr_employee, self).write(cr, uid, vals, context=context) if vals['second_name']: employee_data = self.pool.get('hr.employee').browse(cr, uid, ids) name = str(employee_data.first_name or '') + ' ' +str(vals['second_name']) vals['name'] = name return super(hr_employee, self).write(cr, uid, vals, context=context)

philip
Autore

Thanks will try this later, is this indentation is right?
def write(self, cr, uid, ids, vals, context=None):
----employee_data = self.pool.get('hr.employee').browse(cr, uid, ids)
----if vals['first_name'] and vals['last_name']:
----name = str(vals['first_name']) + ' ' +str(vals['last_name']) vals['name'] = name
----return super(hr_employee, self).write(cr, uid, vals, context=context) if vals['first_name']:
----name = str(vals['first_name']) + ' ' +str(employee_data.last_name or '') vals['name'] = name
----return super(hr_employee, self).write(cr, uid, vals, context=context) if vals['second_name']:
----employee_data = self.pool.get('hr.employee').browse(cr, uid, ids)
----name = str(employee_data.first_name or '') + ' ' +str(vals['second_name'])
----vals['name'] = name return super(hr_employee, self).write(cr, uid, vals, context=context)

Mariusz Mizgier

No, it is not right - comments are not working well with the indents: ----def write(self, cr, uid, ids, vals, context=None): --------employee_data = self.pool.get('hr.employee').browse(cr, uid, ids) --------if vals['first_name'] and vals['last_name']: ------------name = str(vals['first_name']) + ' ' +str(vals['last_name']) vals['name'] = name ------------return super(hr_employee, self).write(cr, uid, vals, context=context) --------if vals['first_name']: ------------name = str(vals['first_name']) + ' ' +str(employee_data.last_name or '') ------------vals['name'] = name ------------return super(hr_employee, self).write(cr, uid, vals, context=context) --------if vals['second_name']: ------------name = str(employee_data.first_name or '') + ' ' +str(vals['second_name']) ------------vals['name'] = name ------------return super(hr_employee, self).write(cr, uid, vals, context=context) --------else: ------------return super(hr_employee, self).write(cr, uid, vals, context=context)

philip
Autore

Thanks will try later. thanks for your response

philip
Autore

PYTHON-----
----def write(self, cr, uid, ids, vals, context=None):
--------employee_data = self.pool.get('hr.employee').browse(cr, uid, ids)
--------if vals['first_name'] and vals['last_name']:
------------name = str(vals['first_name']) + ' ' +str(vals['last_name'])
------------vals['name'] = name
------------return super(hr_employee, self).write(cr, uid, vals, context=context)
--------if vals['first_name']:
------------name = str(vals['first_name']) + ' ' +str(employee_data.last_name or '')
------------vals['name'] = name
------------return super(hr_employee, self).write(cr, uid, vals, context=context)
--------if vals['second_name']:
------------name = str(employee_data.first_name or '') + ' ' +str(vals['second_name'])
------------vals['name'] = name
------------return super(hr_employee, self).write(cr, uid, vals, context=context)
--------else:
------------return super(hr_employee, self).write(cr, uid, vals, context=context)


ERRORS------ Server Traceback (most recent call last):
--File "/home/jp/ws/openerp/web/addons/web/session.py", line 89, in send
----return openerp.netsvc.dispatch_rpc(service_name, method, args)
--File "/home/jp/ws/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
----result = ExportService.getService(service_name).dispatch(method, params)
--File "/home/jp/ws/openerp/server/openerp/service/web_services.py", line 626, in dispatch
----res = fn(db, uid, *params)
--File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
----return self.execute(db, uid, obj, method, *args, **kw or {})
--File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 132, in wrapper
----return f(self, dbname, *args, **kwargs)
--File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 199, in execute
----res = self.execute_cr(cr, uid, obj, method, *args, **kw)
--File "/home/jp/ws/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
----return getattr(object, method)(cr, uid, *args, **kw)
--File "/home/jp/ws/openerp/my_addons/for_development/philcode_test.py", line 15, in write
----name = str(vals['first_name']) + ' ' +str(vals['last_name'])
KeyError: 'last_name'

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
launch a wizard before saving a record
wizard create write
Avatar
Avatar
1
ago 20
5575
Odoo 13 Create() Write() stores old values
create write 13.0
Avatar
Avatar
1
apr 20
6079
How to create and write multiple records by overriding create and write method of odoo12 Risolto
create write odoo12
Avatar
Avatar
1
set 19
9748
Creating a record or editing an existing record? How to know?
create write odoo12.0
Avatar
Avatar
Avatar
Avatar
3
feb 19
10206
how to override create or write method Risolto
one2many create write
Avatar
Avatar
Avatar
3
lug 17
12681
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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