Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

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

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
developmentcrm
1701 Visualizzazioni
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
Abbandona
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'?

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
How does Odoo manage lost leads? Risolto
development crm
Avatar
Avatar
Avatar
Avatar
3
set 25
969
Insert Spreadsheet button dissapeared
development crm spreadsheets
Avatar
0
apr 22
2878
How to control "lead to opportunity convertion"?
development crm v7
Avatar
0
giu 20
7215
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
nov 25
329
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
267
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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