[IMP] sale: split invoicing method for cleaner overrides
closes odoo/odoo#31529 Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
committed by
Stéphane Bidoul (ACSONE)
parent
5a18c8e71b
commit
389bd53a0b
+32
-25
@@ -506,6 +506,37 @@ class SaleOrder(models.Model):
|
||||
action = {'type': 'ir.actions.act_window_close'}
|
||||
return action
|
||||
|
||||
def _finalize_invoices(self, invoices, references):
|
||||
"""
|
||||
Invoked after creating invoices at the end of action_invoice_create.
|
||||
:param invoices: {group_key: invoice}
|
||||
:param references: {invoice: order}
|
||||
"""
|
||||
for invoice in invoices.values():
|
||||
invoice.compute_taxes()
|
||||
if not invoice.invoice_line_ids:
|
||||
raise UserError(_(
|
||||
'There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
|
||||
# If invoice is negative, do a refund invoice instead
|
||||
if invoice.amount_total < 0:
|
||||
invoice.type = 'out_refund'
|
||||
for line in invoice.invoice_line_ids:
|
||||
line.quantity = -line.quantity
|
||||
# Use additional field helper function (for account extensions)
|
||||
for line in invoice.invoice_line_ids:
|
||||
line._set_additional_fields(invoice)
|
||||
# Necessary to force computation of taxes. In account_invoice, they are triggered
|
||||
# by onchanges, which are not triggered when doing a create.
|
||||
invoice.compute_taxes()
|
||||
# Idem for partner
|
||||
so_payment_term_id = invoice.payment_term_id.id
|
||||
invoice._onchange_partner_id()
|
||||
# To keep the payment terms set on the SO
|
||||
invoice.payment_term_id = so_payment_term_id
|
||||
invoice.message_post_with_view('mail.message_origin_link',
|
||||
values={'self': invoice, 'origin': references[invoice]},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
|
||||
@api.multi
|
||||
def action_invoice_create(self, grouped=False, final=False):
|
||||
"""
|
||||
@@ -587,31 +618,7 @@ class SaleOrder(models.Model):
|
||||
if not invoices:
|
||||
raise UserError(_('There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
|
||||
|
||||
for invoice in invoices.values():
|
||||
invoice.compute_taxes()
|
||||
if not invoice.invoice_line_ids:
|
||||
raise UserError(_('There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
|
||||
# If invoice is negative, do a refund invoice instead
|
||||
if invoice.amount_total < 0:
|
||||
invoice.type = 'out_refund'
|
||||
for line in invoice.invoice_line_ids:
|
||||
line.quantity = -line.quantity
|
||||
# Use additional field helper function (for account extensions)
|
||||
for line in invoice.invoice_line_ids:
|
||||
line._set_additional_fields(invoice)
|
||||
# Necessary to force computation of taxes. In account_invoice, they are triggered
|
||||
# by onchanges, which are not triggered when doing a create.
|
||||
invoice.compute_taxes()
|
||||
# Idem for partner
|
||||
so_payment_term_id = invoice.payment_term_id.id
|
||||
fp_invoice = invoice.fiscal_position_id
|
||||
invoice._onchange_partner_id()
|
||||
invoice.fiscal_position_id = fp_invoice
|
||||
# To keep the payment terms set on the SO
|
||||
invoice.payment_term_id = so_payment_term_id
|
||||
invoice.message_post_with_view('mail.message_origin_link',
|
||||
values={'self': invoice, 'origin': references[invoice]},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
self._finalize_invoices(invoices, references)
|
||||
return [inv.id for inv in invoices.values()]
|
||||
|
||||
@api.multi
|
||||
|
||||
Reference in New Issue
Block a user