Skip to content

Commit

Permalink
Merge PR #83 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Dec 19, 2023
2 parents c368739 + 3ddf748 commit f55a5be
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 20 deletions.
5 changes: 5 additions & 0 deletions joint_buying_base/data/ir_config_parameter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
<field name="value">Your Group Name</field>
</record>

<record id="parameter_tour_max_duration" model="ir.config_parameter">
<field name="key">joint_buying_base.tour_max_duration</field>
<field name="value">56</field>
</record>

</odoo>
12 changes: 12 additions & 0 deletions joint_buying_base/demo/joint_buying_transport_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
]]></field>
</record>

<record id="request_vev_lse_week_1" model="joint.buying.transport.request">
<field name="manual_start_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_VEV').joint_buying_partner_id.id"/>
<field name="manual_arrival_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_LSE').joint_buying_partner_id.id"/>
<field name="manual_availability_date" eval="(DateTime.today() + timedelta(days=1)).strftime('%Y-%m-%d 07:01')"/>
<field name="manual_amount_untaxed">111</field>
<field name="manual_total_weight">22</field>
<field name="manual_description"><![CDATA[
Products that should be taken in VEV, because it is available after
the begining of the tour, but before the truck pass over VEV
]]></field>
</record>

<record id="request_vev_fumet_dombes_week_1" model="joint.buying.transport.request">
<field name="manual_start_partner_id" model="res.partner" eval="obj().env.ref('joint_buying_base.company_VEV').joint_buying_partner_id.id"/>
<field name="manual_arrival_partner_id" ref="joint_buying_base.supplier_fumet_dombes"/>
Expand Down
72 changes: 60 additions & 12 deletions joint_buying_base/tests/test_joint_buying_wizard_find_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import timedelta

from odoo.tests import tagged

Expand All @@ -10,11 +11,20 @@

@tagged("post_install", "-at_install", "find_route")
class TestJointBuyingWizardFindRoute(TestAbstract):
def setUp(self):
super().setUp()
self.IrConfigParameter = self.env["ir.config_parameter"].sudo()
self.max_duration = int(
self.IrConfigParameter.get_param("joint_buying_base.tour_max_duration", 0)
)

def test_20_transport_request_vev_cda_week_1(self):
"""simplest case: direct route"""
self._verify_tour_lines_computation(
"joint_buying_base.request_vev_cda_week_1",
["joint_buying_base.tour_lyon_loire_1_line_4"],
[
"joint_buying_base.tour_lyon_loire_1_line_4", # VEV->CDA
],
"computed",
)

Expand All @@ -23,10 +33,10 @@ def test_21_transport_request_vev_che_week_1(self):
self._verify_tour_lines_computation(
"joint_buying_base.request_vev_che_week_1",
[
"joint_buying_base.tour_lyon_loire_1_line_4",
"joint_buying_base.tour_lyon_loire_1_line_6",
"joint_buying_base.tour_lyon_drome_1_line_2",
"joint_buying_base.tour_lyon_drome_1_line_4",
"joint_buying_base.tour_lyon_loire_1_line_4", # VEV->CDA
"joint_buying_base.tour_lyon_loire_1_line_6", # CDA->LSE
"joint_buying_base.tour_lyon_drome_1_line_2", # LSE->C3P
"joint_buying_base.tour_lyon_drome_1_line_4", # C3P->CHE
],
"computed",
)
Expand All @@ -36,10 +46,10 @@ def test_22_transport_request_vev_edc_1(self):
self._verify_tour_lines_computation(
"joint_buying_base.request_vev_edc_week_1",
[
"joint_buying_base.tour_lyon_loire_1_line_4",
"joint_buying_base.tour_lyon_loire_1_line_6",
"joint_buying_base.tour_lyon_savoie_1_line_2",
"joint_buying_base.tours_savoie_1_line_2",
"joint_buying_base.tour_lyon_loire_1_line_4", # VEV->CDA
"joint_buying_base.tour_lyon_loire_1_line_6", # CDA->LSE
"joint_buying_base.tour_lyon_savoie_1_line_2", # LSE->Cognin
"joint_buying_base.tours_savoie_1_line_2", # Cognin->EDC
],
"computed",
)
Expand All @@ -55,13 +65,51 @@ def test_24_transport_request_vev_che_week_2(self):
self._verify_tour_lines_computation(
"joint_buying_base.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",
"joint_buying_base.tour_lyon_loire_3_line_2", # VEV->LSE
"joint_buying_base.tour_lyon_drome_2_line_2", # LSE->C3P
"joint_buying_base.tour_lyon_drome_2_line_4", # C3P->CHE
],
"computed",
)

def test_25_transport_request_vev_lse_week_1(self):
"""Complex case: product availability is after the truck has left,
but before it passes through"""
self._verify_tour_lines_computation(
"joint_buying_base.request_vev_lse_week_1",
[
"joint_buying_base.tour_lyon_loire_1_line_4", # VEV->CDA
"joint_buying_base.tour_lyon_loire_1_line_6", # CDA->LSE
],
"computed",
)

def test_26_transport_request_vev_cda_week_1(self):
"""Simple case: Check maximum duration to deliver"""
request = self.env.ref("joint_buying_base.request_vev_lse_week_1")
tour = self.env.ref("joint_buying_base.tour_lyon_loire_1")

# Max duration - 1 should success
request.manual_availability_date = tour.start_date - timedelta(
days=self.max_duration - 1
)
self._verify_tour_lines_computation(
"joint_buying_base.request_vev_lse_week_1",
[
"joint_buying_base.tour_lyon_loire_1_line_4", # VEV->CDA
"joint_buying_base.tour_lyon_loire_1_line_6", # CDA->LSE
],
"computed",
)

# Max duration + 1 should fail
request.manual_availability_date = tour.start_date - timedelta(
days=self.max_duration + 1
)
self._verify_tour_lines_computation(
"joint_buying_base.request_vev_lse_week_1", [], "not_computable"
)

def _verify_tour_lines_computation(
self, request_xml_id, tour_line_xml_ids, expected_state
):
Expand Down
12 changes: 7 additions & 5 deletions joint_buying_base/wizards/joint_buying_wizard_find_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class JointBuyingWizardFindRoute(models.TransientModel):
_name = "joint.buying.wizard.find.route"
_description = "Joint Buying Wizard Find Route"

# 30 Days
_MAX_TRANSPORT_DURATION = 30

transport_request_id = fields.Many2one(
string="Transport Request",
comodel_name="joint.buying.transport.request",
Expand Down Expand Up @@ -201,12 +198,17 @@ def get_nodes_optimal_road(self, tree, arrival_partner_id):
@api.model
def _populate_tree(self, transport_request):
# Get all the tours subsequent to the transport request for a given period of time
max_duration = int(
self.env["ir.config_parameter"]
.sudo()
.get_param("joint_buying_base.tour_max_duration", 0)
)
max_date = transport_request.availability_date + datetime.timedelta(
days=self._MAX_TRANSPORT_DURATION
days=max_duration
)
tours = self.env["joint.buying.tour"].search(
[
("start_date", ">=", transport_request.availability_date),
("end_date", ">=", transport_request.availability_date),
("start_date", "<=", max_date),
],
order="start_date",
Expand Down
7 changes: 4 additions & 3 deletions joint_buying_product/migrations/12.0.4.0.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def migrate(env, version):
partners.write({"joint_buying_is_durable_storage": True})

# Create Transport Requests for recent joint buying purchase orders
min_deposit_date = datetime.today() + timedelta(
days=-env["joint.buying.wizard.find.route"]._MAX_TRANSPORT_DURATION
)
icp = env["ir.config_parameter"].sudo()
max_duration = int(icp.get_param("joint_buying_base.tour_max_duration", 0))

min_deposit_date = datetime.today() + timedelta(days=-max_duration)
orders = (
env["joint.buying.purchase.order.grouped"]
.search([("deposit_date", ">", min_deposit_date.strftime("%Y-%m-%d %H:%M"))])
Expand Down

0 comments on commit f55a5be

Please sign in to comment.