Reprocess sale when deleting invoice lines

issue6131
review31821002
This commit is contained in:
Sergi Almacellas Abellana committed 2017-01-18 10:18:29 +01:00
1 parent 0cc67eaa6b
commit db2ba660c4
2 files changed
+35

No files matched your search

+13
View File
@@ -156,3 +156,16 @@ class InvoiceLine:
models = super(InvoiceLine, cls)._get_origin()
models.append('sale.line')
return models
@classmethod
def delete(cls, lines):
pool = Pool()
Sale = pool.get('sale.sale')
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)
sales = [s for i in invoices for s in i.sales]
super(InvoiceLine, cls).delete(lines)
with Transaction().set_context(_check_access=False):
Sale.process(sales)
+22
View File
@@ -697,3 +697,25 @@ invoices::
5.0
>>> stock_move.state
u'draft'
Deleting a line from a invoice should recreate it::
>>> sale = Sale()
>>> sale.party = customer
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 10.0
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.click('process')
>>> invoice, = sale.invoices
>>> config.user = account_user.id
>>> invoice_line, = invoice.lines
>>> invoice.lines.remove(invoice_line)
>>> invoice.click('post')
>>> config.user = sale_user.id
>>> sale.reload()
>>> new_invoice, = sale.invoices
>>> new_invoice.number
>>> len(new_invoice.lines)
1