Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
developmentcrm
1686 Zobrazenia
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šiť
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!

Registrácia
Related Posts Replies Zobrazenia Aktivita
How does Odoo manage lost leads? Solved
development crm
Avatar
Avatar
Avatar
Avatar
3
sep 25
958
Insert Spreadsheet button dissapeared
development crm spreadsheets
Avatar
0
apr 22
2869
How to control "lead to opportunity convertion"?
development crm v7
Avatar
0
jún 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
213
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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