summaryrefslogtreecommitdiff
path: root/addons/purchase/migrations
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/purchase/migrations
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/purchase/migrations')
-rw-r--r--addons/purchase/migrations/9.0.1.2/pre-create-properties.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/addons/purchase/migrations/9.0.1.2/pre-create-properties.py b/addons/purchase/migrations/9.0.1.2/pre-create-properties.py
new file mode 100644
index 00000000..e9d3b060
--- /dev/null
+++ b/addons/purchase/migrations/9.0.1.2/pre-create-properties.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+
+def convert_field(cr, model, field, target_model):
+ table = model.replace('.', '_')
+
+ cr.execute("""SELECT 1
+ FROM information_schema.columns
+ WHERE table_name = %s
+ AND column_name = %s
+ """, (table, field))
+ if not cr.fetchone():
+ return
+
+ cr.execute("SELECT id FROM ir_model_fields WHERE model=%s AND name=%s", (model, field))
+ [fields_id] = cr.fetchone()
+
+ cr.execute("""
+ INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference)
+ SELECT %(field)s, 'many2one', %(fields_id)s, company_id, CONCAT('{model},', id),
+ CONCAT('{target_model},', {field})
+ FROM {table} t
+ WHERE {field} IS NOT NULL
+ AND NOT EXISTS(SELECT 1
+ FROM ir_property
+ WHERE fields_id=%(fields_id)s
+ AND company_id=t.company_id
+ AND res_id=CONCAT('{model},', t.id))
+ """.format(**locals()), locals())
+
+ cr.execute('ALTER TABLE "{0}" DROP COLUMN "{1}" CASCADE'.format(table, field))
+
+def migrate(cr, version):
+ convert_field(cr, 'res.partner', 'property_purchase_currency_id', 'res.currency')
+ convert_field(cr, 'product.template',
+ 'property_account_creditor_price_difference', 'account.account')