diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-05-30 15:06:15 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-05-30 15:06:15 +0700 |
| commit | acd06377bb5c4b375fadf3ad37a7ad5853ed79b3 (patch) | |
| tree | aef72c07173801e6836e5a8bc3ad87763dd9b0ad /fixco_custom/models/sale_order_multi_invoices.py | |
| parent | c7f63c374488c2f28dedc070308dadb5cfc1f9bd (diff) | |
push
Diffstat (limited to 'fixco_custom/models/sale_order_multi_invoices.py')
| -rw-r--r-- | fixco_custom/models/sale_order_multi_invoices.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/fixco_custom/models/sale_order_multi_invoices.py b/fixco_custom/models/sale_order_multi_invoices.py new file mode 100644 index 0000000..2638ddc --- /dev/null +++ b/fixco_custom/models/sale_order_multi_invoices.py @@ -0,0 +1,47 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import UserError + +class SaleOrderMultiInvoices(models.TransientModel): + _name = 'sale.order.multi_invoices' + _description = 'Create Invoices for Multiple Sales Orders' + + def create_invoices(self): + # Get SO IDs from context + so_ids = self._context.get('so_ids', []) + if not so_ids: + raise UserError(_("No sales orders selected!")) + + # Browse all selected sales orders + sale_orders = self.env['sale.order'].browse(so_ids) + created_invoices = self.env['account.move'] + + # Create one invoice per SO (even if partner is the same) + for order in sale_orders: + # Create invoice for this SO only + invoice = order.with_context(default_invoice_origin=order.name)._create_invoices(final=True) + created_invoices += invoice + + # Link the invoice to the SO + order.invoice_ids += invoice + + # Return action to view created invoices + if len(created_invoices) > 1: + action = { + 'name': _('Created Invoices'), + 'type': 'ir.actions.act_window', + 'res_model': 'account.move', + 'view_mode': 'tree,form', + 'domain': [('id', 'in', created_invoices.ids)], + } + elif created_invoices: + action = { + 'name': _('Created Invoice'), + 'type': 'ir.actions.act_window', + 'res_model': 'account.move', + 'view_mode': 'form', + 'res_id': created_invoices.id, + } + else: + action = {'type': 'ir.actions.act_window_close'} + + return action
\ No newline at end of file |
