From dd493cd6c42e261549070012819cdfd7e9009f25 Mon Sep 17 00:00:00 2001 From: "Laurent Stukkens (LTU)" Date: Wed, 17 Nov 2021 10:38:15 +0000 Subject: [PATCH] [IMP] sales: add _create_invoices hook in sale.advance.payment.inv Prior to this commit it was not possible to get a hook from sale.advance.payment.inv in order to get the created invoices. The create_invoices def returns either an action or an ir.actions.act_window_close The introduction of the _create_invoices def will allow to get the created invoices from the wizzard. task-2608812 Closes: #79926 --- addons/sale/wizard/sale_make_invoice_advance.py | 14 +++++++++----- .../wizard/sale_make_invoice_advance.py | 14 +++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index 590a1080f21..a8e1ff3c58b 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -151,11 +151,9 @@ class SaleAdvancePaymentInv(models.TransientModel): del context return so_values - def create_invoices(self): - sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', [])) - + def _create_invoices(self, sale_orders): if self.advance_payment_method == 'delivered': - sale_orders._create_invoices(final=self.deduct_down_payments) + return sale_orders._create_invoices(final=self.deduct_down_payments) else: # Create deposit product if necessary if not self.product_id: @@ -164,6 +162,7 @@ class SaleAdvancePaymentInv(models.TransientModel): self.env['ir.config_parameter'].sudo().set_param('sale.default_deposit_product_id', self.product_id.id) sale_line_obj = self.env['sale.order.line'] + invoices = self.env['account.move'] for order in sale_orders: amount, name = self._get_advance_details(order) @@ -179,7 +178,12 @@ class SaleAdvancePaymentInv(models.TransientModel): so_line_values = self._prepare_so_line(order, analytic_tag_ids, tax_ids, amount) so_line = sale_line_obj.create(so_line_values) - self._create_invoice(order, so_line, amount) + invoices += self._create_invoice(order, so_line, amount) + return invoices + + def create_invoices(self): + sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', [])) + self._create_invoices(sale_orders) if self._context.get('open_invoices', False): return sale_orders.action_view_invoice() return {'type': 'ir.actions.act_window_close'} diff --git a/addons/sale_timesheet/wizard/sale_make_invoice_advance.py b/addons/sale_timesheet/wizard/sale_make_invoice_advance.py index 24faf0b34c1..1ae467651e2 100644 --- a/addons/sale_timesheet/wizard/sale_make_invoice_advance.py +++ b/addons/sale_timesheet/wizard/sale_make_invoice_advance.py @@ -24,7 +24,7 @@ class SaleAdvancePaymentInv(models.TransientModel): help="Only timesheets not yet invoiced (and validated, if applicable) from this period will be invoiced. If the period is not indicated, all timesheets not yet invoiced (and validated, if applicable) will be invoiced without distinction.") invoicing_timesheet_enabled = fields.Boolean(default=_default_invoicing_timesheet_enabled) - def create_invoices(self): + def _create_invoices(self, sale_orders): """ Override method from sale/wizard/sale_make_invoice_advance.py When the user want to invoice the timesheets to the SO @@ -32,18 +32,10 @@ class SaleAdvancePaymentInv(models.TransientModel): qty_to_invoice for each product_id in sale.order.line, before creating the invoice. """ - sale_orders = self.env['sale.order'].browse( - self._context.get('active_ids', []) - ) - if self.advance_payment_method == 'delivered' and self.invoicing_timesheet_enabled: if self.date_start_invoice_timesheet or self.date_end_invoice_timesheet: sale_orders.mapped('order_line')._recompute_qty_to_invoice(self.date_start_invoice_timesheet, self.date_end_invoice_timesheet) - sale_orders._create_invoices(final=self.deduct_down_payments, start_date=self.date_start_invoice_timesheet, end_date=self.date_end_invoice_timesheet) + return sale_orders._create_invoices(final=self.deduct_down_payments, start_date=self.date_start_invoice_timesheet, end_date=self.date_end_invoice_timesheet) - if self._context.get('open_invoices', False): - return sale_orders.action_view_invoice() - return {'type': 'ir.actions.act_window_close'} - - return super(SaleAdvancePaymentInv, self).create_invoices() + return super()._create_invoices(sale_orders)