From bba1edb759d84000cfec3a9f7af4f0707c987622 Mon Sep 17 00:00:00 2001 From: francesc Date: Sat, 6 Aug 2022 12:07:04 +0200 Subject: [PATCH] Add check that invoices do not exist already before import. --- account.py | 16 ++++++++++++++++ message.xml | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/account.py b/account.py index 54647f1..634c5a3 100644 --- a/account.py +++ b/account.py @@ -107,6 +107,19 @@ def convert_account(account): else: return account +def find_factura(number, company): + pool = Pool() + Invoice = pool.get('account.invoice') + invoice, = Invoice.search([('number', '=', number), + ('company', '=', company)], limit=1) + return invoice + +def check_factura_not_exists(number, company): + if find_factura(number, company): + raise UserError( + gettext('account_import_contaplus.msg_factura_exists', + number=number)) + class Move(metaclass=PoolMeta): __name__ = 'account.move' @@ -339,6 +352,7 @@ class AccountImportContaplus(Wizard): invoice.sii_issued_key = '02' return invoice + def import_invoices(self, company, imp_record): pool = Pool() @@ -367,6 +381,8 @@ class AccountImportContaplus(Wizard): invoice_number = iline.serie + iline.factura if invoice_number not in to_create: # todo check num factura not alredy there. + check_factura_not_exists(invoice_number, company) + if invoice: # check factura # if lines empty remove from to_create diff --git a/message.xml b/message.xml index 4a492c8..8512134 100644 --- a/message.xml +++ b/message.xml @@ -24,5 +24,8 @@ Payment terms missing for %(party)s. - + + Invoice "%(number)s" already exists for this company. + +