Delete non line type before unlink invoice lines
issue3001
This commit is contained in:
+1
-1
@@ -49,6 +49,6 @@ class InvoiceLine:
|
||||
def delete(cls, lines):
|
||||
PurchaseLine = Pool().get('purchase.line')
|
||||
if any(l for l in lines
|
||||
if isinstance(l.origin, PurchaseLine)):
|
||||
if isinstance(l.origin, PurchaseLine) and l.type == 'line'):
|
||||
cls.raise_user_error('delete_purchase_invoice_line')
|
||||
super(InvoiceLine, cls).delete(lines)
|
||||
|
||||
+5
-2
@@ -36,15 +36,18 @@ class Purchase:
|
||||
invoice = super(Purchase, self).create_invoice(invoice_type)
|
||||
|
||||
if invoice:
|
||||
invoice_line_ids = [l.id for l in invoice.lines]
|
||||
lines_to_delete = [l for l in invoice.lines if l.type != 'line']
|
||||
lines = [l for l in invoice.lines if l.type == 'line']
|
||||
invoice_line_ids = [l.id for l in lines]
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
InvoiceLine.write(invoice.lines, {
|
||||
InvoiceLine.write(lines, {
|
||||
'invoice': None,
|
||||
'invoice_type': invoice.type,
|
||||
'party': invoice.party.id,
|
||||
'currency': invoice.currency.id,
|
||||
'company': invoice.company.id,
|
||||
})
|
||||
InvoiceLine.delete(lines_to_delete)
|
||||
self.write([self], {
|
||||
'invoices': [('unlink', [invoice.id])],
|
||||
'invoice_lines': [('add', invoice_line_ids)],
|
||||
|
||||
@@ -179,6 +179,10 @@ Purchase 5 products::
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 4.0
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.type = 'subtotal'
|
||||
>>> purchase_line.description = 'Subtotal'
|
||||
>>> purchase.save()
|
||||
>>> Purchase.quote([purchase.id], current_config.context)
|
||||
>>> Purchase.confirm([purchase.id], current_config.context)
|
||||
|
||||
Reference in New Issue
Block a user