Skip to content

Commit

Permalink
[FIX] joint_buying_product: if line changed lately, recreate (or rede…
Browse files Browse the repository at this point in the history
…lete) transport requests related to orders, if required, calling hook
  • Loading branch information
legalsylvain committed Sep 17, 2024
1 parent e45e57e commit 47bb94d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions joint_buying_product/models/joint_buying_purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,13 @@ def _get_report_tour_data(self):
"</span>"
),
}

def write(self, vals):
res = super().write(vals)
# if the related orders are closed (or deposited), and if user changed the quantity
# lately. (for exemple, view joint.buying.wizard.update.order.grouped), we should
# ensure that transport request are correctly created. (or deleted)
self.mapped("order_id").filtered(
lambda x: x.state in ["closed", "deposited"]
)._hook_state_changed()
return res
1 change: 1 addition & 0 deletions joint_buying_product/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from . import test_tour_report
from . import test_request_invalidate
from . import test_joint_buying_transport_request_compute
from . import test_joint_buying_wizard_update_order_grouped
6 changes: 6 additions & 0 deletions joint_buying_product/tests/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def setUp(self):
self.Order = self.env["joint.buying.purchase.order"]
self.OrderLine = self.env["joint.buying.purchase.order.line"]
self.JointBuyingWizardCreateOrder = self.env["joint.buying.wizard.create.order"]
self.JointBuyingWizardUpdateOrderGrouped = self.env[
"joint.buying.wizard.update.order.grouped"
]

self.company_ELD = self.env.ref("joint_buying_base.company_ELD")
self.company_CDA = self.env.ref("joint_buying_base.company_CDA")
Expand Down Expand Up @@ -57,6 +60,9 @@ def setUp(self):
self.product_LSE_patatoe_agila = self.env.ref(
"joint_buying_product.product_LSE_patatoe_agila"
)
self.grouped_order_ronzon_past = self.env.ref(
"joint_buying_product.grouped_order_ronzon_past"
)

def _create_order_grouped_salaison_devidal_by_wizard(self, user=False):
# Use Wizard to create grouped order
Expand Down
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
)
),
)

0 comments on commit 47bb94d

Please sign in to comment.