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
    • Validations
    • 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
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • 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
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et 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
    Browse all 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
    • Devenez partenaire
    • Services for Partners
    • 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

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
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

Webhooks - Create a lead

S'inscrire

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

Cette question a été signalée
webhookwebhooks
1 Répondre
4796 Vues
Avatar
Wombat

Now I am trying to create a lead via a webhook. In Automations Rules, I have selected the 

Model: "Lead/Opportunity"

Trigger: "On Webhook"

Target Record: "model.browse(int(payload.get('id')))"  I don't know what relevance that has to creating a new record...but anyway.. 

-------------

The execute code is:

try:

    data = request.get_json_data()

except:

data = str(request.get_http_params())


name = data['name']

phone = data['phone']

email = data['email']


env['crm.lead'].create({

    'name': name,

    'user_id': 2,

    'phone': phone,

    'email_from': email,

    'type': "opportunity"

})

-------------

The xml from postman is

{ "id": "1", "name": "fred", "phone": "04400440040", "email": "jon@example.com"}


Postman report a "500 Internal Server Error"

-------------

From the logs:

2024-07-11 08:47:41,214 715 WARNING cal odoo.addons.base_automation.models.base_automation: Webhook #1 failed with error:

Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5851, in ensure_one

    _id, = self._ids

ValueError: not enough values to unpack (expected 1, got 0)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/tools/safe_eval.py", line 390, in safe_eval

    return unsafe_eval(c, globals_dict, locals_dict)

  File "ir.actions.server(487,)", line 10, in

  File "", line 2, in create

  File "/opt/odoosrc/17.0/odoo/odoo/api.py", line 414, in _model_create_multi

    return create(self, [arg])

  File "/opt/odoosrc/17.0/odoo/addons/crm_iap_enrich/models/crm_lead.py", line 43, in create

    leads = super(Lead, self).create(vals_list)

  File "", line 2, in create

  File "/opt/odoosrc/17.0/odoo/odoo/api.py", line 415, in _model_create_multi

    return create(self, arg)

  File "/opt/odoosrc/17.0/odoo/addons/crm/models/crm_lead.py", line 761, in create

    leads = super(Lead, self).create(vals_list)

  File "", line 2, in create

  File "/opt/odoosrc/17.0/odoo/odoo/api.py", line 415, in _model_create_multi

    return create(self, arg)

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 285, in create

    thread.sudo().message_post(subtype_id=subtype.id, author_id=self.env.user.partner_id.id)

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 2136, in message_post

    if self.env.user._is_public() and guest:

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/res_users.py", line 1156, in _is_public

    self.ensure_one()

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5854, in ensure_one

    raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: res.users()


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/addons/base_automation/models/base_automation.py", line 509, in _execute_webhook

    return self._process(record)

  File "/opt/odoosrc/17.0/odoo/addons/base_automation/models/base_automation.py", line 671, in _process

    action.with_context(**ctx).run()

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/ir_actions.py", line 941, in run

    res = runner(run_self, eval_context=eval_context)

  File "/opt/odoosrc/17.0/odoo/addons/website/models/ir_actions_server.py", line 61, in _run_action_code_multi

    res = super(ServerAction, self)._run_action_code_multi(eval_context)

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/ir_actions.py", line 771, in _run_action_code_multi

    safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True, filename=str(self))  # nocopy allows to return 'action'

  File "/opt/odoosrc/17.0/odoo/odoo/tools/safe_eval.py", line 404, in safe_eval

    raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))

ValueError: : "Expected singleton: res.users()" while evaluating

'try:\n    data = request.get_json_data()\nexcept:\n\tdata = str(request.get_http_params())\n\nname = data[\'name\']\nphone = data[\'phone\']\nemail = data[\'email\']\n\nenv[\'crm.lead\'].create({\n    \'name\': name,\n    \'user_id\': 2,\n    \'phone\': phone,\n    \'email_from\': email,\n    \'type\': "opportunity"\n})'


2024-07-11 08:47:41,247 715 ERROR cal odoo.http: Exception during request handling. 

Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5851, in ensure_one

    _id, = self._ids

ValueError: not enough values to unpack (expected 1, got 0)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/http.py", line 2189, in __call__

    response = request._serve_db()

  File "/opt/odoosrc/17.0/odoo/odoo/http.py", line 1764, in _serve_db

    return service_model.retrying(self._serve_ir_http, self.env)

  File "/opt/odoosrc/17.0/odoo/odoo/service/model.py", line 135, in retrying

    env.cr.flush()  # submit the changes to the database

  File "/opt/odoosrc/17.0/odoo/odoo/sql_db.py", line 138, in flush

    self.precommit.run()

  File "/opt/odoosrc/17.0/odoo/odoo/tools/misc.py", line 1224, in run

    func()

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 530, in _track_finalize

    tracking = records.with_context(context)._message_track(fnames, initial_values)

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 636, in _message_track

    record.message_post(

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 2136, in message_post

    if self.env.user._is_public() and guest:

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/res_users.py", line 1156, in _is_public

    self.ensure_one()

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5854, in ensure_one

    raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: res.users()

2024-07-11 08:47:41,248 715 INFO cal werkzeug: 127.0.0.1 - - [11/Jul/2024 08:47:41] "POST /web/hook/90b41425-8632-405d-b9a3-2e3f4a21fb5c HTTP/1.1" 500 - 83 0.047 0.137

-------------

I don't understand the "singleton" error as there is only one record being created and one user id supplied and no lists or arrays.


0
Avatar
Ignorer
info@webdevelop.nl

Which fields do you need to map for a new opportunity?


Avatar
Niyas Raphy (Walnut Software Solutions)
Meilleure réponse

Hi,
See the method explained here: https://www.youtube.com/watch?v=D3urHJ9rB2o

Thanks 

0
Avatar
Ignorer
Wombat
Auteur

Perfect. Thank you Niyas.

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é
webhook GET support?
webhooks
Avatar
0
janv. 25
1503
Webhooks - request.get_http_params() Résolu
webhooks
Avatar
Avatar
1
juil. 24
2678
Webhooks NameError: name 'request' is not defined Résolu
webhook
Avatar
Avatar
Avatar
2
juil. 24
3699
Is a webhook the best way to send data to a URL outside Odoo?
webhook
Avatar
1
déc. 22
4190
Error 500 Webhooks
saas webhook
Avatar
Avatar
Avatar
2
août 24
2287
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
  • Devenez 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 ภาษาไทย 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