drop constraint bank_account_number_number_iban_exclude

issue11198
This commit is contained in:
Raimon Esteve 2022-12-07 12:13:45 +01:00 committed by GitHub
parent 1edc5c2b02
commit 78a885d986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -27,6 +27,7 @@ def register():
Pool.register(
bank.Bank,
bank.BankAccount,
bank.BankAccountNumber,
depends=['bank'],
module='party_company', type_='model')
Pool.register(

20
bank.py
View File

@ -3,6 +3,7 @@
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond import backend
from . import party
@ -32,6 +33,25 @@ class BankAccount(metaclass=PoolMeta):
def search_companies(cls, name, clause):
return [('bank.party.companies',) + tuple(clause[1:])]
class BankAccountNumber(metaclass=PoolMeta):
__name__ = 'bank.account.number'
@classmethod
def __register__(cls, module_name):
cursor = Transaction().connection.cursor()
# since issue11198 fill or create bank from IBAN and enforce uniqueness
# replace default sql_constrain (keep same name) that always return false
exist = backend.TableHandler.table_exist(cls._table)
if exist:
cursor.execute("ALTER TABLE bank_account_number DROP CONSTRAINT "
"IF EXISTS bank_account_number_number_iban_exclude")
cursor.execute("ALTER table bank_account_number add constraint "
"bank_account_number_number_iban_exclude check (type != 'x')")
super(BankAccountNumber, cls).__register__(module_name)
@classmethod
def get_owners_by_companies(cls, records, name):
PartyCompany = Pool().get('party.company.rel')