Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
developmentcrm
1696 Zobrazení
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
Zrušit
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'?

Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
How does Odoo manage lost leads? Vyřešeno
development crm
Avatar
Avatar
Avatar
Avatar
3
zář 25
962
Insert Spreadsheet button dissapeared
development crm spreadsheets
Avatar
0
dub 22
2874
How to control "lead to opportunity convertion"?
development crm v7
Avatar
0
čvn 20
7209
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
lis 25
300
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
lis 25
231
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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