Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

Custom PHP Code. Opportunity not created when automating sending data via web page (Lead is created)

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
developmentcrm
1680 Ansichten
Avatar
Matheus Okazaki

Hello, I am creating an automation so that I can fill in the name, opportunity, value, email and phone number through an external page. When I click on register, the system should automatically send this data to Odoo, create the Lead and automatically convert the lead into an opportunity. But it is not working, it creates the lead, but the opportunity is never created. My code is this:


<?php

require_once("verifica_login.php");


if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    

    ACCESS INFORM


    $nome_cliente     = $_POST['nome_cliente'];

    $nome_negociacao  = $_POST['nome_negociacao'];

    $valor_previsto   = floatval($_POST['valor_previsto']);

    $email            = $_POST['email'];

    $telefone         = $_POST['telefone'];


    // === Autenticação ===

    $common_request = xmlrpc_encode_request("authenticate", [$db, $username, $password, []]);

    $context = stream_context_create(['http' => [

        'method'  => "POST",

        'header'  => "Content-Type: text/xml",

        'content' => $common_request

    ]]);

    $response = file_get_contents("$url/xmlrpc/2/common", false, $context);

    $uid = xmlrpc_decode($response);

    if (!$uid) {

        die("❌ Falha na autenticação com o Odoo.");

    }


    $object_url = "$url/xmlrpc/2/object";


    // === Buscar cliente existente pelo e-mail ===

    $params = [$db, $uid, $password, 'res.partner', 'search_read', [[['email', '=', $email]]], ['fields' => ['id'], 'limit' => 1]];

    $request = xmlrpc_encode_request("execute_kw", $params);

    $context['http']['content'] = $request;

    $response = file_get_contents($object_url, false, $context);

    $partner_data = xmlrpc_decode($response);

    $partner_id = $partner_data[0]['id'] ?? false;


    // === Buscar time de vendas ===

    $params = [$db, $uid, $password, 'crm.team', 'search_read', [[]], ['fields' => ['id'], 'limit' => 1]];

    $request = xmlrpc_encode_request("execute_kw", $params);

    $context['http']['content'] = $request;

    $response = file_get_contents($object_url, false, $context);

    $team_data = xmlrpc_decode($response);

    $team_id = $team_data[0]['id'] ?? null;

    if (!$team_id) {

        die("❌ Nenhum time de vendas encontrado.");

    }


    // === Buscar usuário "Matheus Okazaki" ===

    $params = [$db, $uid, $password, 'res.users', 'search_read', [[['name', '=', 'Matheus Okazaki']]], ['fields' => ['id'], 'limit' => 1]];

    $request = xmlrpc_encode_request("execute_kw", $params);

    $context['http']['content'] = $request;

    $response = file_get_contents($object_url, false, $context);

    $user_data = xmlrpc_decode($response);

    $user_id = $user_data[0]['id'] ?? $uid;


    // === Buscar estágio "Lead Novo" ===

    $params = [$db, $uid, $password, 'crm.stage', 'search_read', [[['name', '=', 'Lead Novo']]], ['fields' => ['id'], 'limit' => 1]];

    $request = xmlrpc_encode_request("execute_kw", $params);

    $context['http']['content'] = $request;

    $response = file_get_contents($object_url, false, $context);

    $stage_data = xmlrpc_decode($response);

    $stage_id = $stage_data[0]['id'] ?? null;

    if (!$stage_id) {

        die("❌ Etapa 'Lead Novo' não encontrada.");

    }


    // === Criar oportunidade diretamente ===

    $opportunity_data = [

        'type' => 'opportunity',

        'name' => $nome_negociacao,

        'contact_name' => $nome_cliente,

        'email_from' => $email,

        'phone' => $telefone,

        'expected_revenue' => $valor_previsto,

        'team_id' => $team_id,

        'user_id' => $user_id,

        'priority' => '2',

        'stage_id' => $stage_id,

        'partner_id' => $partner_id

    ];


    $params = [$db, $uid, $password, 'crm.lead', 'create', [$opportunity_data]];

    $request = xmlrpc_encode_request("execute_kw", $params);

    $context['http']['content'] = $request;

    $response = file_get_contents($object_url, false, $context);

    $opportunity_id = xmlrpc_decode($response);


    if (!is_int($opportunity_id)) {

        echo "<p style='color:red;'> Erro ao criar a oportunidade:</p><pre>";

        print_r($opportunity_id);

        echo "</pre>";

        exit;

    }


    echo "<p style='color:green;'> Oportunidade criada com sucesso! ID: $opportunity_id</p>";


    // === Adicionar nota na oportunidade ===

    $params = [$db, $uid, $password, 'crm.lead', 'message_post', [

        $opportunity_id,

        [

            'body' => 'Nova oportunidade criada',

            'message_type' => 'comment',

        ]

    ]];

    $request = xmlrpc_encode_request("execute_kw", $params);

    $context['http']['content'] = $request;

    file_get_contents($object_url, false, $context);

}

?>


<!-- Formulário HTML -->

<!DOCTYPE html>

<html lang="pt-br">

<head>

    <meta charset="UTF-8">

    <title>Cadastrar Oportunidade no Odoo CRM</title>

</head>

<body>

    <h2>Cadastro de Nova Oportunidade</h2>

    <form method="POST" action="">

        <label>Nome do Cliente:</label><br>

        <input type="text" name="nome_cliente" required><br><br>


        <label>Nome da Negociação:</label><br>

        <input type="text" name="nome_negociacao" required><br><br>


        <label>Valor Previsto (R$):</label><br>

        <input type="number" step="0.01" name="valor_previsto" required><br><br>


        <label>Email:</label><br>

        <input type="email" name="email" required><br><br>


        <label>Telefone:</label><br>

        <input type="text" name="telefone" required><br><br>


        <button type="submit">Cadastrar</button>

    </form>

</body>

</html>


any idea what it's wrong? what should I do exactly? ​ ​


0
Avatar
Verwerfen
Christoph Farnleitner

You should probably try to trim your source down to what is actually relevant to the question and format it so it can be read... You mean to say that
$params = [$db, $uid, $password, 'crm.lead', 'create', [$opportunity_data]];
does not create an crm.lead of type 'opportunity' but of type 'lead'?

Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
How does Odoo manage lost leads? Gelöst
development crm
Avatar
Avatar
Avatar
Avatar
3
Sept. 25
958
Insert Spreadsheet button dissapeared
development crm spreadsheets
Avatar
0
Apr. 22
2864
How to control "lead to opportunity convertion"?
development crm v7
Avatar
0
Juni 20
7197
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
Nov. 25
289
MrpBom _skip_bom_line skips line of product that has two multi-choice attribute values when both are selected in Apply to variant
development
Avatar
Avatar
1
Nov. 25
211
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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