Skip to Content
Menu
This question has been flagged

How do you create journal entries on an invoice from a sales order via Python? 

We have an eCommerce website and we're creating the Sales Order via the XML RPC API, without any issues. However, in order to create the invoice, I would like to use the following approach; 

- Create an automation in Odoo, which utilises a webhook as a trigger 
- In the webhook, we pass the order_id from the website (to a custom field in Odoo called x_ecom_order_id) 
- The webhook then executes python code, within which we find the Sales Order associated to the Order ID in the x_ecom_order_id custom field (this is already stored on the Sales Order) and then we call _create_invoices on the sale.order model 

All of the above works as expected and a draft invoice is correctly generated, with invoice details, including the product line items and a journal entry to recognise the revenue in Sales Account.

However, it does not automatically generate the VAT Output Credit and Accounts Receivable Debit, as per the behaviour if you manually create a draft invoice via the Odoo UI. 

Need some help and guidance on how we can automatically create the missing journal entires, prior to posting the invoice.

***********
For your reference, this is the pyhton that is executed, when we call the webhook;

# Retrieve the x_ecom_order_id from the payload

x_ecom_order_id = payload.get('x_ecom_order_id')


if x_ecom_order_id:

    sales_orders = env['sale.order'].search([('x_ecom_order_id', '=', x_ecom_order_id)], limit=1)


    if len(sales_orders) == 1:

        sales_order = sales_orders[0]


        if sales_order.invoice_status == 'to invoice':

            try:

                # Create invoices from the Sales Order

                invoice_ids = sales_order._create_invoices()

            except Exception as e:

                # Log or handle any exception during invoice creation

                pass

        else:

            # Log or handle the case where the Sales Order is not ready for invoicing

            pass

    else:

        # Log or handle the case where the Sales Order is not found or multiple are found

        pass

else:

    # Log or handle the case where x_ecom_order_id is not provided or invalid

    pass




Avatar
Discard

Hello,

Thank you for reaching out.

I'm currently on my yearly vacation, and won't be available to check or respond to emails. I'll attend to your message promptly upon my return on January 02nd, 2024.

 

Regards,

Debashish Roy

Disclaimer:Grant Thornton India is a member firm of Grant Thornton International Ltd (Grant Thornton International). References to Grant Thornton are to Grant Thornton International or its member firms. Grant Thornton International and the member firms are not a worldwide partnership. Services are delivered independently by the member firms.The information contained in this e-mail is private & confidential and may also be legally privileged. While the information contained in this document and any of its attachments is provided for the assistance of the recipient, the same should not be relied upon as a substitute for professional, technical or legal advice; unless it is sent after being duly signed by a partner of our firm in hardcopy. The contents of this mail and any of its attachments are subject to change without notice. If you are not the intended recipient of this mail, please notify us, preferably by e-mail; and do not read, copy or disclose the contents of this message to anyone. Whilst we have taken reasonable precautions to ensure that any attachment to this e-mail has been swept for viruses, e-mail communications cannot be guaranteed to be secure or error free, as information can be corrupted, intercepted, lost or contain viruses. We do not accept liability for such matter or their consequences.
Related Posts Replies Views Activity
3
May 24
1501
0
Nov 23
1179
2
Mar 24
2119
1
Feb 24
1904
1
Jun 23
1617