2018-10-16 23:30:19 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
dbname = sys.argv[1]
|
|
|
|
config_file = sys.argv[2]
|
2018-10-17 07:44:39 +02:00
|
|
|
digits = sys.argv[3] if len(sys.argv) == 4 else 6
|
2018-10-16 23:30:19 +02:00
|
|
|
from trytond.config import config as CONFIG
|
|
|
|
CONFIG.update_etc(config_file)
|
|
|
|
|
|
|
|
from trytond.transaction import Transaction
|
|
|
|
from trytond.pool import Pool
|
|
|
|
import trytond.tools as tools
|
|
|
|
import logging
|
|
|
|
|
|
|
|
Pool.start()
|
|
|
|
pool = Pool(dbname)
|
|
|
|
pool.init()
|
|
|
|
|
|
|
|
context = {}
|
|
|
|
|
|
|
|
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')
|
|
|
|
Configuration = pool.get('account.configuration')
|
|
|
|
Account = pool.get('account.account')
|
|
|
|
AccountTemplate = pool.get('account.account.template')
|
2018-11-19 14:50:49 +01:00
|
|
|
Party = pool.get('party.party')
|
|
|
|
|
2018-12-17 14:18:04 +01:00
|
|
|
party = Party.search([('name', '=', 'Generic for Party required Accounts')])
|
2018-11-19 14:50:49 +01:00
|
|
|
if not party:
|
2018-12-17 14:18:04 +01:00
|
|
|
party = Party(name='Generic for Party required Accounts')
|
2018-11-19 14:50:49 +01:00
|
|
|
party.save()
|
|
|
|
else:
|
|
|
|
party, = party
|
|
|
|
|
|
|
|
cursor = Transaction().connection.cursor()
|
|
|
|
cursor.execute(''' update account_move_line set party=%s where id in (
|
|
|
|
select l.id from account_move_line l, account_account a where
|
|
|
|
l.account=a.id and a.party_required and l.party is null) ''' %
|
|
|
|
party.id)
|
2018-10-16 23:30:19 +02:00
|
|
|
|
|
|
|
UpdateChart = pool.get('account.update_chart', type='wizard')
|
|
|
|
|
2018-11-19 14:50:49 +01:00
|
|
|
Account.parent.left = None
|
|
|
|
Account.parent.right = None
|
|
|
|
|
|
|
|
for company in Company.search([('parent', '!=', None)]):
|
|
|
|
print "company", company.id
|
2018-10-16 23:30:19 +02:00
|
|
|
with Transaction().set_context(company=company.id):
|
2018-11-19 14:50:49 +01:00
|
|
|
|
2018-10-16 23:30:19 +02:00
|
|
|
template = AccountTemplate(ModelData.get_id('account_es', 'pgc_0'))
|
|
|
|
account, = Account.search([('template', '=', template)], limit=1)
|
|
|
|
config = Configuration(1)
|
|
|
|
|
2018-10-17 07:44:39 +02:00
|
|
|
if not config.default_account_code_digits:
|
|
|
|
config.default_account_code_digits = digits
|
|
|
|
config.force_digits = True
|
|
|
|
config.save()
|
|
|
|
|
2018-10-16 23:30:19 +02:00
|
|
|
session_id, _, _ = UpdateChart.create()
|
|
|
|
update_chart = UpdateChart(session_id)
|
|
|
|
update_chart.start.account = account
|
|
|
|
update_chart.start.account_code_digits = config.default_account_code_digits
|
|
|
|
print(update_chart.start.account_code_digits)
|
|
|
|
logger.info('%s: Upgrading Account Chart' % (company.rec_name))
|
|
|
|
update_chart.transition_update()
|
|
|
|
logger.info('%s: End Account Chart' % (company.rec_name))
|
|
|
|
|
2018-11-19 14:50:49 +01:00
|
|
|
Transaction().commit()
|
|
|
|
|
|
|
|
Account.parent.left = 'left'
|
|
|
|
Account.parent.right = 'right'
|
|
|
|
|
|
|
|
for company in Company.search([]):
|
|
|
|
with Transaction().set_context(company=company.id):
|
|
|
|
Account._rebuild_tree('parent', None, 0)
|
2018-10-16 23:30:19 +02:00
|
|
|
|
|
|
|
logger.info('Done')
|