2018-03-19 16:41:26 +01:00
|
|
|
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
2016-06-14 17:22:17 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
import logging
|
2019-11-18 11:46:59 +01:00
|
|
|
|
2016-09-09 13:29:58 +02:00
|
|
|
from psycopg2.extensions import AsIs
|
2016-06-14 17:22:17 +02:00
|
|
|
|
2019-11-18 11:34:02 +01:00
|
|
|
from odoo.tools import column_exists
|
2016-06-14 17:22:17 +02:00
|
|
|
|
2019-11-18 11:34:02 +01:00
|
|
|
_logger = logging.getLogger(__name__)
|
2016-09-09 13:29:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def column_add_with_value(cr, table, column, field_type, value):
|
|
|
|
if not column_exists(cr, table, column):
|
2019-11-18 11:46:59 +01:00
|
|
|
cr.execute(
|
|
|
|
"""
|
2016-09-09 13:29:58 +02:00
|
|
|
ALTER TABLE %s
|
2019-11-18 11:46:59 +01:00
|
|
|
ADD COLUMN %s %s""",
|
|
|
|
(AsIs(table), AsIs(column), AsIs(field_type)),
|
|
|
|
)
|
|
|
|
cr.execute(
|
|
|
|
"""
|
|
|
|
UPDATE %s SET %s = %s""",
|
|
|
|
(AsIs(table), AsIs(column), value),
|
|
|
|
)
|
2016-09-09 13:29:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def pre_init_hook(cr):
|
2019-11-18 11:46:59 +01:00
|
|
|
_logger.info("Creating res.partner.tracking_emails_count column " "with value 0")
|
|
|
|
column_add_with_value(cr, "res_partner", "tracking_emails_count", "integer", 0)
|
|
|
|
_logger.info("Creating res.partner.email_score column " "with value 50.0")
|
|
|
|
column_add_with_value(cr, "res_partner", "email_score", "double precision", 50.0)
|