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
    • Artificial Intelligence
    • 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
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Property Management
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • 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
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • 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
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

Create a res.partner object from a controller

Subscriure's

Get notified when there's activity on this post

This question has been flagged
res.partnercontrollersController
1 Respondre
6383 Vistes
Avatar
Blessings

Hello everyone, I'm using Odoo 15 and here's my controller code:


@http.route('/res_partner/create_partner', type='json', auth='none')
    def create_partner(self, json_data):

        vals = ast.literal_eval(json_data)
        admin_id = request.env.ref('base.user_admin')

        vals['company_id'] = admin_id.company_id.id
        vals['user_ids'] = [[6, False, [admin_id.id]]]
        vals['user_id'] = admin_id.id
        vals['is_company'] = False
        # vals['property_account_receivable_id'] = 2  
        # vals['property_account_payable_id'] = 3    
        vals['active'] = False
        vals['type'] = 'contact'
        vals['company_type'] = 'person'

        try:
            new_partner = request.env['res.partner'].sudo().create(vals)
        except Exception as ex:
            logging.warning(ex)
            data = {'response': [], 'message': "Exception occured while creating a partner"}
            return data
       
        else:
            if new_partner:
                data = {'response': [{'id': new_partner.id, 'name' : new_partner.name}], 'message': 'Success'}
            else:
                data = {'response': [], 'message': "Problem occurred with the new partner"}
            return data

Error:

2023-04-20 08:53:21,522 15886 ERROR odoo15_numerp odoo.sql_db: bad query:
                SELECT substr(p.res_id, 13)::integer, r.id
                FROM ir_property p
                LEFT JOIN stock_location r ON substr(p.value_reference, 16)::integer=r.id
                WHERE p.fields_id=3762
                    AND (p.company_id=false OR p.company_id IS NULL)
                    AND (p.res_id IN ('res.partner,56') OR p.res_id IS NULL)
                ORDER BY p.company_id NULLS FIRST
           
ERROR: operator does not exist: integer = boolean
LINE 6:                     AND (p.company_id=false OR p.company_id ...
                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
 
2023-04-20 08:53:21,522 15886 WARNING odoo15_numerp root: operator does not exist: integer = boolean
LINE 6:                     AND (p.company_id=false OR p.company_id ...
                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
 
2023-04-20 08:53:21,523 15886 INFO odoo15_numerp odoo.addons.phone_validation.tools.phone_validation: The `phonenumbers` Python module is not installed, contact numbers will not be verified. Please install the `phonenumbers` Python module.
2023-04-20 08:53:21,525 15886 ERROR odoo15_numerp odoo.sql_db: bad query: SELECT "res_users"."id" as "id", "res_users"."partner_id" as "partner_id", "res_users"."login" as "login", "res_users"."signature" as "signature", "res_users"."active" as "active", "res_users"."action_id" as "action_id", "res_users"."share" as "share", "res_users"."company_id" as "company_id", "res_users"."create_uid" as "create_uid", "res_users"."create_date" as "create_date", "res_users"."write_uid" as "write_uid", "res_users"."write_date" as "write_date", "res_users"."notification_type" as "notification_type", "res_users"."odoobot_state" as "odoobot_state", "res_users"."odoobot_failed" as "odoobot_failed", "res_users"."sale_team_id" as "sale_team_id", "res_users"."oauth_provider_id" as "oauth_provider_id", "res_users"."oauth_uid" as "oauth_uid", "res_users"."oauth_access_token" as "oauth_access_token" FROM "res_users" WHERE "res_users".id IN (1)
ERROR: current transaction is aborted, commands ignored until end of transaction block
 
2023-04-20 08:53:21,525 15886 ERROR odoo15_numerp odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/api.py", line 886, in get
    return field_cache[record._ids[0]]
KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1057, in __get__
    value = env.cache.get(record, self)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/api.py", line 889, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'res.users(1,).partner_id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 687, in dispatch
    result = self._call_function(**self.params)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 359, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 355, in checked_call
    self._cr.flush()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/sql_db.py", line 109, in flush
    self.transaction.flush()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/api.py", line 833, in flush
    env_to_flush['base'].flush()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 5644, in flush
    self.recompute()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 6117, in recompute
    process(field)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 6101, in process
    field.recompute(recs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1243, in recompute
    self.compute_value(recs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1265, in compute_value
    records._compute_field_value(self)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/addons/mail/models/mail_thread.py", line 411, in _compute_field_value
    return super()._compute_field_value(field)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 4255, in _compute_field_value
    getattr(self, field.compute)()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/addons/base/models/res_partner.py", line 301, in _compute_partner_share
    super_partner = self.env['res.users'].browse(SUPERUSER_ID).partner_id
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 2603, in __get__
    return super().__get__(records, owner)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1083, in __get__
    recs._fetch_field(self)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 3276, in _fetch_field
    self._read(fnames)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/addons/base/models/res_users.py", line 449, in _read
    super(Users, self)._read(fields)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 3343, in _read
    cr.execute(query_str, params + [sub_ids])
  File "", line 2, in execute
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/sql_db.py", line 90, in check
    return f(self, *args, **kwargs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/sql_db.py", line 313, in execute
    res = self._obj.execute(query, params)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block

0
Avatar
Descartar
Avatar
Blessings
Autor Best Answer

It seems that it is impossible to create a res.partner object when there's no session(not logged in). So, I found out that I need to authenticate as a user before calling the res.partner create method.


@http.route('/res_partner/create_partner', type='json', auth='none')
def create_partner(self, json_data):

​test = request.session.authenticate(db="odoo15", login="admin", password="admin")

​session_info = request.env['ir.http'].session_info()

1
Avatar
Descartar
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
Controller giving 404 Error
controllers
Avatar
Avatar
Avatar
2
d’ag. 25
5101
Controller not working Solved
controllers
Avatar
Avatar
Avatar
2
de juny 25
3385
How to add simple logic inside methods of Odoo 16 website controller?
controllers
Avatar
Avatar
Avatar
3
de juny 24
5886
Domain for res.partner having which are tagged with users ? Solved
res.partner
Avatar
Avatar
2
d’oct. 23
7748
Restrict duplicate phone number creation in res_partner odoo 16
res.partner
Avatar
Avatar
Avatar
Avatar
3
de set. 23
4543
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 Svenska ภาษาไทย 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