Skip to Content
Menu
This question has been flagged
4 Replies
6799 Views

Hello,

i have my invoice policy set to 'delivered quantities'.

I am trying to find an automated solution to create a draft invoice after the delivery is 'done' without going manually to the sales order and click Create invoice.

I was trying to use the ODOO app Automated Actions to trigger the Invoice from the Delivery. But i did not find out how to did.

Anyone has an idea how to do it ? 

Thanks

Avatar
Discard
Author Best Answer

Hello, many thanks for your solution. I have paste the Python code as you proposed. 

res = (records.origin).startswith("S0")
if res:
sale_id = env['sale.order'].search([('name','=',records.origin)])
sale_id._create_invoices()

But when i save, i receive the following Validation error message : 

IndentationError : expected an indented block at line 3 sale_id = env['sale.order'].search([('name','=',records.origin)])

Also, I am not much familar with the Python code, but i see the first line startwith("SO"). Does it mean that my Sales Order have to start with SO ? Our sales order come from different source and not all Sales Order start with 'SO". For example : Imported Sales order from an US Shopify website starts with "US", EU Shopify starts with "EU", etc. 

Many thanks

Avatar
Discard
Best Answer

Do u solve it yet?  Trying to automated invoice for Month end too. 

Avatar
Discard
Author

Yes. solved.
With Automated Actions (Technical -> Automated Actions) (with debug mode on and Automated actions module installed)

Model: Transfer
Trigger: On Update
Before Update Domain:
- Status is not 'done'
- Sales Order is Set
- Type of Operations = "outgoing"

Apply On:
- Sales Order is set
- Status = done
- Type of Operation = "outgoing"

Action to do : Execute Python code

Code used :
sale_ids = records.mapped('sale_id')
invoice_ids = []
for sale_id in sale_ids.filtered(lambda x: x.invoice_status == 'to invoice'):
invoice_ids.append(sale_id._create_invoices())
if invoice_ids:
log('Invoice created with id: %s' % ', '.join([str(i.id) for i in invoice_ids if i]), level='info')

Thank you, you are amazing!

Best Answer

In Odoo, you can create an invoice automatically after a delivery transfer is done by creating a new module and overriding the _action_done method of the stock.picking model.


Here is an example of how you can create an invoice automatically after a delivery transfer is done:


Create a new module, for example stock_invoice_auto.


In the models folder of your module, create a new file called stock.py and add the following code:


Copy code

from odoo import api, fields, models


class StockPicking(models.Model):

    _inherit = 'stock.picking'


    def _action_done(self):

        res = super(StockPicking, self)._action_done()

        for picking in self:

            if picking.picking_type_id.code == 'outgoing':

                invoice_id = self.env['account.move'].create({

                    'type': 'out_invoice',

                    'partner_id': picking.partner_id.id,

                    'invoice_line_ids': [

                        (0, 0, {

                            'product_id': move.product_id.id,

                            'name': move.product_id.name,

                            'quantity': move.product_uom_qty,

                            'price_unit': move.product_id.lst_price,

                            'account_id': move.product_id.categ_id.property_account_income_categ_id.id,

                        })

                        for move in picking.move_lines

                    ],

                })

                invoice_id.post()

        return res

Add the dependencies in the manifest.py file of your module

Copy code

    'depends': ['base','sale','stock'],

Update the module list and install the stock_invoice_auto module.


Once the installation is done, you can test it by creating a delivery order, and confirm it, you should see the invoice created automatically.


Please note that the above code is an example, you might need to adapt it to your specific requirements

Avatar
Discard
Best Answer

Hello Dan Witting,

You Can Create Draft Invoice using Automated Action.


Find Example in comment.

Steps -
1) Confirm Sale Order.
2) Validate the quantity.
3) When the state changes from Ready to Done State, then your invoice will be generated.

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

For Example -

- Create an Automated action by adding name, model (Transfer as per your requirement), trigger (update as per your requirement), trigger fields(Status), Before Update domain (Status = "assigned"), filter domain (Status = "done") and Action to do ( Execute Python Code as per your requirement )

- In the Python Code Below Paste this code:-
res = (records.origin).startswith("S0")
if res:
sale_id = env['sale.order'].search([('name','=',records.origin)])
sale_id._create_invoices()

Author

Hello, many thanks for your solution. I have paste the Python code as you proposed.

res = (records.origin).startswith("S0")
if res:
sale_id = env['sale.order'].search([('name','=',records.origin)])
sale_id._create_invoices()

But when i save, i receive the following Validation error message :

IndentationError : expected an indented block at line 3 sale_id = env['sale.order'].search([('name','=',records.origin)])

Also, I am not much familar with the Python code, but i see the first line startwith("SO"). Does it mean that my Sales Order have to start with SO ? Our sales order come from different source and not all Sales Order start with 'SO". For example : Imported Sales order from an US Shopify website starts with "US", EU Shopify starts with "EU", etc.

Many thanks

Related Posts Replies Views Activity
1
Aug 24
1082
0
Nov 17
3643
3
Mar 15
8486
0
Mar 15
5452
0
Jun 18
2637