Send OpenCell Invoices flow
Related with the Trello card: https://trello.com/c/8eMYA0eb
Requirements
Create a workflow to manage the send OpenCell invoices flow.
OpenCell has the endpoint /invoice/sendByEmail
to send the invoices to the customer by email.
We need to manage this flow from Tryton because the flow in the web client is not secure.
We need to create a workflow with different views for any state and actions to manage the transitions.
Design
OpenCell Invoice Workflow
graph LR;
pending[**Pending to Send**]-->enqueued(Enqueued to send);
errored(Send Error)-->pending[Pending to Send];
enqueued(Enqueued to send)-->errored(Send Error);
enqueued(Enqueued to send)-->sent((Sent));
States
- Pending to send - To be sent.
- Enqueued to send - Enqueued to be processed by the background workers.
- Sent - Sent OK.
- Send Error - Error in the sending process returned by the OC API.
Transitions
- Pending to Send --> Enqueued to send - Run the Send action.
- Send Error --> Pending to Send - Fix the problems in OC and return the OpenCellInvoice to the pending state to be sent.
- Enqueued to send --> Send Error - The OC API returns an error.
- Enqueued to send --> Sent - Sent OK!
Workflow steps
- Generate the invoices in OpenCell.
- From Tryton we pull all the invoices to generate the AccountMoves. This step generates the instances of the OpenCellInvoices in Tryton to relate them with the AccountMoves origins.
- When all the invoices are in Tryton, go to Totel les Factures to show the OpenCell invoices, the invoices are in the tab
Pending
. - Select a group of invoices and run the action Send. This step enqueues the jobs to send the invoices one by one. Send the invoices means a call to Opencell API
invoice/sendByEmail
to send the invoices from OpenCell by mail to the customer. - Ones the job finish, if the result is OK, the invoices state change to
Sent
. If an error was returned, change the invoice status toSend Error
. - After all the invoice jobs finish, look at the tab
Send Error
. Check the error message and fix it in OpenCell. - After fixing the error, return to Tryton, select the invoice and return it to status
Pending
to start the process again.
QA steps
Edited by Daniel Palomar