forked from tvtma/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfaaaca
commit 1ab049c
Showing
4 changed files
with
276 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
openupgrade_scripts/scripts/hr_expense/17.0.2.0/post-migration.py
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,24 @@ | ||
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def _company_update_company_expense_allowed_payment_method_line(env): | ||
env.cr.execute( | ||
""" | ||
SELECT id, company_expense_journal_id FROM res_company company | ||
""" | ||
) | ||
for company_id, company_expense_journal_id in env.cr.fetchall(): | ||
company = env["res.company"].browse(company_id) | ||
if company_expense_journal_id: | ||
journal = env["account.journal"].browse(company_expense_journal_id) | ||
company.company_expense_allowed_payment_method_line_ids = ( | ||
journal.outbound_payment_method_line_ids | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.load_data(env, "hr_expense", "17.0.2.0/noupdate_changes.xml") | ||
_company_update_company_expense_allowed_payment_method_line(env) |
153 changes: 153 additions & 0 deletions
153
openupgrade_scripts/scripts/hr_expense/17.0.2.0/pre-migration.py
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,153 @@ | ||
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
|
||
_fields_renames = [ | ||
( | ||
"hr.expense", | ||
"hr_expense", | ||
"amount_tax", | ||
"tax_amount_currency", | ||
), | ||
( | ||
"hr.expense", | ||
"hr_expense", | ||
"amount_tax_company", | ||
"tax_amount", | ||
), | ||
( | ||
"hr.expense", | ||
"hr_expense", | ||
"price_unit", | ||
"unit_price", | ||
), | ||
( | ||
"hr.expense", | ||
"hr_expense", | ||
"untaxed_amount", | ||
"untaxed_amount_currency", | ||
), | ||
( | ||
"hr.expense", | ||
"hr_expense", | ||
"total_amount", | ||
"total_amount_currency", | ||
), | ||
( | ||
"hr.expense", | ||
"hr_expense", | ||
"total_amount_company", | ||
"total_amount", | ||
), | ||
( | ||
"hr.expense.sheet", | ||
"hr_expense_sheet", | ||
"total_amount_taxes", | ||
"total_tax_amount", | ||
), | ||
] | ||
|
||
|
||
def _am_update_expense_sheet_id(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE account_move | ||
ADD COLUMN IF NOT EXISTS expense_sheet_id INTEGER | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE account_move am | ||
SET expense_sheet_id = sheet.id | ||
FROM hr_expense_sheet sheet | ||
WHERE am.id = sheet.account_move_id | ||
""", | ||
) | ||
|
||
|
||
def _hr_expense_update_state(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE hr_expense expense | ||
SET state = 'reported' | ||
FROM hr_expense_sheet sheet | ||
WHERE expense.sheet_id = sheet.id AND | ||
sheet.state = 'draft' | ||
""", | ||
) | ||
|
||
|
||
def _hr_expense_sheet_fill_approval_state(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE hr_expense_sheet | ||
ADD COLUMN IF NOT EXISTS approval_state VARCHAR | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE hr_expense_sheet | ||
SET approval_state = CASE | ||
WHEN state = 'submit' then 'submit' | ||
WHEN state in ('approve', 'post', 'done') then 'approve' | ||
WHEN state = 'cancel' then 'cancel' | ||
END | ||
""", | ||
) | ||
|
||
|
||
def _hr_expense_sheet_journal(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE hr_expense_sheet | ||
ADD COLUMN IF NOT EXISTS employee_journal_id INTEGER, | ||
ADD COLUMN IF NOT EXISTS payment_method_line_id INTEGER; | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE hr_expense_sheet sheet | ||
SET payment_method_line_id = method_line.id | ||
FROM account_journal journal | ||
JOIN account_payment_method_line method_line | ||
ON method_line.journal_id = journal.id | ||
JOIN account_payment_method method | ||
ON method.id = method_line.payment_method_id | ||
WHERE sheet.bank_journal_id = journal.id | ||
AND method.payment_type = 'outbound' | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE hr_expense_sheet | ||
SET employee_journal_id = journal_id | ||
WHERE journal_id IS NOT NULL | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE hr_expense_sheet sheet | ||
SET journal_id = CASE | ||
WHEN bank_journal_id IS NOT NULL | ||
AND expense.payment_mode = 'company_account' THEN bank_journal_id | ||
FROM hr_expense expense | ||
WHERE expense.sheet_id = sheet.id | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_am_update_expense_sheet_id(env) | ||
openupgrade.rename_fields(env, _fields_renames) | ||
_hr_expense_update_state(env) | ||
_hr_expense_sheet_fill_approval_state(env) |
98 changes: 98 additions & 0 deletions
98
openupgrade_scripts/scripts/hr_expense/17.0.2.0/upgrade_analysis_work.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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
---Models in module 'hr_expense'--- | ||
---Fields in module 'hr_expense'--- | ||
hr_expense / account.bank.statement.line / expense_sheet_id (one2many) : type is now 'many2one' ('one2many') | ||
hr_expense / account.move / expense_sheet_id (one2many) : type is now 'many2one' ('one2many') | ||
hr_expense / account.payment / expense_sheet_id (one2many) : type is now 'many2one' ('one2many') | ||
# DONE pre-migration: set expense_sheet_id for each account_move_id present at hr.expense.sheet | ||
|
||
hr_expense / hr.employee / filter_for_expense (boolean) : NEW | ||
# NOTHING TO DO: no store field | ||
|
||
hr_expense / hr.expense / activity_user_id (many2one) : not related anymore | ||
hr_expense / hr.expense / activity_user_id (many2one) : now a function | ||
hr_expense / hr.expense / rating_ids (one2many) : NEW relation: rating.rating | ||
# NOTHING TO DO | ||
|
||
hr_expense / hr.expense / amount_tax (float) : DEL | ||
hr_expense / hr.expense / amount_tax_company (float) : DEL | ||
# DONE pre-migration: rename amount_tax to tax_amount_currency, amount_tax_company to tax_amount | ||
|
||
|
||
hr_expense / hr.expense / is_refused (boolean) : DEL | ||
# NOTHING TO DO: dead code https://github.com/odoo/odoo/pull/110518 | ||
|
||
hr_expense / hr.expense / price_unit (float) : NEW required, isfunction: function, stored | ||
# DONE pre-migration: rename to unit_price | ||
|
||
hr_expense / hr.expense / reference (char) : DEL | ||
hr_expense / hr.expense / sample (boolean) : DEL | ||
# NOTHING TO DO: deprecated field https://github.com/odoo/odoo/pull/130244/commits/266b482264576903cf736ffe2bddfc71f7a7a4ec | ||
|
||
hr_expense / hr.expense / state (selection) : selection_keys is now '['approved', 'done', 'draft', 'refused', 'reported', 'submitted']' ('['approved', 'done', 'draft', 'refused', 'reported']') | ||
# DONE pre-migration: if any expense has expense sheet and the sheet is on draft state, then update state of expense to 'reported' | ||
|
||
hr_expense / hr.expense / tax_amount (float) : NEW isfunction: function, stored | ||
hr_expense / hr.expense / tax_amount_currency (float) : NEW isfunction: function, stored | ||
# DONE pre-migration: rename from amount_tax_company, amount_tax | ||
|
||
hr_expense / hr.expense / total_amount_company (float) : DEL | ||
hr_expense / hr.expense / total_amount_currency (float) : NEW hasdefault: compute | ||
hr_expense / hr.expense / unit_amount (float) : DEL required | ||
hr_expense / hr.expense / untaxed_amount (float) : DEL | ||
hr_expense / hr.expense / untaxed_amount_currency (float): NEW isfunction: function, stored | ||
# DONE pre-migration: total_amount_company -> total_amount, total_amount -> total_amount_currency, untaxed_amount -> untaxed_amount_currency | ||
|
||
hr_expense / hr.expense.sheet / account_move_id (many2one) : DEL relation: account.move | ||
hr_expense / hr.expense.sheet / account_move_ids (one2many) : NEW relation: account.move | ||
# DONE pre-migration: set expense_sheet_id for each account_move_id present at hr.expense.sheet | ||
|
||
hr_expense / hr.expense.sheet / activity_user_id (many2one) : not related anymore | ||
hr_expense / hr.expense.sheet / activity_user_id (many2one) : now a function | ||
# NOTHING TO DO | ||
|
||
hr_expense / hr.expense.sheet / address_id (many2one) : DEL relation: res.partner | ||
# NOTHING TO DO: deprecated field | ||
|
||
hr_expense / hr.expense.sheet / amount_residual (float) : not related anymore | ||
hr_expense / hr.expense.sheet / amount_residual (float) : now a function | ||
# NOTHING TO DO | ||
|
||
hr_expense / hr.expense.sheet / approval_state (selection) : NEW selection_keys: ['approve', 'cancel', 'submit'] | ||
# DONE pre-migration: create column and fill value according to state of expense sheet | ||
|
||
hr_expense / hr.expense.sheet / bank_journal_id (many2one) : DEL relation: account.journal | ||
# TODO: update outbout payment method line of bank_journal_id into 'payment_method_line_id', https://github.com/odoo/odoo/pull/110518/ | ||
|
||
hr_expense / hr.expense.sheet / department_id (many2one) : now related | ||
# NOTHING TO DO | ||
|
||
hr_expense / hr.expense.sheet / employee_journal_id (many2one): NEW relation: account.journal, hasdefault: default | ||
hr_expense / hr.expense.sheet / journal_id (many2one) : now a function | ||
# DONE pre-migration: fill value by 'journal_id' then update 'journal_id' by 'payment_method_line_id.jounal_id' if 'paid by company (bank_journal_id)', https://github.com/odoo/odoo/pull/110518/ | ||
|
||
hr_expense / hr.expense.sheet / payment_method_line_id (many2one): NEW relation: account.payment.method.line, hasdefault: compute | ||
# DONE: update outbount payment method line of bank_journal_id into 'payment_method_line_id', https://github.com/odoo/odoo/pull/110518/ | ||
|
||
hr_expense / hr.expense.sheet / rating_ids (one2many) : NEW relation: rating.rating | ||
hr_expense / hr.expense.sheet / state (selection) : now a function | ||
# NOTHING TO DO | ||
|
||
hr_expense / hr.expense.sheet / total_amount_taxes (float) : DEL | ||
hr_expense / hr.expense.sheet / total_tax_amount (float) : NEW isfunction: function, stored | ||
# DONE pre-migration total_amount_taxes - > total_tax_amount | ||
|
||
hr_expense / res.company / company_expense_allowed_payment_method_line_ids (many2many): NEW relation: account.payment.method.line | ||
hr_expense / res.company / company_expense_journal_id (many2one): DEL relation: account.journal | ||
# DONE post-migration: update 'company_expense_allowed_payment_method_line_ids' using 'company_expense_journal_id.outbound_payment_method_line_ids', https://github.com/odoo/odoo/pull/110518/ | ||
|
||
hr_expense / res.company / expense_product_id (many2one) : NEW relation: product.product | ||
# NOTHING TO DO | ||
|
||
---XML records in module 'hr_expense'--- | ||
ir.actions.act_window: hr_expense.action_hr_expense_sheet_my_all (deleted domain) | ||
NEW ir.actions.report: hr_expense.action_report_expense_sheet_img | ||
NEW ir.ui.view: hr_expense.product_product_expense_kanban_view | ||
NEW ir.ui.view: hr_expense.report_expense_sheet_img | ||
NEW mail.message.subtype: hr_expense.mt_expense_entry_delete (noupdate) | ||
NEW mail.message.subtype: hr_expense.mt_expense_reset (noupdate) | ||
# NOTHING TO DO |