Make an invoice correction for credit note action
This is needed to keep the quantity invoiced coherent with the stock move quantity to update the unit price. issue9975 review353061002
This commit is contained in:
1 parent
73843c64fe
commit
9fd46306bf
3 files changed
+32
-20
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Make an invoice correction for credit note action
|
||||
* Compute amount of complaint action
|
||||
* Add active field to complaint type
|
||||
|
||||
|
||||
+21
-13
@@ -581,19 +581,27 @@ class Action(ModelSQL, ModelView):
|
||||
line2qty = {invoice_line: self.quantity}
|
||||
if self.unit_price is not None:
|
||||
line2price = {invoice_line: self.unit_price}
|
||||
credit_note = invoice._credit()
|
||||
credit_lines = []
|
||||
for invoice_line in invoice_lines:
|
||||
credit_line = invoice_line._credit()
|
||||
credit_lines.append(credit_line)
|
||||
credit_line.origin = self.complaint
|
||||
if invoice_line in line2qty:
|
||||
credit_line.quantity = -line2qty[invoice_line]
|
||||
if invoice_line in line2price:
|
||||
credit_line.unit_price = line2price[invoice_line]
|
||||
credit_note.lines = credit_lines
|
||||
credit_note.taxes = None
|
||||
credit_note.save()
|
||||
with Transaction().set_context(_account_invoice_correction=True):
|
||||
credit_note, = Invoice.copy([invoice], default={
|
||||
'lines': [],
|
||||
})
|
||||
# Copy each line one by one to get negative and positive lines
|
||||
# following each other
|
||||
for invoice_line in invoice_lines:
|
||||
qty = line2qty.get(invoice_line, invoice_line.quantity)
|
||||
unit_price = invoice_line.unit_price - line2price.get(
|
||||
invoice_line, invoice_line.unit_price)
|
||||
Line.copy([invoice_line], default={
|
||||
'invoice': credit_note.id,
|
||||
'quantity': -qty,
|
||||
'origin': str(self.complaint),
|
||||
})
|
||||
credit_line, = Line.copy([invoice_line], default={
|
||||
'invoice': credit_note.id,
|
||||
'quantity': qty,
|
||||
'unit_price': unit_price,
|
||||
'origin': str(self.complaint),
|
||||
})
|
||||
credit_note.update_taxes()
|
||||
else:
|
||||
return
|
||||
|
||||
@@ -216,9 +216,11 @@ Create a complaint to credit the invoice::
|
||||
>>> credit_note.type
|
||||
'out'
|
||||
>>> len(credit_note.lines)
|
||||
2
|
||||
4
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
-5.0
|
||||
0.0
|
||||
>>> credit_note.total_amount
|
||||
Decimal('-50.00')
|
||||
|
||||
Create a complaint to credit partially the invoice::
|
||||
|
||||
@@ -246,9 +248,9 @@ Create a complaint to credit partially the invoice::
|
||||
>>> credit_note.type
|
||||
'out'
|
||||
>>> len(credit_note.lines)
|
||||
2
|
||||
4
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
-2.0
|
||||
0.0
|
||||
>>> credit_note.total_amount
|
||||
Decimal('-15.00')
|
||||
|
||||
@@ -271,6 +273,7 @@ Create a complaint to credit a invoice line::
|
||||
>>> credit_note = action.result
|
||||
>>> credit_note.type
|
||||
'out'
|
||||
>>> credit_note_line, = credit_note.lines
|
||||
>>> credit_note_line.quantity
|
||||
-1.0
|
||||
>>> len(credit_note.lines)
|
||||
2
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
0.0
|
||||
Reference in new issue
Block a user