Skip to content

Commit

Permalink
[FIX][12.0] forbid cancel or delete of invoice with self-invoice link…
Browse files Browse the repository at this point in the history
…ed with xml
  • Loading branch information
sergiocorato committed Feb 8, 2021
1 parent bf000bb commit 1872bfc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
16 changes: 15 additions & 1 deletion l10n_it_fatturapa_out_rc/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import models
from odoo import api, models, _
from odoo.exceptions import UserError


class Invoice(models.Model):
Expand All @@ -23,3 +24,16 @@ def generate_self_invoice(self):
})
]
return res

@api.multi
def action_invoice_draft(self):
super().action_invoice_draft()
for inv in self:
if not inv.env.context.get("rc_set_to_draft") and \
inv.rc_purchase_invoice_id.state in ['draft', 'cancel']:
raise UserError(_(
"Vendor invoice that has generated this self invoice isn't "
"validated. "
"Validate vendor invoice before."
))
return True
30 changes: 30 additions & 0 deletions l10n_it_fatturapa_out_rc/tests/test_e_invoice_out_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,33 @@ def test_intra_EU_customer(self):
invoice.compute_taxes()
invoice.action_invoice_open()
self.assertFalse(invoice.rc_self_invoice_id)

def test_intra_EU_draft(self):
self.set_sequence_journal_selfinvoice(15, '2020-12-01')
self.set_bill_sequence(25, '2020-12-01')
self.supplier_intraEU.property_payment_term_id = self.term_15_30.id
invoice = self.invoice_model.create({
'partner_id': self.supplier_intraEU.id,
'account_id': self.invoice_account,
'type': 'in_invoice',
'date_invoice': '2020-12-01',
'reference': 'EU-SUPPLIER-REF'
})

invoice_line_vals = {
'name': 'Invoice for sample product',
'account_id': self.invoice_line_account,
'invoice_id': invoice.id,
'product_id': self.sample_product.id,
'price_unit': 100,
'invoice_line_tax_ids': [(4, self.tax_22ai.id, 0)]}
invoice_line = self.invoice_line_model.create(invoice_line_vals)
invoice_line.onchange_invoice_line_tax_id()
invoice.compute_taxes()
invoice.action_invoice_open()
self.assertEqual(invoice.rc_self_invoice_id.state, 'paid')
invoice.journal_id.update_posted = True
invoice.action_invoice_cancel()
self.assertEqual(invoice.rc_self_invoice_id.state, 'cancel')
with self.assertRaises(UserError):
invoice.rc_self_invoice_id.action_invoice_draft()
7 changes: 4 additions & 3 deletions l10n_it_reverse_charge/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ def action_cancel(self):

@api.multi
def action_invoice_draft(self):
super(AccountInvoice, self).action_invoice_draft()
invoice_model = self.env['account.invoice']
for inv in self:
new_self = self.with_context(rc_set_to_draft=True)
super(AccountInvoice, new_self).action_invoice_draft()
invoice_model = new_self.env['account.invoice']
for inv in new_self:
if inv.rc_self_invoice_id:
self_invoice = invoice_model.browse(
inv.rc_self_invoice_id.id)
Expand Down

0 comments on commit 1872bfc

Please sign in to comment.