Skip to content

Commit

Permalink
[WIP] Improving algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Oct 30, 2023
1 parent b045d57 commit 46f8ffb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 34 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
80 changes: 47 additions & 33 deletions joint_buying_product/wizards/joint_buying_wizard_find_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ class JointBuyingWizardFindRoute(models.TransientModel):
compute="_compute_simulation",
)

# #################
# Default Section
# #################
def _default_transport_reqquest_id(self):
return self.env.context.get("active_id")

# #################
# Compute Section
# #################
@api.depends("transport_request_id")
def _compute_simulation(self):
self.ensure_one()
Expand All @@ -89,6 +94,48 @@ def compute_results(self, transport_requests):

return results

# #################
# UI Section
# #################
def button_apply(self):
self.ensure_one()
self.transport_request_id._set_tour_lines(self.tour_line_ids)

# #################
# Treelib Tools Section
# #################
@api.model
def _create_initial_node(self, tree, partner, date):
durable_storable = True
return tree.create_node(
tag=f"{partner.joint_buying_code}-{date}-{durable_storable}",
data=SimpleNamespace(
partner=partner,
date=date,
durable_storable=durable_storable,
line=False,
),
)

@api.model
def _create_following_node(self, tree, parent, line, destination):
partner = line.arrival_point_id
date = line.arrival_date
durable_storable = (
line.arrival_point_id == destination
or line.arrival_point_id.joint_buying_is_durable_storage
)
return tree.create_node(
parent=parent,
tag=f"{partner.joint_buying_code}-{date}-{durable_storable}-{line.id}",
data=SimpleNamespace(
partner=partner, date=date, durable_storable=durable_storable, line=line
),
)

# #################
# Tree creation / Update Section
# #################
@api.model
def _extract_tour_lines_from_tree(self, tree, transport_request):
# For the time being, there is only one valid way
Expand Down Expand Up @@ -168,35 +215,6 @@ def _populate_tree(self, transport_request):

return tree

@api.model
def _create_initial_node(self, tree, partner, date):
durable_storable = True
return tree.create_node(
tag=f"{partner.joint_buying_code}-{date}-{durable_storable}",
data=SimpleNamespace(
partner=partner,
date=date,
durable_storable=durable_storable,
line=False,
),
)

@api.model
def _create_following_node(self, tree, parent, line, destination):
partner = line.arrival_point_id
date = line.arrival_date
durable_storable = (
line.arrival_point_id == destination
or line.arrival_point_id.joint_buying_is_durable_storage
)
return tree.create_node(
parent=parent,
tag=f"{partner.joint_buying_code}-{date}-{durable_storable}-{line.id}",
data=SimpleNamespace(
partner=partner, date=date, durable_storable=durable_storable, line=line
),
)

@api.model
def _get_interesting_route(self, tour, from_line, destination, excludes):
# we try to go the destination
Expand Down Expand Up @@ -228,7 +246,3 @@ def _get_interesting_route(self, tour, from_line, destination, excludes):
to_select = True
result.reverse()
return result

def button_apply(self):
self.ensure_one()
self.transport_request_id._set_tour_lines(self.tour_line_ids)

0 comments on commit 46f8ffb

Please sign in to comment.