-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
80 changed files
with
5,456 additions
and
1,590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ var/ | |
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.eggs | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding='UTF-8'?> | ||
<odoo noupdate="1"> | ||
|
||
<record model="ir.cron" id="contract_line_cron_for_renew"> | ||
<field name="name">Renew Contract lines</field> | ||
<field name="model_id" ref="model_contract_line"/> | ||
<field name="state">code</field> | ||
<field name="code">model.cron_renew_contract_line()</field> | ||
<field name="user_id" ref="base.user_root" /> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field eval="False" name="doall" /> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright 2018 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from openupgradelib import openupgrade | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def _set_finished_contract(cr): | ||
_logger.info("set recurring_next_date to false for finished contract") | ||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
UPDATE account_analytic_account | ||
SET recurring_next_date=NULL | ||
WHERE recurring_next_date > date_end | ||
""", | ||
) | ||
|
||
|
||
def _move_contract_recurrence_info_to_contract_line(cr): | ||
_logger.info("Move contract data to line level") | ||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
ALTER TABLE account_analytic_invoice_line | ||
ADD COLUMN IF NOT EXISTS recurring_rule_type VARCHAR(255), | ||
ADD COLUMN IF NOT EXISTS recurring_invoicing_type VARCHAR(255), | ||
ADD COLUMN IF NOT EXISTS recurring_interval INTEGER, | ||
ADD COLUMN IF NOT EXISTS recurring_next_date DATE, | ||
ADD COLUMN IF NOT EXISTS date_start DATE, | ||
ADD COLUMN IF NOT EXISTS date_end DATE | ||
""", | ||
) | ||
|
||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
UPDATE account_analytic_invoice_line AS contract_line | ||
SET | ||
recurring_rule_type=contract.recurring_rule_type, | ||
recurring_invoicing_type=contract.recurring_invoicing_type, | ||
recurring_interval=contract.recurring_interval, | ||
recurring_next_date=contract.recurring_next_date, | ||
date_start=contract.date_start, | ||
date_end=contract.date_end | ||
FROM | ||
account_analytic_account AS contract | ||
WHERE | ||
contract.id=contract_line.analytic_account_id | ||
""", | ||
) | ||
|
||
|
||
def _move_contract_template_recurrence_info_to_contract_template_line(cr): | ||
_logger.info("Move contract template data to line level") | ||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
ALTER TABLE account_analytic_contract_line | ||
ADD COLUMN IF NOT EXISTS recurring_rule_type VARCHAR(255), | ||
ADD COLUMN IF NOT EXISTS recurring_invoicing_type VARCHAR(255), | ||
ADD COLUMN IF NOT EXISTS recurring_interval INTEGER | ||
""", | ||
) | ||
|
||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
UPDATE account_analytic_contract_line AS contract_template_line | ||
SET | ||
recurring_rule_type=contract_template.recurring_rule_type, | ||
recurring_invoicing_type=contract_template.recurring_invoicing_type, | ||
recurring_interval=contract_template.recurring_interval | ||
FROM | ||
account_analytic_contract AS contract_template | ||
WHERE | ||
contract_template.id=contract_template_line.analytic_account_id | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
""" | ||
set recurring_next_date to false for finished contract | ||
""" | ||
_logger.info(">> Pre-Migration 12.0.2.0.0") | ||
cr = env.cr | ||
_set_finished_contract(cr) | ||
_move_contract_recurrence_info_to_contract_line(cr) | ||
_move_contract_template_recurrence_info_to_contract_template_line(cr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2019 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from openupgradelib import openupgrade | ||
from odoo.tools import parse_version | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def _update_no_update_ir_cron(env): | ||
# Update ir.cron | ||
env.ref('contract.contract_cron_for_invoice').model_id = env.ref( | ||
'contract.model_contract_contract' | ||
) | ||
env.ref('contract.contract_line_cron_for_renew').model_id = env.ref( | ||
'contract.model_contract_line' | ||
) | ||
env.ref('contract.email_contract_template').model_id = env.ref( | ||
'contract.model_contract_contract' | ||
) | ||
|
||
|
||
def _init_last_date_invoiced_on_contract_lines(env): | ||
_logger.info("init last_date_invoiced field for contract lines") | ||
contract_lines = env["contract.line"].search( | ||
[("recurring_next_date", "!=", False)] | ||
) | ||
contract_lines._init_last_date_invoiced() | ||
|
||
|
||
def _init_invoicing_partner_id_on_contracts(env): | ||
_logger.info("Populate invoicing partner field on contracts") | ||
contracts = env["contract.contract"].search([]) | ||
contracts._inverse_partner_id() | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_update_no_update_ir_cron(env) | ||
if parse_version(version) < parse_version('12.0.2.0.0'): | ||
# We check the version here as this post-migration script was in | ||
# 12.0.2.0.0 and already done for those who used the module when | ||
# it was a PR | ||
_init_last_date_invoiced_on_contract_lines(env) | ||
_init_invoicing_partner_id_on_contracts(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import account_analytic_contract | ||
from . import account_analytic_account | ||
from . import account_analytic_contract_line | ||
from . import account_analytic_invoice_line | ||
from . import abstract_contract | ||
from . import abstract_contract_line | ||
from . import contract_template | ||
from . import contract | ||
from . import contract_template_line | ||
from . import contract_line | ||
from . import account_invoice | ||
from . import account_invoice_line | ||
from . import res_partner |
Oops, something went wrong.