-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] joint_buying_product: Add a script to fix transport requests th…
…at should be deleted (or created)
- Loading branch information
1 parent
47bb94d
commit 96885cd
Showing
2 changed files
with
59 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
58 changes: 58 additions & 0 deletions
58
joint_buying_product/migrations/12.0.6.0.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,58 @@ | ||
# 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): | ||
JointBuyingOrder = env["joint.buying.purchase.order"] | ||
|
||
# Get null orders deposited or closed | ||
# that still have a transport request related | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
SELECT po.id | ||
FROM joint_buying_transport_request tr | ||
INNER JOIN joint_buying_purchase_order po | ||
ON po.id = tr.order_id | ||
WHERE po.state IN ('deposited', 'closed') | ||
AND po.amount_untaxed = 0.0; | ||
""", | ||
) | ||
|
||
order_ids = [x[0] for x in env.cr.fetchall()] | ||
|
||
_logger.info(f"Unlink Transport Requests for orders {order_ids} ...") | ||
JointBuyingOrder.browse(order_ids)._hook_state_changed() | ||
|
||
# Get NOT null recent orders | ||
# that don't have a transport request related | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
SELECT | ||
po.id, | ||
po.create_date, | ||
po.state, | ||
po.amount_untaxed | ||
FROM joint_buying_purchase_order po | ||
WHERE po.id not in ( | ||
SELECT order_id from joint_buying_transport_request | ||
WHERE order_id is not null | ||
) | ||
AND po.deposit_partner_id != po.delivery_partner_id | ||
AND po.amount_untaxed > 0.0 AND po.deposit_date > '2024-01-01'; | ||
""", | ||
) | ||
|
||
order_ids = [x[0] for x in env.cr.fetchall()] | ||
|
||
_logger.info(f"Create Transport Requests for orders {order_ids} ...") | ||
JointBuyingOrder.browse(order_ids)._hook_state_changed() |