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

[MIG][15.0] sale_timesheet: migration to 15.0 #3350

Closed
wants to merge 1 commit into from
Closed
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 @@ -638,7 +638,7 @@ Module coverage 14.0 -> 15.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| sale_stock_margin | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| sale_timesheet | | |
| sale_timesheet |Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| |del| sale_timesheet_edit | |Merged into sale_timesheet. |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
156 changes: 156 additions & 0 deletions openupgrade_scripts/scripts/sale_timesheet/15.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
from openupgradelib import openupgrade


def _fast_fill_account_analytic_line_order_id(env):

openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_analytic_line
ADD COLUMN IF NOT EXISTS order_id integer
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_analytic_line aal
SET order_id = sol.order_id
FROM sale_order_line sol
WHERE aal.so_line IS NOT NULL AND aal.so_line = sol.id
""",
)


def _fast_fill_project_sale_line_employee_map_is_cost_changed(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE project_sale_line_employee_map
ADD COLUMN IF NOT EXISTS is_cost_changed boolean
""",
)
# 1. Set is_cost_changed = False when employee_id IS NULL
openupgrade.logged_query(
env.cr,
"""
UPDATE project_sale_line_employee_map
SET is_cost_changed = CASE
WHEN employee_id IS NULL THEN false
ELSE true
END
WHERE is_cost_changed IS NULL
""",
)


def _fast_fill_project_sale_line_employee_map_cost(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE project_sale_line_employee_map
ADD COLUMN IF NOT EXISTS cost numeric
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE project_sale_line_employee_map
SET cost = 0
WHERE is_cost_changed = false AND employee_id IS NULL
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE project_sale_line_employee_map emp_map
SET cost = emp.timesheet_cost
FROM hr_employee emp
WHERE emp_map.is_cost_changed = false AND emp_map.employee_id IS NOT NULL
AND emp_map.employee_id = emp.id
""",
)


def _fill_project_task_analytic_account_id(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE project_task task
SET analytic_account_id = so.analytic_account_id
FROM sale_order so
WHERE task.sale_order_id = so.id AND task.sale_order_id IS NOT NULL
AND task.analytic_account_id IS NULL
""",
)


def _re_fill_account_analytic_line_timesheet_invoice_type(env):
openupgrade.logged_query(
env.cr,
"""
WITH aal_tmp AS (
SELECT aal.id AS aal_id,
CASE
WHEN product IS NOT NULL
AND tmpl.type = 'service' THEN 'service_revenues'
WHEN aal.amount >=0 THEN 'other_revenues' ELSE 'other_costs' END
AS timesheet_invoice_type
FROM account_analytic_line aal
LEFT JOIN sale_order_line so_line ON aal.so_line = so_line.id
LEFT JOIN product_product product ON so_line.product_id = product.id
LEFT JOIN product_template tmpl ON tmpl.id = product.product_tmpl_id
WHERE aal.project_id IS NULL
)
UPDATE account_analytic_line aal
SET timesheet_invoice_type = aal_tmp.timesheet_invoice_type
FROM aal_tmp WHERE aal_tmp.aal_id = aal.id
""",
)
openupgrade.logged_query(
env.cr,
"""
WITH aal_tmp AS (
SELECT aal.id AS aal_id,
CASE
WHEN so_line IS NOT NULL AND product IS NOT NULL
AND tmpl.type = 'service' AND tmpl.invoice_policy = 'order'
THEN 'billable_fixed'
WHEN so_line IS NOT NULL AND product IS NOT NULL
AND tmpl.type = 'service' AND tmpl.invoice_policy = 'delivery'
AND tmpl.service_type = 'timesheet' AND aal.amount > 0
THEN 'timesheet_revenues'
WHEN so_line IS NOT NULL AND product IS NOT NULL
AND tmpl.type = 'service' AND tmpl.invoice_policy = 'delivery'
AND tmpl.service_type = 'timesheet' AND aal.amount <= 0
THEN 'billable_time'
WHEN so_line IS NOT NULL AND product IS NOT NULL
AND tmpl.type = 'service' AND tmpl.invoice_policy = 'delivery'
AND tmpl.service_type != 'timesheet'
THEN 'billable_fixed'
WHEN so_line IS NOT NULL AND product IS NOT NULL
AND tmpl.type = 'service' AND tmpl.invoice_policy = 'order'
THEN 'billable_fixed'
WHEN so_line IS NULL OR (product IS NOT NULL AND tmpl.type != 'service')
THEN 'non_billable'
END
AS timesheet_invoice_type
FROM account_analytic_line aal
LEFT JOIN sale_order_line so_line ON aal.so_line = so_line.id
LEFT JOIN product_product product ON so_line.product_id = product.id
LEFT JOIN product_template tmpl ON tmpl.id = product.product_tmpl_id
WHERE aal.project_id IS NOT NULL AND aal.timesheet_invoice_type IS NULL
)
UPDATE account_analytic_line aal
SET timesheet_invoice_type = aal_tmp.timesheet_invoice_type
FROM aal_tmp WHERE aal_tmp.aal_id = aal.id
""",
)


@openupgrade.migrate()
def migrate(env, version):
_fast_fill_account_analytic_line_order_id(env)
_fast_fill_project_sale_line_employee_map_is_cost_changed(env)
_fast_fill_project_sale_line_employee_map_cost(env)
_fill_project_task_analytic_account_id(env)
_re_fill_account_analytic_line_timesheet_invoice_type(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---Models in module 'sale_timesheet'---
obsolete model project.task.create.sale.order [transient]
---Fields in module 'sale_timesheet'---
sale_timesheet / account.analytic.line / order_id (many2one) : NEW relation: sale.order, isrelated: related, stored
# DONE: pre-migration: fill value from sale order line

sale_timesheet / account.analytic.line / non_allow_billable (boolean) : DEL
# NOTHING TO DO: non_allow_billable is not used anymore

sale_timesheet / account.analytic.line / timesheet_invoice_type (selection): selection_keys is now '['billable_fixed', 'billable_time', 'non_billable', 'other_costs', 'other_revenues', 'service_revenues', 'timesheet_revenues']' ('['billable_fixed', 'billable_time', 'non_billable', 'non_billable_project', 'non_billable_timesheet']')
# DONE: end-migration: re-filled value

sale_timesheet / product.template / service_upsell_threshold (float): NEW hasdefault
# NOTHING TO DO

sale_timesheet / project.project / bill_type (selection) : DEL selection_keys: ['customer_project', 'customer_task']
# NOTHING TO DO: bill_type is not used anymore

sale_timesheet / project.project / pricing_type (selection) : not stored anymore
sale_timesheet / project.project / pricing_type (selection) : now a function
sale_timesheet / project.project / pricing_type (selection) : selection_keys is now '['employee_rate', 'fixed_rate', 'task_rate']' ('['employee_rate', 'fixed_rate']')
# NOTHING TO DO: non-stored field

sale_timesheet / project.sale.line.employee.map / cost (float) : NEW isfunction: function, stored
# DONE: pre-migration: fast filled

sale_timesheet / project.sale.line.employee.map / is_cost_changed (boolean) : NEW isfunction: function, stored
# DONE: pre-migration: fast filled

sale_timesheet / project.sale.line.employee.map / sale_line_id (many2one) : now a function
# NOTHING TO DO

sale_timesheet / project.sale.line.employee.map / timesheet_product_id (many2one): DEL relation: product.product
# NOTHING TO DO: timesheet_product_id is not used anymore

sale_timesheet / project.task / analytic_account_id (many2one): is now stored
sale_timesheet / project.task / analytic_account_id (many2one): module is now 'project' ('sale_timesheet')
sale_timesheet / project.task / analytic_account_id (many2one): not related anymore
# DONE: pre-migration: filled value

sale_timesheet / project.task / non_allow_billable (boolean) : DEL
# NOTHING TO DO: non_allow_billable is not used anymore, we use allow_billable instead

sale_timesheet / project.task / timesheet_product_id (many2one): not stored anymore
sale_timesheet / project.task / timesheet_product_id (many2one): now related
# NOTHING TO DO: non-stored field

sale_timesheet / sale.order.line / has_displayed_warning_upsell (boolean): NEW
# NOTHING TO DO: new field for new feature

sale_timesheet / sale.order.line / remaining_hours (float) : is now stored
# NOTHING TO DO: handed by ORM

---XML records in module 'sale_timesheet'---
DEL ir.actions.act_window: sale_timesheet.project_profitability_report_action
DEL ir.actions.act_window: sale_timesheet.project_task_action_multi_create_sale_order
DEL ir.actions.act_window: sale_timesheet.project_timesheet_action_client_timesheet_plan
NEW ir.actions.act_window.view: sale_timesheet.action_timesheet_from_invoice_view_form
NEW ir.actions.act_window.view: sale_timesheet.action_timesheet_from_invoice_view_graph
NEW ir.actions.act_window.view: sale_timesheet.action_timesheet_from_invoice_view_kanban
NEW ir.actions.act_window.view: sale_timesheet.action_timesheet_from_invoice_view_pivot
NEW ir.actions.act_window.view: sale_timesheet.action_timesheet_from_invoice_view_tree
NEW ir.actions.act_window.view: sale_timesheet.timesheet_action_view_report_by_billing_rate_form
NEW ir.actions.act_window.view: sale_timesheet.timesheet_action_view_report_by_billing_rate_kanban
NEW ir.actions.act_window.view: sale_timesheet.timesheet_action_view_report_by_billing_rate_tree
DEL ir.model.access: sale_timesheet.access_project_task_create_sale_order
DEL ir.model.constraint: sale_timesheet.constraint_project_create_sale_order_line_unique_employee_per_wizard
DEL ir.model.constraint: sale_timesheet.constraint_project_project_timesheet_product_required_if_billable_and_timesheets
DEL ir.model.constraint: sale_timesheet.constraint_project_sale_line_employee_map_uniqueness_employee
DEL ir.ui.menu: sale_timesheet.menu_project_profitability_analysis
NEW ir.ui.view: sale_timesheet.hr_timesheet_line_form_inherit
NEW ir.ui.view: sale_timesheet.hr_timesheet_line_tree_inherit
NEW ir.ui.view: sale_timesheet.portal_invoice_page_inherit
NEW ir.ui.view: sale_timesheet.portal_my_task_inherit
NEW ir.ui.view: sale_timesheet.portal_timesheet_table_inherit
NEW ir.ui.view: sale_timesheet.project_profitability_report_view_tree
NEW ir.ui.view: sale_timesheet.project_sharing_inherit_project_task_view_form
NEW ir.ui.view: sale_timesheet.project_task_view_form_inherit_sale_timesheet_editable
NEW ir.ui.view: sale_timesheet.project_update_default_description
DEL ir.ui.view: sale_timesheet.assets_backend
DEL ir.ui.view: sale_timesheet.assets_frontend
DEL ir.ui.view: sale_timesheet.portal_invoice_page_inherit_timesheet
DEL ir.ui.view: sale_timesheet.progressbar
DEL ir.ui.view: sale_timesheet.project_task_create_sale_order_view_form
DEL ir.ui.view: sale_timesheet.quick_create_task_form_sale_timesheet
DEL ir.ui.view: sale_timesheet.report_invoice_document
DEL ir.ui.view: sale_timesheet.sale_order_portal_template_inherit
DEL ir.ui.view: sale_timesheet.timesheet_plan
DEL ir.ui.view: sale_timesheet.timesheet_view_tree_sale
DEL ir.ui.view: sale_timesheet_edit.assets_backend
DEL ir.ui.view: sale_timesheet_edit.project_task_view_form_inherit_sale_timesheet_edit
DEL ir.ui.view: sale_timesheet_edit.project_task_view_form_inherit_sale_timesheet_editable
# NOTHING TO DO: noupdate="0" records