mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
* Remove incorrect oldname attributes. * Add filter on partners for running contracts (+ a support o2m field for that). * Cover more tables in model renaming + cleaner code using a loop. * Don't copy contract lines, but rename table + copy contract records on pre. * Contract code is now populated to "Reference/Description" field in invoice. * Order on new contract model has been restored to the same as old analytic accounts.
114 lines
3.2 KiB
Python
114 lines
3.2 KiB
Python
# Copyright 2019 ACSONE SA/NV
|
|
# Copyright 2019 Tecnativa 2019 - Pedro M. Baeza
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
import logging
|
|
|
|
from openupgradelib import openupgrade
|
|
from psycopg2 import sql
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
models_to_rename = [
|
|
# Contract Line Wizard
|
|
('account.analytic.invoice.line.wizard', 'contract.line.wizard'),
|
|
# Abstract Contract
|
|
('account.abstract.analytic.contract', 'contract.abstract.contract'),
|
|
# Abstract Contract Line
|
|
(
|
|
'account.abstract.analytic.contract.line',
|
|
'contract.abstract.contract.line',
|
|
),
|
|
# Contract Line
|
|
('account.analytic.invoice.line', 'contract.line'),
|
|
# Contract Template
|
|
('account.analytic.contract', 'contract.template'),
|
|
# Contract Template Line
|
|
('account.analytic.contract.line', 'contract.template.line'),
|
|
]
|
|
tables_to_rename = [
|
|
# Contract Line
|
|
('account_analytic_invoice_line', 'contract_line'),
|
|
# Contract Template
|
|
('account_analytic_contract', 'contract_template'),
|
|
# Contract Template Line
|
|
('account_analytic_contract_line', 'contract_template_line'),
|
|
]
|
|
columns_to_copy = {
|
|
'contract_line': [
|
|
('analytic_account_id', 'contract_id', None),
|
|
],
|
|
}
|
|
xmlids_to_rename = [
|
|
(
|
|
'contract.account_analytic_cron_for_invoice',
|
|
'contract.contract_cron_for_invoice',
|
|
),
|
|
(
|
|
'contract.account_analytic_contract_manager',
|
|
'contract.contract_template_manager',
|
|
),
|
|
(
|
|
'contract.account_analytic_contract_user',
|
|
'contract.contract_template_user',
|
|
),
|
|
(
|
|
'contract.account_analytic_invoice_line_manager',
|
|
'contract.contract_line_manager',
|
|
),
|
|
(
|
|
'contract.account_analytic_invoice_line_user',
|
|
'contract.contract_line_user',
|
|
),
|
|
(
|
|
'contract.account_analytic_contract_line_manager',
|
|
'contract.contract_template_line_manager',
|
|
),
|
|
(
|
|
'contract.account_analytic_contract_line_user',
|
|
'contract.contract_template_line_user',
|
|
),
|
|
]
|
|
|
|
|
|
def _get_contract_field_name(cr):
|
|
"""
|
|
Contract field changed the name from analytic_account_id to contract_id
|
|
in 12.0.2.0.0. This method used to get the contract field name in
|
|
account_analytic_invoice_line"""
|
|
return (
|
|
'contract_id'
|
|
if openupgrade.column_exists(
|
|
cr, 'account_analytic_invoice_line', 'contract_id'
|
|
)
|
|
else 'analytic_account_id'
|
|
)
|
|
|
|
|
|
def create_contract_records(cr):
|
|
contract_field_name = _get_contract_field_name(cr)
|
|
openupgrade.logged_query(
|
|
cr, """
|
|
CREATE TABLE contract_contract
|
|
(LIKE account_analytic_account INCLUDING ALL)""",
|
|
)
|
|
openupgrade.logged_query(
|
|
cr, sql.SQL("""
|
|
INSERT INTO contract_contract
|
|
SELECT * FROM account_analytic_account
|
|
WHERE id IN (SELECT DISTINCT {} FROM contract_line)
|
|
""").format(
|
|
sql.Identifier(contract_field_name),
|
|
),
|
|
)
|
|
|
|
|
|
@openupgrade.migrate()
|
|
def migrate(env, version):
|
|
cr = env.cr
|
|
openupgrade.rename_models(cr, models_to_rename)
|
|
openupgrade.rename_tables(cr, tables_to_rename)
|
|
openupgrade.rename_xmlids(cr, xmlids_to_rename)
|
|
openupgrade.copy_columns(cr, columns_to_copy)
|
|
create_contract_records(cr)
|