[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
This commit is contained in:
Laurent Stukkens (LTU)
2022-01-03 18:11:00 +00:00
parent 09a6df204f
commit dd493cd6c4
2 changed files with 12 additions and 16 deletions
@@ -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'}
@@ -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)