Browse Source

[FIX] base_comment_template: Make field truly company dependent

Previous field declaration was incorrect due to a typo, leading to non applying the
company dependent features.

Now everything is correct and the migration scripts care of moving data properly.
myc-14.0-py3o
Pedro M. Baeza 5 years ago
committed by Pierre Verkest
parent
commit
ff774d9bdf
  1. 57
      base_comment_template/migrations/12.0.2.0.0/post-migrate.py
  2. 13
      base_comment_template/migrations/12.0.3.0.0/post-migration.py
  3. 13
      base_comment_template/migrations/12.0.3.0.0/pre-migration.py

57
base_comment_template/migrations/12.0.2.0.0/post-migrate.py

@ -1,57 +0,0 @@
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',
))

13
base_comment_template/migrations/12.0.3.0.0/post-migration.py

@ -1,13 +0,0 @@
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
table = 'res_partner'
old_column = 'property_comment_template_id'
new_column = openupgrade.get_legacy_name(old_column)
if openupgrade.column_exists(cr, table, new_column):
openupgrade.convert_to_company_dependent(
env, 'res.partner', old_column, new_column, 'res.partner')

13
base_comment_template/migrations/12.0.3.0.0/pre-migration.py

@ -1,13 +0,0 @@
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
table = 'res_partner'
old_column = 'property_comment_template_id'
new_column = openupgrade.get_legacy_name(old_column)
if openupgrade.column_exists(cr, table, old_column):
openupgrade.rename_columns(cr, {table: [(old_column, new_column)]})
Loading…
Cancel
Save