Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][OU-ADD] hr_expense: Migration scripts #3689

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules140-150.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Module coverage 14.0 -> 15.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_contract | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_expense | | |
| hr_expense | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_fleet |Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
36 changes: 36 additions & 0 deletions openupgrade_scripts/scripts/hr_expense/15.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from openupgradelib import openupgrade


def _fill_payment_state(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE hr_expense_sheet
SET payment_state = 'not_paid'
WHERE account_move_id IS NULL
""",
)
# Recompute payment_state for the moves associated to the expenses, as on
# v14 these ones were not computed being of type `entry`, which changes now
# on v15 if the method `_payment_state_matters` returns True, which is the
# case for the expense moves
env["hr.expense.sheet"].search([]).account_move_id._compute_amount()
# Now perform the SQL to transfer the payment_state
openupgrade.logged_query(
env.cr,
"""
UPDATE hr_expense_sheet hes
SET payment_state = am.payment_state
FROM account_move am
WHERE am.id = hes.account_move_id
""",
)


@openupgrade.migrate()
def migrate(env, version):
_fill_payment_state(env)
openupgrade.load_data(env.cr, "hr_expense", "15.0.2.0/noupdate_changes.xml")
openupgrade.delete_record_translations(
env.cr, "hr_expense", ["hr_expense_template_register"]
)
22 changes: 22 additions & 0 deletions openupgrade_scripts/scripts/hr_expense/15.0.2.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from openupgradelib import openupgrade


def _compute_currency_id_has_not_value(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE hr_expense e
SET currency_id = c.currency_id
FROM res_company c
WHERE e.currency_id IS NULL AND c.id = e.company_id
""",
)


@openupgrade.migrate()
def migrate(env, version):
_compute_currency_id_has_not_value(env)
openupgrade.logged_query(
env.cr,
"ALTER TABLE hr_expense_sheet ADD COLUMN IF NOT EXISTS payment_state varchar",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---Models in module 'hr_expense'---
new model hr.expense.approve.duplicate [transient]
---Fields in module 'hr_expense'---
hr_expense / hr.expense / company_currency_id (many2one): not stored anymore
# NOTHING TO DO

hr_expense / hr.expense / currency_id (many2one) : now a function
hr_expense / hr.expense / currency_id (many2one) : now required, req_default: function
# DONE: pre-migration: fill currency_id from the company for empty ones

hr_expense / hr.expense.sheet / amount_residual (float) : not a function anymore
hr_expense / hr.expense.sheet / amount_residual (float) : now related
hr_expense / hr.expense.sheet / approval_date (datetime) : NEW
# NOTHING TO DO

hr_expense / hr.expense.sheet / payment_state (selection) : NEW selection_keys: ['in_payment', 'invoicing_legacy', 'not_paid', 'paid', 'partial', 'reversed'], isfunction: function, stored
# DONE: pre-migration: Pre-create the column for avoiding the computation
# DONE: post-migration: fill value of payment_state

---XML records in module 'hr_expense'---
NEW ir.actions.act_window: hr_expense.hr_expense_approve_duplicate_action
DEL ir.actions.server: hr_expense.action_expense_sheet_register_payment
DEL ir.actions.server: hr_expense.hr_expense_sheet_approve_action_server
DEL ir.actions.server: hr_expense.hr_expense_sheet_post_action_server
DEL ir.actions.server: hr_expense.hr_expense_submit_action_server
NEW ir.model.access: hr_expense.access_hr_expense_approve_duplicate
DEL ir.model.constraint: hr_expense.constraint_hr_expense_sheet_journal_id_required_posted
NEW ir.ui.view: hr_expense.hr_expense_approve_duplicate_view_form
NEW ir.ui.view: hr_expense.product_template_search_view_inherit_hr_expense
DEL ir.ui.view: hr_expense.assets_backend
DEL ir.ui.view: hr_expense.assets_tests
DEL ir.ui.view: hr_expense.view_product_hr_expense_form
NEW product.product: hr_expense.product_product_zero_cost
# NOTHING TO DO: noupdate="0" records