Skip to content

Commit

Permalink
[FIX] joint_buying_base: Recompute all the start_date of the model jo…
Browse files Browse the repository at this point in the history
…int_buying_transport_request, as the previous value was bad computed
  • Loading branch information
legalsylvain committed Oct 18, 2024
1 parent 0b630f9 commit 0c8470e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions joint_buying_base/migrations/12.0.7.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (C) 2024-Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):

_logger.info(
"Fix bad computation of joint_buying_transport_request.start_date field."
)
openupgrade.logged_query(
"""
UPDATE joint_buying_transport_request tr_main
SET start_date = tmp.min_start_date
FROM (
SELECT tr.id as transport_request_id,
min(tl.start_date) as min_start_date
FROM joint_buying_transport_request tr
INNER JOIN joint_buying_transport_request_line trl
ON trl.request_id = tr.id
INNER JOIN joint_buying_tour_line tl
ON tl.id = trl.tour_line_id
WHERE tr.state = 'computed'
GROUP BY tr.id
) as tmp
WHERE
tr_main.id = tmp.transport_request_id
AND tr_main.start_date != tmp.min_start_date;
"""
)
2 changes: 1 addition & 1 deletion joint_buying_base/models/joint_buying_transport_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _set_tour_lines(self, tour_lines):

self.write(
{
"start_date": max(tour_lines.mapped("start_date")),
"start_date": min(tour_lines.mapped("start_date")),
"arrival_date": max(tour_lines.mapped("arrival_date")),
"state": "computed",
"line_ids": [(5,)] + [(0, 0, x) for x in line_vals],
Expand Down

0 comments on commit 0c8470e

Please sign in to comment.