Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

[SOLVED] Working with external id in controllers

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
5 Răspunsuri
9341 Vizualizări
Imagine profil
Thomas Brouwer

Hi ! First sorry for my poor English !

Here's my problem : I'm trying to create data in a controller like this. It works and my employees are created in the employees module.

@http.route('/employees/api/employee', type='json', auth='user', methods=['POST'], cors='*', csrf=False)
def create_employee (self, **kwargs):
data = json.loads(request.httprequest.data)

employee = request.env['hr.employee'].sudo().search([('work_email', '=', data.get('work_email'))])
if employee:
return {'message': 'already exists'}
else:
id = request.env['hr.employee'].sudo().create({
'name': data.get('name'),
'work_email': data.get('email'),
}).id
return {'message': 'Employee {} created'.format(id)}

Now, I want to insert personnal address for this employee, but I don't know how to do that ... In the model, I see that it's in the address_home_id field, but I don't know how to create the address and attach the address_home_id to the newly created address !

Thanks you very much !


PS : I'm on odoo 12 ;)  

0
Imagine profil
Abandonează
Sehrish

Controllers in odoo: https://goo.gl/gPjPas

Imagine profil
Anisha Bahukhandi
Cel mai bun răspuns

Hello Thomas,

Firstly, you need to create your address inside res.partner model; then you can assign its inside employee record.

You can refer to the below mentioned code:

@http.route('/employees/api/employee', type='json', auth='user', methods=['POST'], cors='*', csrf=False)
def create_employee (self, **kwargs):
    data = json.loads(request.httprequest.data)
    employee = request.env['hr.employee'].sudo().search([('work_email', '=', data.get('work_email'))])
    if employee:
        return {'message': 'already exists'}
    else:
        # Create Home Address
        home_address = request.env['re.partner'].sudo().create({
            'name': 'Name',
            'street': 'Street',
            'street2': 'Street2',
            'city': 'City',
            'state_id': state_id,
            'country_id': country_id,
            'zip': '201301',
            'phone': '99999999',
            'email': 'email@email.com',
        })
        if home_address:
            home_address = home_address.id
            employee = request.env['hr.employee'].sudo().create({
                'name': data.get('name'),
                'work_email': data.get('email'),
                'address_home_id':home_address
            })
            if employee:
                employee = employee.id
        return {'message': 'Employee {} created'.format(employee)}
Thanks 
Anisha Bahukhandi
Technical Content Writer
Webkul Softwares
3
Imagine profil
Abandonează
Imagine profil
Thomas Brouwer
Autor Cel mai bun răspuns
thank you very much to both of you it works!
Have a nice day and thanks again !
0
Imagine profil
Abandonează
Anisha Bahukhandi

Hello Thomas,

It's great that your query is resolved and you are satisfied with my assistance for the question you asked in Odoo Forum.

I would really appreciate if you can take out a few minutes out of your busy schedule and put a google review for me here -

https://www.google.com/search?q=webkul&oq=webkul+&aqs=chrome..69i57j69i60l3j0l2.4182j0j7&sourceid=chrome&ie=UTF-8#lrd=0x390ce561c5555555:0xcfb40ae166ce6c21,1,

A nice review from your side will motivate me and my team to provide exceptional assistance.

I hope you can manage to provide few minutes for this :)

Regards

Anisha Bahukhandi

Vishnu Vanneri

Thanks

Imagine profil
Vishnu Vanneri
Cel mai bun răspuns

Hi,

I think you can create home address and assign to employee. Please check below.

@http.route('/employees/api/employee', type='json', auth='user', methods=['POST'], cors='*', csrf=False)
def create_employee (self, **kwargs):
data = json.loads(request.httprequest.data)
address_id = False

address = request.env['res.partner'].sudo().search([('email', '=', data.get('work_email')),limit=1])

if address:
address_id = address.id
else:
address_id = request.env['res.partner'].sudo().create({
'name': data.get('name'),
'email': data.get('email'),
}).id



employee = request.env['hr.employee'].sudo().search([('work_email', '=', data.get('work_email'))])
if employee:
return {'message': 'already exists'}
else:
id = request.env['hr.employee'].sudo().create({
'name': data.get('name'),
'work_email': data.get('email'),
'address_home_id' : address_id,
}).id
return {'message': 'Employee {} created'.format(id)}
0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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