mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MOV] migration script to base_comment_template
This commit is contained in:
committed by
Pierre Verkest
parent
a4f010ed53
commit
2e692e79ea
57
base_comment_template/migrations/12.0.2.0.0/post-migrate.py
Normal file
57
base_comment_template/migrations/12.0.2.0.0/post-migrate.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
from odoo import tools
|
||||||
|
|
||||||
|
import logging
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def migrate(cr, version):
|
||||||
|
|
||||||
|
_logger.debug('Migrating res.partner comment_template_id')
|
||||||
|
|
||||||
|
if not tools.column_exists(cr, 'res_partner', 'comment_template_id'):
|
||||||
|
return
|
||||||
|
|
||||||
|
cr.execute("SELECT id FROM res_company")
|
||||||
|
company_ids = [d[0] for d in cr.fetchall()]
|
||||||
|
|
||||||
|
cr.execute(
|
||||||
|
"SELECT id FROM ir_model_fields WHERE model=%s AND name=%s",
|
||||||
|
('res.partner', 'property_comment_template_id'))
|
||||||
|
[field_id] = cr.fetchone()
|
||||||
|
|
||||||
|
for company_id in company_ids:
|
||||||
|
cr.execute("""
|
||||||
|
INSERT INTO ir_property(
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
fields_id,
|
||||||
|
company_id,
|
||||||
|
res_id,
|
||||||
|
value_reference
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
{field},
|
||||||
|
'many2one',
|
||||||
|
{field_id},
|
||||||
|
{company_id},
|
||||||
|
CONCAT('{model},',id),
|
||||||
|
CONCAT('{target_model},',{oldfield})
|
||||||
|
FROM {table} t
|
||||||
|
WHERE {oldfield} IS NOT NULL
|
||||||
|
AND (company_id IS NULL OR company_id = {company_id})
|
||||||
|
AND NOT EXISTS(
|
||||||
|
SELECT 1
|
||||||
|
FROM ir_property
|
||||||
|
WHERE fields_id={field_id}
|
||||||
|
AND company_id={company_id}
|
||||||
|
AND res_id=CONCAT('{model},',t.id)
|
||||||
|
)
|
||||||
|
""".format(
|
||||||
|
oldfield='comment_template_id',
|
||||||
|
field='property_comment_template_id',
|
||||||
|
field_id=field_id,
|
||||||
|
company_id=company_id,
|
||||||
|
model='res.partner',
|
||||||
|
target_model='base.comment.template',
|
||||||
|
table='res_partner',
|
||||||
|
))
|
||||||
Reference in New Issue
Block a user