Add check that invoices do not exist already before import.

This commit is contained in:
francesc 2022-08-06 12:07:04 +02:00
parent 6458ea1b60
commit bba1edb759
2 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -24,5 +24,8 @@
<record model="ir.message" id="msg_missing_payment_term">
<field name="text">Payment terms missing for %(party)s.</field>
</record>
</data>
<record model="ir.message" id="msg_factura_exists">
<field name="text">Invoice "%(number)s" already exists for this company.</field>
</record>
</data>
</tryton>