[FIX] product_contract: set 'Contract template' field company depend

This commit is contained in:
Ernesto Tejeda
2020-02-11 12:27:33 -05:00
committed by Pedro M. Baeza
parent 93663d99c8
commit 500461396b
7 changed files with 105 additions and 33 deletions

View File

@@ -0,0 +1,36 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
# Convert contract_template_id field of the product_template table
# to a company dependent field
model_name = "product.template"
model_table_name = "product_template"
origin_field_name = "contract_template_id"
destination_field_name = "property_contract_template_id"
# Add ir.model.fields entry
env.cr.execute(
"SELECT id FROM ir_model WHERE model = %s", (model_name, ),
)
model_id = env.cr.fetchone()[0]
openupgrade.logged_query(
env.cr, """
INSERT INTO ir_model_fields (
model_id, model, name, field_description, ttype, state, relation
) VALUES (
%s, %s, %s, %s, %s, %s, %s
)""",
(model_id, model_name, destination_field_name, 'OU', "many2one",
'base', 'contract.template'),
)
openupgrade.convert_to_company_dependent(
env,
model_name,
origin_field_name,
destination_field_name,
model_table_name,
)