Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Sample code for Applying payment to Invoice via XML-RPC (PHP) ?

Naroči se

Get notified when there's activity on this post

This question has been flagged
paymentapiaccount.invoice
2 Odgovori
19816 Prikazi
Avatar
Antoni

I am using PHP to communicate with the XML-RPC API. I have been able to successfully create and validate an invoice but I am running into a problem applying a payment to an invoice.

Does anyone know how this can be done through the API? Or have a code sample I could reference?

Thanks

Here is the code I am using. It doesnt show the actual xml-rpc calls but it shows the fields. This is using a custom handler I wrote.

echo "LOGIN<BR /><BR />";
$conn = new openerp_client($user, $password, $dbname, $server_url);

//search for company in partner model to get id
echo "SEARCH<br /><br />";
$data = array(
    0 => array('field' => 'name', 'operator' => '=', 'value' => 'Antoni\'s Company 2', 'type' => 'string')
);
$conn->search('res.partner', $data);

$partner_id = $conn->response['last_record_id'][0];

//search for company in res.comapny model to get id
echo "SEARCH<br /><br />";
$data = array(
    0 => array('field' => 'name', 'operator' => '=', 'value' => 'Antoni\'s Company 2', 'type' => 'string')
);
$conn->search('res.company', $data);

$company_id = $conn->response['last_record_id'][0];

//create the invoice
echo "INVOICE<BR /><BR />";

$data = array(
    0 => array('field' => 'partner_id', 'value' => $partner_id, 'type' => 'int'),
    1 => array('field' => 'date_invoice', 'value' => date('Y-m-d'), 'type' => 'string'),
    2 => array('field' => 'date_due', 'value' => date('Y-m-d'), 'type' => 'string'),
    3 => array('field' => 'account_id', 'value' => 40, 'type' => 'int'),
    4 => array('field' => 'journal_id', 'value' => 11, 'type' => 'int'),
    6 => array('field' => 'company_id', 'value' => $company_id, 'type' => 'int'),
    7 => array('field' => 'period_id', 'value' => 4, 'type' => 'int')
);

$conn->put('account.invoice', 'create', $data);
$invoice_id = $conn->response['last_record_id'];

//create the invoice lines
echo "CREATE INVOICE LINES<BR /><BR />";
$data = array(
    0 => array('field' => 'invoice_id', 'value' => $invoice_id, 'type' => 'int'),
    1 => array('field' => 'product_id', 'value' => 49, 'type' => 'int'),
    2 => array('field' => 'name', 'value' => '[ADPT] USB Adapter', 'type' => 'string'),
    3 => array('field' => 'price_unit', 'value' => 18.0, 'type' => 'double'),
    4 => array('field' => 'quantity', 'value' => 2.0, 'type' => 'double'),
    5 => array('field' => 'account_id', 'value' => 51, 'type' => 'int')
);

$conn->put('account.invoice.line', 'create', $data);

//validate the invoice
echo "VALIDATE<BR /><BR />";
$conn->workflow('account.invoice', 'invoice_open', $invoice_id);

//get move_id from invoice
echo "SEARCH INVOICE<BR /><BR />";
$data = array(
    0 => array('field' =>'id', 'operator' => '=', 'value' => $invoice_id, 'type' => 'int')
);
$conn->search('account.invoice', $data);

echo "GET INVOICE<BR /><BR />";
$fields = array();
$conn->get('account.invoice', $fields);

echo $move_id = $conn->response['last_record_id'][0]['move_id']->me['array'][0]->me['int'];

//create voucher
echo "Create<br /><br />";

$data = array(
    0 => array('field' => 'partner_id', 'value' => 166, 'type' => 'int'),
    1 => array('field' => 'company_id', 'value' => 1, 'type' => 'int'),
    2 => array('field' => 'type', 'value' => 'receipt', 'type' => 'string'),
    3 => array('field' => 'account_id', 'value' => 57, 'type' => 'int'),
    4 => array('field' => 'period_id', 'value' => 5, 'type' => 'int'),
    5 => array('field' => 'journal_id', 'value' => 17, 'type' => 'int'),
    6 => array('field' => 'amount', 'value' => 12.0, 'type' => 'double'),
    7 => array('field' => 'move_id', 'value' => $move_id, 'type' => 'int'),
    8 => array('field' => 'currency_id', 'value' => 1, 'type' => 'int'),
    9 => array('field' => 'date', 'value' => date('Y-m-d'), 'type' => 'string')
);
$conn->put('account.voucher', 'create', $data);
$voucher_id = $conn->response['last_record_id'];

//get move_line_id
$data = array(
    0 => array('field' => 'move_id', 'operator' => '=', 'value' => $move_id, 'type' => 'int'),
    1 => array('field' => 'name', 'operator' => '=', 'value' => '/', 'type' => 'string')
);
$conn->search('account.move.line', $data);

$fields = array();
$conn->get('account.move.line', $fields);

$move_line_id = $conn->response['last_record_id'][0]['id']->me['int'];

$invoice_name = $conn->response['last_record_id'][0]['invoice']->me['array'][1]->me['string'];

//create voucher line
echo "Create Voucher Line<br /><br />";
$data = array(
    0 => array('field' => 'partner_id', 'value' => 166, 'type' => 'int'),
    1 => array('field' => 'company_id', 'value' => 1, 'type' => 'int'),
    2 => array('field' => 'voucher_id', 'value' => $voucher_id, 'type' => 'int'),
    3 => array('field' => 'amount', 'value' => 12.0, 'type' => 'double'),
    4 => array('field' => 'type', 'value' => 'cr', 'type' => 'string'),
    5 => array('field' => 'name', 'value' => $invoice_name, 'type' => 'string'),
    6 => array('field' => 'account_id', 'value' => 40, 'type' => 'int'),
    7 => array('field' => 'move_line_id', 'value' => $move_line_id, 'type' => 'int')
);

$conn->put('account.voucher.line','create',$data);

//Post voucher
echo "Post Voucher<BR /><BR />";
$conn->workflow('account.voucher', 'proforma_voucher', $voucher_id);
0
Avatar
Opusti
Avatar
Francesco OpenCode
Best Answer

If you want, you can use my script hosted in github: https://github.com/OpenCode/openerp-php-connector

If you read index.php page you can find examples for alla the feature. You must use create to create an invoice and call_function to validate it.

1
Avatar
Opusti
Antoni
Avtor

Hi Francesco, Thanks for replying. I have already figured out how to create and invoice and validate one. I am looking to make payments to an invoice and reconcile and invoice. Would you happen to have any code samples on that? Thanks.

Francesco OpenCode

A solution is to study the openerp workflow for the invoice and call the some functions with PHP

Antoni
Avtor

I tried that as well. I did the following: created an invoice, added lines to the invoice, validated the invoice. Then created a voucher with the move_id related to the invoice got the move_line_id related to the invoice/lines. But the payment does not show up in the invoice and the voucher cannot be posted. So I am still missing something. I update the question with the code I have already. It uses a class I wrote but will give you an idea of the fields I am using. Thanks for your help.

Avatar
Nicholas Linn
Best Answer

I haven't had a chance to try it but I dug this up earlier and bookmarked it:

http://forum.openerp.com/forum/topic32306.html

Hope it helps.

0
Avatar
Opusti
Jason Judge

This link is now dead. I've put the essence of the link content into this gist: https://gist.github.com/judgej/38d5bcba3c8f5e3f6fa5

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Apply payment to invoice via API
payment api account.invoice
Avatar
0
mar. 15
4578
Odoo API invoice
invoice payment api
Avatar
0
nov. 24
2114
POS Payment method: Partner debit/credit
pos payment api
Avatar
Avatar
1
mar. 17
12312
Register Payment Amount Changes
payment account.invoice register
Avatar
1
mar. 15
5796
Vendor bills payments using an bank API
payment api bank vendorbill
Avatar
Avatar
2
apr. 25
1554
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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