From e7bc5cfcff19dc811eafc90ba36f391b53e05486 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Wed, 18 Jan 2017 10:19:36 +0100 Subject: [PATCH] Reprocess purchase when deleting invoice lines issue6131 review34571002 --- invoice.py | 13 +++++++++++++ tests/scenario_purchase.rst | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/invoice.py b/invoice.py index 004783b24e..13f1b13fe1 100644 --- a/invoice.py +++ b/invoice.py @@ -151,3 +151,16 @@ class InvoiceLine: models = super(InvoiceLine, cls)._get_origin() models.append('purchase.line') return models + + @classmethod + def delete(cls, lines): + pool = Pool() + Purchase = pool.get('purchase.purchase') + with Transaction().set_context(_check_access=False): + lines = cls.browse(lines) + invoices = (l.invoice for l in lines + if l.type == 'line' and l.invoice) + purchases = [p for i in invoices for p in i.purchases] + super(InvoiceLine, cls).delete(lines) + with Transaction().set_context(_check_access=False): + Purchase.process(purchases) diff --git a/tests/scenario_purchase.rst b/tests/scenario_purchase.rst index 33195ba2c2..699f9085f7 100644 --- a/tests/scenario_purchase.rst +++ b/tests/scenario_purchase.rst @@ -573,3 +573,26 @@ linked to invoices:: 5.0 >>> stock_move.state u'done' + +Deleting a line from a invoice should recreate it:: + + >>> purchase = Purchase() + >>> purchase.party = customer + >>> line = purchase.lines.new() + >>> line.product = product + >>> line.quantity = 10.0 + >>> purchase.click('quote') + >>> purchase.click('confirm') + >>> purchase.click('process') + >>> invoice, = purchase.invoices + >>> config.user = account_user.id + >>> invoice_line, = invoice.lines + >>> invoice.lines.remove(invoice_line) + >>> invoice.invoice_date = today + >>> invoice.click('post') + >>> config.user = purchase_user.id + >>> purchase.reload() + >>> new_invoice, = purchase.invoices + >>> new_invoice.number + >>> len(new_invoice.lines) + 1