Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
Odoo13.0create()
16 Replies
18467 Zobrazenia
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
Zrušiť
Sehrish

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

Avatar
Prakash
Best Answer
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
Zrušiť
Moaz Mabrok
Autor

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

Moaz Mabrok
Autor

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
Autor

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
Autor

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)
Best Answer

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
Zrušiť
Moaz Mabrok
Autor

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
Autor

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
Autor

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

Moaz Mabrok
Autor

the company has been created but the form is not saving

Niyas Raphy (Walnut Software Solutions)

See the updated answer,

Moaz Mabrok
Autor

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

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

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
what is difference between these vals.get("field name", False) and vals['field name'] == False Solved
Odoo13.0 create()
Avatar
Avatar
Avatar
2
júl 21
6299
Odoo 13. Don't close a wizard when Click a button Solved
Odoo13.0
Avatar
Avatar
Avatar
Avatar
4
máj 24
14089
Permission error while user printing excel sheet report in odoo 13 Solved
Odoo13.0
Avatar
Avatar
1
apr 24
4335
One2many field edited from Transient Model cannot be made empty.
Odoo13.0
Avatar
0
nov 23
3021
Blank White Page After log in to Odoo13 Solved
Odoo13.0
Avatar
1
sep 23
3165
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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