コード例 #1
0
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    cr.execute("""
        SELECT id FROM account_journal
        WHERE code IN ('RCC', 'CPP')
    """)
    if cr.fetchall():
        openupgrade.add_xmlid(
            cr,
            'sponsorship_switzerland',
            'journal_raif',
            'account.journal',
            219,
            noupdate=True
        )
        openupgrade.add_xmlid(
            cr,
            'sponsorship_switzerland',
            'journal_post',
            'account.journal',
            212,
            noupdate=True
        )
コード例 #2
0
def migrate(env, version):
    group_type_codes = ['0001', '0002']
    group_type_obj = env['education.group_type']
    for group_code in group_type_codes:
        res = group_type_obj.search([('education_code', '=', group_code)])
        if res:
            openupgrade.add_xmlid(
                env.cr, 'hezkuntza',
                'education_group_type_{}'.format(group_code),
                'education.group_type', res.id, noupdate=False)
コード例 #3
0
def pre_init_hook(cr):
    cr.execute("""
        SELECT id
        FROM account_payment_method
        WHERE code = 'sepa.ch.dd' AND pain_version = 'pain.008.001.02.ch.03'
    """)
    res_id = cr.fetchone()
    if can_migrate and res_id:
        _logger.info("Associating module data with database record.")
        openupgrade.add_xmlid(cr, 'l10n_ch_pain_direct_debit',
                              'export_sepa_dd', 'account.payment.method',
                              res_id[0])
コード例 #4
0
def migrate(env, version):
    if not version:
        return

    # Associate records with xml data
    export_sepa_dd = env['account.payment.method'].search([
        ('code', '=', 'sepa.ch.dd'),
        ('pain_version', '=', 'pain.008.001.02.ch.03')
    ])
    if export_sepa_dd:
        openupgrade.add_xmlid(env.cr, 'l10n_ch_pain_direct_debit',
                              'export_sepa_dd', 'account.payment.method',
                              export_sepa_dd.id)
コード例 #5
0
def migrate(env, version):
    if not version:
        return

    # Associate already created toilets fund to new xml record
    toilets_fund = env["product.template"].search([("default_code", "=",
                                                    "toilet")])

    if toilets_fund:
        openupgrade.add_xmlid(
            env.cr,
            "sponsorship_switzerland",
            "product_template_fund_toilets",
            "product.template",
            toilets_fund.id,
        )
コード例 #6
0
def migrate(env, version):
    if not version:
        return

    # Attach flyer in post record
    env.cr.execute("""
        SELECT id FROM calendar_event_type
        WHERE name = 'flyer in post'
    """)
    res_id = env.cr.fetchone()[0]
    openupgrade.add_xmlid(env.cr,
                          'calendar_switzerland',
                          'calendar_event_flyer',
                          'calendar.event.type',
                          res_id,
                          noupdate=True)
コード例 #7
0
def migrate(env, installed_version):
    if not installed_version:
        return

    # Link existing communication rules to XML ids.
    rules_mapping = {
        "Notification Planned Exit": (
            "planned_exit_notification", "email_planned_exit_notification"),
    }
    module = "partner_communication_switzerland"
    for rule_name, rule_ids in rules_mapping.items():
        rule = env["partner.communication.config"].search([("name", "=", rule_name)])
        if not rule:
            continue
        openupgrade.add_xmlid(
            env.cr, module, rule_ids[0], "partner.communication.config", rule.id)
        openupgrade.add_xmlid(
            env.cr, module, rule_ids[1], "mail.template", rule.email_template_id.id)
コード例 #8
0
def pre_init_hook(cr):
    # Attach Prod mail templates to XML records
    env = api.Environment(cr, SUPERUSER_ID, {})
    comm_configs = env["partner.communication.config"].search([
        ("name", "ilike", "crowdfunding")
    ])
    for prod_config in comm_configs:
        _logger.info("Adding XMLID for Crowdfunding communication %s",
                     prod_config.name)
        xml_id = _xml_mapping.get(
            prod_config.name.replace("Crowdfunding - ", ""))
        if xml_id:
            openupgrade.add_xmlid(cr, "crowdfunding_compassion", xml_id[0],
                                  "partner.communication.job", prod_config.id)
            if prod_config.email_template_id:
                openupgrade.add_xmlid(cr, "crowdfunding_compassion", xml_id[1],
                                      "mail.template",
                                      prod_config.email_template_id.id)
コード例 #9
0
def migrate(env, installed_version):
    if not installed_version:
        return

    # Link existing communication rules to XML ids.
    rules_mapping = {
        "MyAccount - New User":
        ("myaccount_welcome_config", "myaccount_welcome_email"),
    }
    module = "mobile_app_switzerland"
    for rule_name, rule_ids in rules_mapping.items():
        rule = env["partner.communication.config"].search([("name", "=",
                                                            rule_name)])
        if not rule:
            continue
        openupgrade.add_xmlid(env.cr, module, rule_ids[0],
                              "partner.communication.config", rule.id)
        openupgrade.add_xmlid(env.cr, module, rule_ids[1], "mail.template",
                              rule.email_template_id.id)
コード例 #10
0
    def add_communication_record(config_name, template_name, config_xmlid,
                                 template_xmlid):
        """
        Map a communication record to a XML record.
        :param config_name: Name of the communication.config record.
        :param template_name: Name of the mail.template record.
        :param config_xmlid: XMLID of the communication.config record.
        :param template_xmlid: XMLID of the mail.template record.
        :return: Nothing
        """
        cr.execute(
            """
            SELECT c.id
            FROM partner_communication_config c
                JOIN utm_source s ON c.source_id = s.id
            WHERE s.name ILIKE %s
        """, ['%' + config_name + '%'])
        config_id = cr.fetchone()
        if config_id:
            openupgrade.add_xmlid(cr,
                                  module='partner_communication_switzerland',
                                  xmlid=config_xmlid,
                                  model='partner.communication.config',
                                  res_id=config_id[0],
                                  noupdate=True)

        cr.execute(
            """
            SELECT id
            FROM mail_template
            WHERE name ILIKE %s
        """, ['%' + template_name + '%'])
        template_id = cr.fetchone()
        if template_id:
            openupgrade.add_xmlid(cr,
                                  module='partner_communication_switzerland',
                                  xmlid=template_xmlid,
                                  model='mail.template',
                                  res_id=template_id[0],
                                  noupdate=True)
コード例 #11
0
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    cr.execute("""
        SELECT id FROM account_journal
        WHERE code IN ('RCC', 'CPP')
    """)
    if cr.fetchall():
        openupgrade.add_xmlid(cr,
                              'sponsorship_switzerland',
                              'journal_raif',
                              'account.journal',
                              219,
                              noupdate=True)
        openupgrade.add_xmlid(cr,
                              'sponsorship_switzerland',
                              'journal_post',
                              'account.journal',
                              212,
                              noupdate=True)
コード例 #12
0
def fix_country_state_xml_id_on_existing_records(cr):
    """Suppose you have country states introduced manually.
    This method ensure you don't have problems later in the migration when
    loading the res.country.state.csv"""
    with open(get_module_resource('base', 'data', 'res.country.state.csv'),
              'r') as country_states_file:
        states = csv.reader(country_states_file, delimiter=',', quotechar='"')
        _ = next(states)
        for row in states:
            state_xml_id, country_xml_id, _, state_code = row
            # find if csv record exists in ir_model_data
            cr.execute(
                """SELECT rcs.id, imd_rcs.id
                FROM res_country_state rcs
                INNER JOIN res_country rc ON rcs.country_id = rc.id
                INNER JOIN ir_model_data imd_rc ON (
                    imd_rc.res_id = rc.id AND
                    imd_rc.model = 'res.country' AND
                    imd_rc.module = 'base' AND
                    imd_rc.name = %(country_xml_id)s
                )
                LEFT JOIN ir_model_data imd_rcs ON (
                    imd_rcs.res_id = rcs.id AND
                    imd_rcs.model = 'res.country.state' AND
                    imd_rcs.module = 'base' AND
                    imd_rcs.name = %(state_xml_id)s
                )
                WHERE rcs.code = %(state_code)s""", {
                    "country_xml_id": country_xml_id,
                    "state_code": state_code,
                    "state_xml_id": state_xml_id,
                })
            row = cr.fetchone()
            if not row:  # non existing record - It will be created later
                continue
            if not row[1]:  # Unexisting XML-ID - Create it
                openupgrade.add_xmlid(cr, "base", state_xml_id,
                                      "res.country.state", row[0])
コード例 #13
0
def migrate(cr, version):
    if not version:
        return

    openupgrade.add_xmlid(cr, 'report_compassion',
                          'communication_style_mailing_bvr', 'ir.ui.view',
                          6928)
    openupgrade.add_xmlid(cr, 'report_compassion',
                          'partner_communication_document_mailing_bvr',
                          'ir.ui.view', 6927)
    openupgrade.add_xmlid(cr, 'report_compassion',
                          'partner_communication_mailing_bvr', 'ir.ui.view',
                          6926)
    openupgrade.add_xmlid(cr, 'report_compassion',
                          'report_partner_communication_mailing_bvr',
                          'ir.actions.report.xml', 1458)
コード例 #14
0
def migrate(cr, version):
    if not version:
        return

    cr.execute(
        """SELECT id FROM account_analytic_journal WHERE type='purchase' """)
    res = cr.fetchone()
    if res:
        openupgrade.add_xmlid(cr, 'account', 'exp', 'account.analytic.journal',
                              res[0], True)
    openupgrade.rename_columns(cr, column_renames)
    openupgrade.rename_tables(cr, tables_renames)
    # drop views that inhibit changing field types. They will be recreated
    # anyways
    for view in [
            'analytic_entries_report', 'account_entries_report',
            'report_invoice_created', 'report_aged_receivable'
    ]:
        cr.execute('drop view if exists %s cascade' % view)
    # Avoid inconsistencies between partner_id in account_invoice_line and
    # account invoice
    openupgrade.logged_query(
        cr, """
        UPDATE account_invoice_line ail
        SET partner_id=ai.partner_id
        FROM account_invoice ai
        WHERE
            ail.invoice_id = ai.id AND
            ail.partner_id != ai.partner_id;
        """)
    # delete a view from obsolete module account_report_company that causes
    # migration of the account module not to happen cleanly
    cr.execute("delete from ir_ui_view v "
               "using ir_model_data d where "
               "v.id=d.res_id and d.model='ir.ui.view' and "
               "d.name='account_report_company_invoice_report_tree_view'")
コード例 #15
0
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    cr.execute("""
        SELECT id FROM label_print
    """)
    if cr.fetchall():
        openupgrade.add_xmlid(
            cr,
            'partner_communication_switzerland',
            'label_print_sponsorship',
            'label.print',
            1,
            noupdate=True
        )
    cr.execute("""
            SELECT id FROM label_print_field
        """)
    if cr.fetchall():
        openupgrade.add_xmlid(
            cr,
            'partner_communication_switzerland',
            'label_print_field_ref',
            'label.print.field',
            1,
            noupdate=True
        )
        openupgrade.add_xmlid(
            cr,
            'partner_communication_switzerland',
            'label_print_field_sponsor_name',
            'label.print.field',
            2,
            noupdate=True
        )
        openupgrade.add_xmlid(
            cr,
            'partner_communication_switzerland',
            'label_print_field_child_name',
            'label.print.field',
            3,
            noupdate=True
        )
コード例 #16
0
def migrate(env, installed_version):
    if not installed_version:
        return

    # Link existing communication rules to XML ids.
    rules_mapping = {
        "Sponsorship Onboarding - Welcome and payment information":
        ("config_onboarding_sponsorship_confirmation",
         "mail_onboarding_sponsorship_confirmation"),
        "Sponsorship Onboarding Step 1 - Child Information and Zoom invitation":
        ("config_onboarding_step1", "mail_onboarding_step1"),
        "Sponsorship Onboarding Step 2 - Video and Country Information":
        ("config_onboarding_step2", "mail_onboarding_step2"),
        "Sponsorship Onboarding Step 3 - Poverty and Child protection":
        ("config_onboarding_step3", "mail_onboarding_step3"),
        "Sponsorship Onboarding Step 4 - Letter information":
        ("config_onboarding_step4", "mail_onboarding_step4"),
        "Sponsorship Onboarding Step 5 - Feedback & Engagement":
        ("config_onboarding_step5", "mail_onboarding_step5"),
        "Sponsorship Onboarding - Photo by post":
        ("config_onboarding_photo_by_post", "mail_onboarding_photo_by_post"),
        "Sponsorship Onboarding - Zoom Reminder":
        ("config_onboarding_zoom_reminder", "mail_onboarding_zoom_reminder"),
        "Sponsorship Onboarding - First B2S Letter":
        ("config_onboarding_first_letter", "mail_onboarding_first_letter"),
        "Sponsorship Transfer - New Dossier":
        ("new_dossier_transfer", "email_sponsorship_transfer_dossier"),
        "Sponsorship - SUB Accept": ("sponsorship_sub_accept",
                                     "email_sub_accept"),
    }
    module = "partner_communication_switzerland"
    for rule_name, rule_ids in rules_mapping.items():
        rule = env["partner.communication.config"].search([("name", "=",
                                                            rule_name)])
        if not rule:
            continue
        openupgrade.add_xmlid(env.cr, module, rule_ids[0],
                              "partner.communication.config", rule.id)
        openupgrade.add_xmlid(env.cr, module, rule_ids[1], "mail.template",
                              rule.email_template_id.id)
    # Remove old communications without deleting it from database (to keep history)
    env.cr.execute("""
        DELETE FROM ir_model_data
        WHERE module = 'partner_communication_switzerland'
        AND name IN (
            'planned_dossier', 'planned_welcome', 'welcome_activation',
            'sms_registration_confirmation_2'
        );
    """)
    # Update sds_state.
    env.cr.execute("""
    UPDATE recurring_contract
    SET sds_state = 'active'
    WHERE sds_state = 'waiting_welcome';
    """)
    # Delete old view
    env.cr.execute("""
    DELETE FROM ir_ui_view
    WHERE arch_db LIKE '%welcome_active_letter_sent%'
    OR arch_db LIKE '%country_info_pdf%'
    """)
コード例 #17
0
def migrate(env, version):
    res = env["education.task_type"].search([("education_code", "=", "0120")])
    if res:
        openupgrade.add_xmlid(
            env.cr, "contacts_school_education", "education_task_type_0120",
            "education.task_type", res.id, noupdate=False)
コード例 #18
0
def migrate(env, version):
    if not version:
        return

    group_visit_configs = env['partner.communication.config'].search([
        ('name', 'ilike', 'Group visit')
    ])
    if group_visit_configs:
        # We hardcode the ids from production database
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_step1_config',
                              'partner.communication.config', 88)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_step2_config',
                              'partner.communication.config', 89)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_step3_config',
                              'partner.communication.config', 90)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_medical_survey_config',
                              'partner.communication.config', 91)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_travel_documents_config',
                              'partner.communication.config', 92)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_information_day_config',
                              'partner.communication.config', 93)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_detailed_config',
                              'partner.communication.config', 94)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_before_sharing_config',
                              'partner.communication.config', 95)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_after_trip_feedback_config',
                              'partner.communication.config', 96)

        # Email templates
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_step1_email', 'mail.template', 145)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_step2_email', 'mail.template', 146)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_step3_email', 'mail.template', 147)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_medical_survey_email',
                              'mail.template', 148)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_travel_documents_email',
                              'mail.template', 149)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_information_day_email',
                              'mail.template', 150)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_detailed_info_email',
                              'mail.template', 151)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_before_sharing_email',
                              'mail.template', 152)
        openupgrade.add_xmlid(env.cr, 'website_event_compassion',
                              'group_visit_after_trip_feedback_email',
                              'mail.template', 153)