diff --git a/CHANGELOG b/CHANGELOG index 8b5051e4be..0e97073da6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add _account_invoice_correction context keyword when copying for correction + Version 5.4.0 - 2019-11-04 * Bug fixes (see mercurial logs for details) diff --git a/invoice.py b/invoice.py index 479e2ebbf1..18a098ec5b 100644 --- a/invoice.py +++ b/invoice.py @@ -68,19 +68,20 @@ class InvoiceCorrect(Wizard): Line = pool.get('account.invoice.line') invoice = Invoice(Transaction().context['active_id']) - correction, = Invoice.copy([invoice], default={ - 'lines': [], - }) - # Copy each line one by one to get negative and positive lines - # following each other - for line in self.start.lines: - Line.copy([line], default={ - 'invoice': correction.id, - 'quantity': -line.quantity, - }) - Line.copy([line], default={ - 'invoice': correction.id, + with Transaction().set_context(_account_invoice_correction=True): + correction, = Invoice.copy([invoice], default={ + 'lines': [], }) + # Copy each line one by one to get negative and positive lines + # following each other + for line in self.start.lines: + Line.copy([line], default={ + 'invoice': correction.id, + 'quantity': -line.quantity, + }) + Line.copy([line], default={ + 'invoice': correction.id, + }) Invoice.update_taxes([correction]) data = {'res_id': [correction.id]} return action, data