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

on record creation run function to create a record in another module odoo 13

Iscriviti

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

La domanda è stata contrassegnata
Odoo13.0create()
16 Risposte
18491 Visualizzazioni
Avatar
Moaz Mabrok

I was trying to create a new company when a record is created in my module but using the create method 

but I can't get it to work

     @api.model
def create(self, vals):
for n_record in self:
company_info ={
'company_type': 'company',
'name': n_record.new_company_name,
'vat': n_record.company_trn
}
record = n_record.env['base.view_partner_form'].create(company_info)

return record

I got this error and I can't understand the Error 

Odoo Server Error
Traceback (most recent call last):
........
........
 return result.id if isinstance(args[0], Mapping) else result.ids
AttributeError: 'NoneType' object has no attribute 'id'

can please help 


edit

@api.model
def create(self, vals):
company_info ={
'company_type': 'company',
'name': self.new_company_name,
'vat': self.company_vat
}
record = self.env['res.partner'].create(company_info)

return record

Something went wrong !

Contacts require a name

1
Avatar
Abbandona
Sehrish

Override odoo methods: https://goo.gl/4BkizH

Avatar
Prakash
Risposta migliore
Hi,
Remove return record
and add return super "yourclassname"
@api.model
def create(self, vals):
company_info ={
'company_type': 'company',
'name': self.new_company_name,
'vat': self.company_vat
}
record = self.env['res.partner'].create(company_info)
return super(yourclassname, self).create(vals)


1
Avatar
Abbandona
Moaz Mabrok
Autore

can you explain using my code, I can't understand your example

Moaz Mabrok
Autore

what is the `ClassName` for `res.partner` or the contacts

Prakash

Are you overriding default create method? In that case create method add below code: change "classname" into your class name.

return super(classname, self).create(values)

Moaz Mabrok
Autore

I am overriding my module `A` create method so after creating the recored in `A` it create a recored in odoo contacts module `B`

Prakash

Updated code, please check remove return record and add return super yourclassname ...

Moaz Mabrok
Autore

how to make it run a function on create instead of having the code in the create function it self

Avatar
Niyas Raphy (Walnut Software Solutions)
Risposta migliore

Hi,

Change this line record = n_record.env['base.view_partner_form'].create(company_info) to

record = self.env['res.company'].create(company_info) and see .


For creating records from code, see : Create Record From Code in Odoo


For Over riding the create method,

@api.model
def create(self, vals):
result = super(ClassName, self).create(vals)
# do what you want
return result

See : - How To Override Create Function in Odoo


Thanks

1
Avatar
Abbandona
Moaz Mabrok
Autore

That is the tutorial that I was following

I am still getting the error

File "/usr/lib/python3/dist-packages/odoo/api.py", line 385, in call_kw

result = _call_kw_model_create(method, model, args, kwargs)

File "/usr/lib/python3/dist-packages/odoo/api.py", line 366, in _call_kw_model_create

return result.id if isinstance(args[0], Mapping) else result.ids

AttributeError: 'NoneType' object has no attribute 'id'

Moaz Mabrok
Autore

I user this instead

@api.model

def create(self, vals):

company_info ={

# 'company_type': 'company',

'name': self.new_company_name,

'vat': self.company_trn

}

record = self.env['res.company'].create(company_info)

return record

and geting

×

The operation cannot be completed:

- Create/update: a mandatory field is not set.

- Delete: another model requires the record being deleted. If possible, archive it instead.

Model: Companies (res.company), Field: Company Name (name)

Niyas Raphy (Walnut Software Solutions)

Make sure that the value for the all the mandatory fields are passed in to the create method, here in your code as per the error self.new_company_name might be returning empty or False, just print it and see, also you can try with vals['new_company_name']

Thanks

Moaz Mabrok
Autore

I tried vals['new_company_name'] I am not going the error but is stuck save

Moaz Mabrok
Autore

the company has been created but the form is not saving

Niyas Raphy (Walnut Software Solutions)

See the updated answer,

Moaz Mabrok
Autore

how to make it run a function on create instead of having the code in the create function it self

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à
what is difference between these vals.get("field name", False) and vals['field name'] == False Risolto
Odoo13.0 create()
Avatar
Avatar
Avatar
2
lug 21
6305
Odoo 13. Don't close a wizard when Click a button Risolto
Odoo13.0
Avatar
Avatar
Avatar
Avatar
4
mag 24
14110
Permission error while user printing excel sheet report in odoo 13 Risolto
Odoo13.0
Avatar
Avatar
1
apr 24
4342
One2many field edited from Transient Model cannot be made empty.
Odoo13.0
Avatar
0
nov 23
3032
Blank White Page After log in to Odoo13 Risolto
Odoo13.0
Avatar
1
set 23
3175
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