Use invoice object when crediting an invoice

This commit is contained in:
Sergi Almacellas Abellana 2018-07-04 15:48:40 +02:00
parent 833f77ca33
commit c98ea77937
2 changed files with 17 additions and 4 deletions

View File

@ -160,12 +160,12 @@ class Invoice:
return result
def _credit(self):
res = super(Invoice, self)._credit()
credit = super(Invoice, self)._credit()
for field in _SII_INVOICE_KEYS:
res[field] = getattr(self, field)
setattr(credit, field, getattr(self, field))
res['sii_operation_key'] = 'R4'
return res
credit.sii_operation_key = 'R4'
return credit
def _set_sii_keys(self):
tax = self.taxes and self.taxes[0]

View File

@ -194,3 +194,16 @@ Create AEAT Report::
>>> report.click('load_invoices')
>>> len(report.lines)
2
Credit invoice with refund::
>>> credit = Wizard('account.invoice.credit', [invoice])
>>> credit.form.with_refund = True
>>> credit.execute('credit')
>>> invoice.reload()
>>> invoice.state
'paid'
>>> credit, = Invoice.find([('total_amount', '<', 0)])
>>> credit.sii_operation_key
'R1'