Add missing queries from discuss.tryton.org and upgrade configuration models from ir_property
This commit is contained in:
parent
d379c4449d
commit
4cdf1aba79
|
@ -0,0 +1,71 @@
|
|||
#!/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.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
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, 0, context=context):
|
||||
user_obj = pool.get('res.user')
|
||||
user = user_obj.search([('login', '=', 'admin')], limit=1)[0]
|
||||
user_id = user.id
|
||||
|
||||
with Transaction().start(dbname, 0, context=context):
|
||||
Company = pool.get('company.company')
|
||||
Model = pool.get('ir.model')
|
||||
Field = pool.get('ir.model.field')
|
||||
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
models = Model.search([
|
||||
('model', 'like', '%_configuration'),
|
||||
])
|
||||
for company in Company.search([]):
|
||||
with Transaction().set_context(company=company.id):
|
||||
print "Company ID %s" % company.id
|
||||
for model in models:
|
||||
ToSave = pool.get(model.model)
|
||||
toSave = ToSave(1)
|
||||
for field in Field.search([('model', '=', model)]):
|
||||
if field.name in ['id', 'create_uid', 'create_date', 'write_uid', 'write_date']:
|
||||
continue
|
||||
query = 'select * from ir_property where field = %s and company = %s;' % (field.id, company.id)
|
||||
cursor.execute(query)
|
||||
results = cursor.fetchone()
|
||||
if results:
|
||||
value = results[5]
|
||||
if field.ttype in ['many2many', 'one2many']:
|
||||
continue
|
||||
elif field.ttype == 'many2one':
|
||||
model, _id = value.split(',')
|
||||
ValueModel = pool.get(model)
|
||||
valueModel = ValueModel(_id)
|
||||
setattr(toSave, field.name, valueModel)
|
||||
else:
|
||||
if value.startswith(','):
|
||||
setattr(toSave, field.name, value.split(',')[1])
|
||||
else:
|
||||
setattr(toSave, field.name, value)
|
||||
toSave.save()
|
||||
Transaction().commit()
|
||||
|
||||
logger.info('Done')
|
26
config.yml
26
config.yml
|
@ -236,10 +236,6 @@ before:
|
|||
version: 4.7
|
||||
query: delete from ir_property where res is null;
|
||||
|
||||
- comment: #
|
||||
tables: ir_lang
|
||||
query: ALTER TABLE ir_lang ADD parent varchar;
|
||||
|
||||
# - comment: # drop ir properties in case account_asset is installed
|
||||
# version: 4.4
|
||||
# script: TODO https://bugs.tryton.org/issue6395
|
||||
|
@ -288,6 +284,11 @@ before:
|
|||
# tables: ir_module_module
|
||||
# query: UPDATE ir_model_data set fs_id = fs_id || (select CASE WHEN state = 'installed' THEN '_pyme' ELSE '_normal' END FROM ir_module_module where name = 'account_es_pyme') where module = 'aeat_340' and fs_id like 'aeat_340_template_type_%';
|
||||
|
||||
- comment: # Add exceptional parent language (must be run before update
|
||||
version: 4.8
|
||||
tables: ir_lang
|
||||
query: ALTER TABLE ir_lang ADD parent varchar;
|
||||
|
||||
- comment: # delete register with type 'jasper' on core modules
|
||||
version: 4.8
|
||||
query: delete from ir_translation where module in ('account_invoice', 'sale', 'stock', 'purchase') and type = 'jasper';
|
||||
|
@ -354,9 +355,22 @@ after:
|
|||
tables: electronic_mail_template
|
||||
query: update ir_translation set value = regexp_replace(value, 'record.code', 'record.number', 'g') where res_id in (select id from electronic_mail_template where model in (select id from ir_model where model in ('account.invoice', 'sale.sale', 'purchase.purchase', 'stock.shipment.in', 'stock.shipment.out', 'stock.shipment.in'))) and name like 'electronic.mail.template,%';
|
||||
|
||||
- comment: # After property migration old model data should be cleared:
|
||||
version: 4.4
|
||||
query: DELETE FROM ir_model_data WHERE model = 'ir.property';
|
||||
|
||||
- comment: # drop purchase invoice line rel
|
||||
version: 4.4
|
||||
query: DROP TABLE if exists purchase_invoice_line_rel;
|
||||
|
||||
- comment: # Update address formats
|
||||
version: 4.4
|
||||
query: UPDATE party_address_format SET format_ = REPLACE(format_, '${district}', '${subdivision}');
|
||||
|
||||
- comment: # Relation between purchase and invoice_lines must be deleted
|
||||
version: 4.4
|
||||
query: DROP TABLE purchase_invoice_line_rel;
|
||||
|
||||
- comment: # delete duplicated party configuration sequence
|
||||
version: 4.4
|
||||
query: DELETE FROM party_configuration_party_sequence where id = 2;
|
||||
|
@ -370,6 +384,10 @@ after:
|
|||
version: 4.7
|
||||
query: update ir_action_report set template_extension = 'jrxml' where report like '%jrxml';
|
||||
|
||||
- comment: # upgrade configuration models from ir_property
|
||||
version: 4.8
|
||||
script: ./upgrades/after/migration_properties.py
|
||||
|
||||
# - script: ./upgrades/after/update_taxes.py
|
||||
|
||||
# - comment: # delete ir properties
|
||||
|
|
Loading…
Reference in New Issue