Skip to Content
Menu
This question has been flagged
1 Odpoveď
253 Zobrazenia

Dear all, 

I'm trying to send an invoice to the invoicee via the External API. (using this package: Ang3 php-odoo-api-client) 

How can I know which Models / Methods / Fields to use in order to send this mail, with the invoice? 

I'm trying to find out via various ways: checking the External API docs, searching through the Odoo forum, searching online (tutorials, ..). 
The External API docs don't help. 
Couldn't find a relevant / recent Odoo forum post
Online tutorials, via YouTube videos are mostly done by non native-english speaking people so hard to follow. 

I've found several things about using the wizard programmatically in order to send the mail. 
First composing the message (via the wizard?) and then sending it via an additional API call? 

I'd like to find out for versions 17, 18 and 19. 

Looking for a push in the right direction

Thanking you in advance. 


Avatar
Zrušiť
Autor

@Ray Carnes: Thank you for your reply.
I'm adding this comment to my post, instead of your answer, because for some reason it's not allowing me to.

I'm trying to check the request-logs via Chrome's developer bar, to see which requests are being done.
That gives me some clarity, but not all the way. For example, I don't see where / how requests are getting their input from. I can guess based on other API requests that are done, but this way of working will cost me hours if not days to completely find out how to do it.

I have an implementation (made in 2022) in our codebase that works for Odoo version 17. I'm not sure if I can keep this for version 18 with some small changes here and there? When I compare what I see in my codebase (for version 17) it does have quite a lot of differences with what I see in the request logs (when connected to a trial (v19) environment).

For what it's worth, here's the (PHP) implementation that I have for v17:

$invoice = $this->accountMoveRepository->find($this->invoice->external_id);
if (! $invoice) {
throw UnableToSendInvoiceException::invoiceDeleted();
}

try {
// Ensure invoice is posted.
$this->accountMoveRepository->update($this->invoice->external_id, ['state' => 'posted']);

$actionSendAndPrint = $this->odoo->api()->call('account.move', 'action_send_and_print', [(int)($this->invoice->external_id)]);
if (empty($actionSendAndPrint['context']['default_template_id'])) {
// This exception is being thrown when connected to Odoo v18
throw UnableToSendInvoiceException::unknownDefaultTemplateId();
}

$response = $this->odoo->api()->call(
'account.invoice.send',
OrmQuery::CREATE,
[
[
'invoice_ids' => [(int)$this->invoice->external_id],
'composition_mode' => 'comment',
'template_id' => $actionSendAndPrint['context']['default_template_id'],
'is_email' => true,
],
],
[
'context' => [
'active_ids' => [(int)$this->invoice->external_id],
'active_id' => (int)$this->invoice->external_id,
'active_model' => 'account.move',
],
]
);

$this->odoo->api()->call(
'account.invoice.send',
'onchange_is_email',
[(int)($response)],
[
'context' => [
'active_ids' => [(int)$this->invoice->external_id],
'active_id' => (int)$this->invoice->external_id,
'active_model' => 'account.move',
],
]
);

$this->odoo->api()->call('account.invoice.send', 'send_and_print_action', [(int)($response)]);
} catch (RemoteException $e) {
throw OdooUserApiException::fromRequestException($e);
}

Best Answer

The easiest and fastest way is to review the Odoo logs (setup to surface the API calls) via either your Odoo.sh staging branch, or your own on premise Odoo installation.

See https://www.odoo.com/forum/help-1/how-can-i-see-which-api-calls-are-made-to-learn-what-odoo-is-doing-at-specific-times-183911

You do what you want to do via code via the UI, and monitor what API calls the web client makes at each step.

Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
2
jan 19
4628
1
aug 25
987
1
aug 25
1227
2
júl 25
3979
3
júl 25
1289