Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Intelligence artificielle
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Supermarché
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Homme à tout faire
    • Matériel informatique & support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Parcourir toutes les industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenir partenaire
    • Services pour partenaires
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Create a res.partner object from a controller

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
res.partnercontrollersController
1 Répondre
6375 Vues
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
Ignorer
Avatar
Blessings
Auteur Meilleure réponse

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
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Controller giving 404 Error
controllers
Avatar
Avatar
Avatar
2
août 25
5087
Controller not working Résolu
controllers
Avatar
Avatar
Avatar
2
juin 25
3378
How to add simple logic inside methods of Odoo 16 website controller?
controllers
Avatar
Avatar
Avatar
3
juin 24
5880
Domain for res.partner having which are tagged with users ? Résolu
res.partner
Avatar
Avatar
2
oct. 23
7745
Restrict duplicate phone number creation in res_partner odoo 16
res.partner
Avatar
Avatar
Avatar
Avatar
3
sept. 23
4540
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenir partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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