Skip to content

Commit

Permalink
[IMP] wizard.find.route : Specific Use Case : The first tour that goe…
Browse files Browse the repository at this point in the history
…s to a route is not allways the best !!!
  • Loading branch information
legalsylvain committed Oct 30, 2023
1 parent ea5b6dd commit 58fbb3b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
8 changes: 8 additions & 0 deletions joint_buying_product/demo/joint_buying_transport_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@
<field name="manual_total_weight">66</field>
</record>

<record id="request_vev_che_week_2" model="joint.buying.transport.request">
<field name="manual_origin_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_VEV').joint_buying_partner_id.id"/>
<field name="manual_destination_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_CHE').joint_buying_partner_id.id"/>
<field name="manual_start_date" eval="(DateTime.today() + timedelta(days=8)).strftime('%Y-%m-%d 07:00')"/>
<field name="manual_amount_untaxed">222</field>
<field name="manual_total_weight">33</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .test_abstract import TestAbstract


@tagged("post_install", "-at_install")
@tagged("post_install", "-at_install", "find_route")
class TestJointBuyingWizardFindRoute(TestAbstract):
def setUp(self):
super().setUp()
Expand Down Expand Up @@ -53,6 +53,18 @@ def test_23_transport_request_vev_fumet_week_1(self):
"joint_buying_product.request_vev_fumet_dombes_week_1", [], "not_computable"
)

def test_24_transport_request_vev_che_week_2(self):
"""Complex case: a later start arrives earlier"""
self._verify_tour_lines_computation(
"joint_buying_product.request_vev_che_week_2",
[
"joint_buying_base.tour_lyon_loire_3_line_2",
"joint_buying_base.tour_lyon_drome_2_line_2",
"joint_buying_base.tour_lyon_drome_2_line_4",
],
"computed",
)

def _verify_tour_lines_computation(
self, request_xml_id, tour_line_xml_ids, expected_state
):
Expand Down
36 changes: 33 additions & 3 deletions joint_buying_product/wizards/joint_buying_wizard_find_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,46 @@ def _create_initial_node(self, tree, partner, date):

@api.model
def _create_following_node(self, tree, parent, line, destination):

partner = line.arrival_point_id
date = line.arrival_date
best_main_node = (
line.arrival_point_id == destination
or line.arrival_point_id.joint_buying_is_durable_storage
)
return tree.create_node(
new_node = tree.create_node(
parent=parent,
tag=f"{partner.joint_buying_code}-{date}-{line.id}"
f"-{best_main_node and '-BEST_MAIN_NODE'}",
f"{best_main_node and '-BEST_MAIN_NODE' or ''}",
data=SimpleNamespace(
partner=partner, date=date, best_main_node=best_main_node, line=line
),
)

best_nodes = [
x
for x in tree.all_nodes()
if x.data.best_main_node and x.data.partner == line.arrival_point_id
]

if len(best_nodes) > 1:
the_best_node = self._get_best_node(best_nodes)
for node in best_nodes:
if node == the_best_node:
continue
node.tag = node.tag.replace("-BEST_MAIN_NODE", "")
node.data.best_main_node = False

return new_node

@api.model
def _get_best_node(self, nodes):
best_node = nodes[0]
for node in nodes[1:]:
if node.data.date < best_node.data.date:
best_node = node
return best_node

@api.model
def _get_startable_nodes(self, tree):
"""
Expand Down Expand Up @@ -208,7 +233,12 @@ def _populate_tree(self, transport_request):
tour=tour,
from_line=line,
destination=transport_request.destination_partner_id,
excludes=[x.data.partner for x in startable_nodes],
# We don't want to target origin
# you don't want to go round and round in the same place.
excludes=[
transport_request.origin_partner_id,
startable_node.data.partner,
],
)
if found_lines:
current_node = startable_node
Expand Down

0 comments on commit 58fbb3b

Please sign in to comment.