mirror of
https://github.com/NaN-tic/tryton-upgrades.git
synced 2023-12-14 03:32:55 +01:00
parent
9588ff6d18
commit
848f82116f
80
before/072070-bank-account.py
Executable file
80
before/072070-bank-account.py
Executable file
|
@ -0,0 +1,80 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
|
|
||||||
|
dbname = sys.argv[1]
|
||||||
|
config_file = sys.argv[2]
|
||||||
|
from trytond.config import config as CONFIG
|
||||||
|
CONFIG.update_etc(config_file)
|
||||||
|
|
||||||
|
from trytond.pool import Pool
|
||||||
|
from trytond.transaction import Transaction
|
||||||
|
import logging
|
||||||
|
from trytond import __version__
|
||||||
|
|
||||||
|
trytond_version = float('.'.join(__version__.split('.')[:2]))
|
||||||
|
|
||||||
|
Pool.start()
|
||||||
|
pool = Pool(dbname)
|
||||||
|
pool.init()
|
||||||
|
|
||||||
|
context = {'active_test': False}
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
ch = logging.StreamHandler(sys.stdout)
|
||||||
|
ch.setLevel(logging.DEBUG)
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
with Transaction().start(dbname, 1, context=context):
|
||||||
|
Company = pool.get('company.company')
|
||||||
|
ModelData = pool.get('ir.model.data')
|
||||||
|
Category = pool.get('product.category')
|
||||||
|
Template = pool.get('product.template')
|
||||||
|
Account = pool.get('account.account')
|
||||||
|
Tax = pool.get('account.tax')
|
||||||
|
|
||||||
|
Payment = pool.get('account.payment')
|
||||||
|
Line = pool.get('account.move.line')
|
||||||
|
SepaMandate = pool.get('account.payment.sepa.mandate')
|
||||||
|
|
||||||
|
BankNumber = pool.get('bank.account.number')
|
||||||
|
|
||||||
|
cursor = Transaction().connection.cursor()
|
||||||
|
|
||||||
|
# 1. drop _sql_constraints
|
||||||
|
# 2. bank_account-party_party data to party_party-bank_account-company table
|
||||||
|
query = "ALTER TABLE bank_account_number DROP CONSTRAINT IF EXISTS bank_account_number_number_iban_exclude"
|
||||||
|
cursor.execute(query)
|
||||||
|
query = "ALTER TABLE bank_account_number DROP CONSTRAINT IF EXISTS bank_account_number_account_iban_exclude"
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
# 1. move data to new
|
||||||
|
query = 'alter table "party_party-bank_account-company" ADD COLUMN IF NOT EXISTS payable_bank_account int';
|
||||||
|
query = 'alter table "party_party-bank_account-company" ADD COLUMN IF NOT EXISTS receivable_bank_account int';
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
query = 'select account, owner, company, payable_bank_account, receivable_bank_account from "bank_account-party_party"'
|
||||||
|
cursor.execute(query)
|
||||||
|
bank_rows = {}
|
||||||
|
for account_id, owner_id, company_id, is_payable_bank_account, is_receivable_bank_account in cursor.fetchall():
|
||||||
|
query2 = 'select id from "party_party-bank_account-company" where party = %s and company = %s' % (owner_id, company_id)
|
||||||
|
cursor.execute(query2)
|
||||||
|
|
||||||
|
has_id = None
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
has_id = row[0]
|
||||||
|
|
||||||
|
if has_id:
|
||||||
|
if is_payable_bank_account:
|
||||||
|
query = 'update "party_party-bank_account-company" set payable_bank_account = %s where id = %s' % (account_id, has_id);
|
||||||
|
cursor.execute(query)
|
||||||
|
if is_receivable_bank_account:
|
||||||
|
query = 'update "party_party-bank_account-company" set receivable_bank_account = %s where id = %s' % (account_id, has_id);
|
||||||
|
cursor.execute(query)
|
||||||
|
else:
|
||||||
|
query = 'insert into "party_party-bank_account-company" (party, company, payable_bank_account, receivable_bank_account) values (%s, %s, %s, %s)' % (owner_id, company_id, account_id if is_payable_bank_account else 'null', account_id if is_receivable_bank_account else 'null')
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
Transaction().commit()
|
|
@ -42,6 +42,32 @@ with Transaction().start(dbname, 1, context=context):
|
||||||
BankNumber = pool.get('bank.account.number')
|
BankNumber = pool.get('bank.account.number')
|
||||||
|
|
||||||
cursor = Transaction().connection.cursor()
|
cursor = Transaction().connection.cursor()
|
||||||
|
|
||||||
|
# 1. drop _sql_constraints
|
||||||
|
# 2. rename account2 to account in case before upgrade rename columns
|
||||||
|
# 3. rename number_compact2 to number_compact in case before upgrade rename columns
|
||||||
|
# 4. remove duplicated iban codes
|
||||||
|
query = "ALTER TABLE bank_account_number DROP CONSTRAINT IF EXISTS bank_account_number_number_iban_exclude"
|
||||||
|
cursor.execute(query)
|
||||||
|
query = "ALTER TABLE bank_account_number DROP CONSTRAINT IF EXISTS bank_account_number_account_iban_exclude"
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
query = "SELECT 1 FROM information_schema.columns WHERE table_name='bank_account_number' and column_name='number_compact2'"
|
||||||
|
cursor.execute(query)
|
||||||
|
if cursor.fetchone():
|
||||||
|
query = "alter table bank_account_number drop column number_compact"
|
||||||
|
cursor.execute(query)
|
||||||
|
query = "alter table bank_account_number rename number_compact2 to number_compact"
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
query = "SELECT 1 FROM information_schema.columns WHERE table_name='bank_account_number' and column_name='account2'"
|
||||||
|
cursor.execute(query)
|
||||||
|
if cursor.fetchone():
|
||||||
|
query = "alter table bank_account_number drop column account"
|
||||||
|
cursor.execute(query)
|
||||||
|
query = "alter table bank_account_number rename account2 to account"
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
query = "select number_compact, count(*) from bank_account_number where type = 'iban' group by number_compact HAVING count(*) > 1"
|
query = "select number_compact, count(*) from bank_account_number where type = 'iban' group by number_compact HAVING count(*) > 1"
|
||||||
|
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
12
config.yml
12
config.yml
|
@ -686,6 +686,13 @@ before:
|
||||||
query: delete from ir_translation where name = 'account.configuration,default_product_account_expense' and lang in ('ca', 'es');
|
query: delete from ir_translation where name = 'account.configuration,default_product_account_expense' and lang in ('ca', 'es');
|
||||||
delete from ir_translation where name = 'account.configuration,default_product_account_revenue' and lang in ('ca', 'es');
|
delete from ir_translation where name = 'account.configuration,default_product_account_revenue' and lang in ('ca', 'es');
|
||||||
|
|
||||||
|
- comment: company_bank with MultiValue - 072070
|
||||||
|
version: 6.4
|
||||||
|
tables: party_party-company_company
|
||||||
|
query: ALTER TABLE "party_party-company_company" RENAME TO "party_party-bank_account-company";ALTER TABLE "party_party-company_company_id_seq" RENAME TO "party_party-bank_account-company_id_seq";
|
||||||
|
ALTER TABLE "party_party-bank_account-company" RENAME COLUMN receivable_bank_account TO receivable_company_bank_account;
|
||||||
|
ALTER TABLE "party_party-bank_account-company" RENAME COLUMN payable_bank_account TO payable_company_bank_account;
|
||||||
|
|
||||||
- comment: Migration incoterm nantic to core
|
- comment: Migration incoterm nantic to core
|
||||||
version: 6.4
|
version: 6.4
|
||||||
tables: incoterm
|
tables: incoterm
|
||||||
|
@ -1024,5 +1031,10 @@ after:
|
||||||
version: 6.4
|
version: 6.4
|
||||||
query: delete from ir_export_line where name = 'currency_digits';
|
query: delete from ir_export_line where name = 'currency_digits';
|
||||||
|
|
||||||
|
- comment: company_bank with MultiValue - 072070
|
||||||
|
version: 6.4
|
||||||
|
tables: bank_account-party_party
|
||||||
|
script: ./upgrades/before/072070-bank-account.py
|
||||||
|
|
||||||
ignore:
|
ignore:
|
||||||
- WARNING trytond.backend.postgresql.table Unable to set column move_line of table analytic_account_line not null !
|
- WARNING trytond.backend.postgresql.table Unable to set column move_line of table analytic_account_line not null !
|
||||||
|
|
Loading…
Reference in a new issue