-
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.
Signed-off-by legalsylvain
- Loading branch information
Showing
8 changed files
with
125 additions
and
7 deletions.
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() |
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
joint_buying_product/tests/test_joint_buying_wizard_update_order_grouped.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,45 @@ | ||
# 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). | ||
|
||
|
||
from odoo.tests import tagged | ||
|
||
from .test_abstract import TestAbstract | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestJointBuyingWizardUpdateOrderGrouped(TestAbstract): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
def test_01_wizard_update_order_grouped(self): | ||
|
||
wizard = self.JointBuyingWizardUpdateOrderGrouped.with_context( | ||
active_id=self.grouped_order_ronzon_past.id | ||
).create({}) | ||
wizard.show_all_orders = True | ||
wizard.show_all_products = True | ||
wizard.onchange_show_settings() | ||
|
||
wizard.line_ids.write({"qty": 0}) | ||
|
||
self.assertEqual( | ||
len( | ||
self.grouped_order_ronzon_past.mapped("order_ids.transport_request_id") | ||
), | ||
0, | ||
) | ||
|
||
wizard.line_ids.write({"qty": 100}) | ||
|
||
self.assertEqual( | ||
len( | ||
self.grouped_order_ronzon_past.mapped("order_ids.transport_request_id") | ||
), | ||
len( | ||
self.grouped_order_ronzon_past.mapped("order_ids").filtered( | ||
lambda x: x.deposit_partner_id != x.delivery_partner_id | ||
) | ||
), | ||
) |