From c45538ed1774f6b5c484828efae7caf177cd0383 Mon Sep 17 00:00:00 2001 From: cubells Date: Thu, 17 Aug 2017 20:17:22 +0200 Subject: [PATCH] [IMP][ADD] account_credit_control: add migration script from account_followup --- account_credit_control/__openerp__.py | 2 +- .../migrations/9.0.1.0.0/post-migration.py | 46 +++++++++++++++++++ .../migrations/9.0.1.0.0/pre-migrate.py | 16 +++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 account_credit_control/migrations/9.0.1.0.0/post-migration.py create mode 100644 account_credit_control/migrations/9.0.1.0.0/pre-migrate.py diff --git a/account_credit_control/__openerp__.py b/account_credit_control/__openerp__.py index 1bb40c2f7..dec7c6713 100644 --- a/account_credit_control/__openerp__.py +++ b/account_credit_control/__openerp__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Account Credit Control', - 'version': '9.0.0.1.0', + 'version': '9.0.1.0.0', 'author': "Camptocamp, " "Tecnativa, " "Odoo Community Association (OCA)", diff --git a/account_credit_control/migrations/9.0.1.0.0/post-migration.py b/account_credit_control/migrations/9.0.1.0.0/post-migration.py new file mode 100644 index 000000000..459426d52 --- /dev/null +++ b/account_credit_control/migrations/9.0.1.0.0/post-migration.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +def migrate_followup_data(env): + env.cr.execute( + """SELECT aff.id, rc.name, aff.company_id + FROM account_followup_followup aff, res_company rc + WHERE aff.company_id = rc.id + """ + ) + followup_count = env.cr.fetchall() + for followup in followup_count: + policy = env['credit.control.policy'].create({ + 'name': followup[1], + 'company_id': followup[2], + }) + env.cr.execute( + """SELECT * FROM account_followup_followup_line + WHERE followup_id = %s""", + (followup[0], ), + ) + lines = env.cr.dictfetchall() + for line in lines: + env['credit.control.policy.level'].create({ + 'name': line['name'], + 'policy_id': policy.id, + 'level': line['sequence'], + 'computation_mode': 'net_days', + 'delay_days': line['delay'], + 'email_template_id': env.ref( + 'account_credit_control.email_template_credit_control_base' + ), + 'channel': 'email' if line['send_email'] else 'letter', + 'custom_text': line['description'], + 'custom_mail_text': line['description'], + }) + + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + if openupgrade.table_exists(env.cr, 'account_followup_followup'): + migrate_followup_data(env) diff --git a/account_credit_control/migrations/9.0.1.0.0/pre-migrate.py b/account_credit_control/migrations/9.0.1.0.0/pre-migrate.py new file mode 100644 index 000000000..252955486 --- /dev/null +++ b/account_credit_control/migrations/9.0.1.0.0/pre-migrate.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + if not openupgrade.table_exists(env.cr, 'account_followup_followup'): + # This is not coming from account_followup migration + return + # Remove no update rules that no longer applies + env.ref('account_credit_control.account_followup_comp_rule').unlink() + env.ref( + 'account_credit_control.account_followup_stat_by_partner_comp_rule' + ).unlink()