Skip to content

Commit

Permalink
[FIX] hr_fleet: add pre-migration to create value for compute field w…
Browse files Browse the repository at this point in the history
…ith store=true by sql instead of auto orm
  • Loading branch information
nguyenvietlam0640 committed Jun 29, 2023
1 parent 1b32e71 commit 3065537
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docsource/modules150-160.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Module coverage 15.0 -> 16.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_expense | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_fleet | Nothing to do | |
| hr_fleet | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_gamification | |No DB layout changes. |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
35 changes: 35 additions & 0 deletions openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from openupgradelib import openupgrade


def create_drive_employee(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE fleet_vehicle_assignation_log
ADD IF NOT EXISTS driver_employee_id INT
""",
)

openupgrade.logged_query(
env.cr,
"""
SELECT id, driver_employee_id
FROM fleet_vehicle
""",
)

for vehicle in env.cr.fetchall():
openupgrade.logged_query(
env.cr,
"""
UPDATE fleet_vehicle_assignation_log
SET driver_employee_id = %s
WHERE vehicle_id = %s
""",
(vehicle[1], vehicle[0]),
)


@openupgrade.migrate()
def migrate(env, version):
create_drive_employee(env)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hr_fleet / fleet.vehicle.assignation.log / driver_employee_id (many2one) : is now stored
hr_fleet / fleet.vehicle.assignation.log / driver_employee_id (many2one) : not related anymore

# NOTHING TO DO: field changed from related field to compute field
# DONE: fill data from old related field for now store current compute field in pre-migration

---XML records in module 'hr_fleet'---
NEW ir.ui.view: hr_fleet.fleet_vehicle_assignation_log_employee_view_list
Expand Down

0 comments on commit 3065537

Please sign in to comment.