-
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.
[REF] Move transport request into joint_buying_base module
- Loading branch information
1 parent
8764760
commit ad72527
Showing
30 changed files
with
359 additions
and
268 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
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
202 changes: 202 additions & 0 deletions
202
joint_buying_base/models/joint_buying_transport_request.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,202 @@ | ||
# Copyright (C) 2023-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 import api, fields, models | ||
|
||
from odoo.addons import decimal_precision as dp | ||
|
||
from .res_partner import _JOINT_BUYING_PARTNER_CONTEXT | ||
|
||
|
||
class JointBuyingTransportRequest(models.Model): | ||
_name = "joint.buying.transport.request" | ||
_description = "Joint Buying Transport Request" | ||
|
||
name = fields.Char(readonly=True, compute="_compute_name", store=True) | ||
|
||
state = fields.Selection( | ||
selection=[ | ||
("to_compute", "To Compute"), | ||
("computed", "Computed"), | ||
("not_computable", "Not Computable"), | ||
], | ||
required=True, | ||
readonly=True, | ||
default="to_compute", | ||
) | ||
|
||
manual_start_date = fields.Datetime( | ||
string="Start Date (Manual)", | ||
) | ||
|
||
start_date = fields.Datetime( | ||
string="Start Date", | ||
compute="_compute_start_date", | ||
store=True, | ||
) | ||
|
||
manual_origin_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
string="Origin (Manual)", | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
domain="[('is_joint_buying_stage', '=', True)]", | ||
) | ||
|
||
origin_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
compute="_compute_origin_partner_id", | ||
string="Origin", | ||
store=True, | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
) | ||
|
||
manual_destination_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
string="Destination (Manual)", | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
domain="[('is_joint_buying_stage', '=', True)]", | ||
) | ||
|
||
destination_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
compute="_compute_destination_partner_id", | ||
string="Destination", | ||
store=True, | ||
context=_JOINT_BUYING_PARTNER_CONTEXT, | ||
) | ||
|
||
manual_amount_untaxed = fields.Float( | ||
string="Untaxed Amount (Manual)", | ||
digits=dp.get_precision("Product Price"), | ||
) | ||
|
||
amount_untaxed = fields.Float( | ||
string="Untaxed Amount", | ||
compute="_compute_amount_untaxed", | ||
store=True, | ||
digits=dp.get_precision("Product Price"), | ||
) | ||
|
||
manual_total_weight = fields.Float( | ||
string="Weight (Manual)", | ||
digits=dp.get_precision("Stock Weight"), | ||
) | ||
|
||
total_weight = fields.Float( | ||
string="Weight", | ||
compute="_compute_weight", | ||
store=True, | ||
digits=dp.get_precision("Stock Weight"), | ||
) | ||
|
||
line_ids = fields.One2many( | ||
comodel_name="joint.buying.transport.request.line", | ||
string="Transport Lines", | ||
inverse_name="request_id", | ||
) | ||
|
||
arrival_date = fields.Datetime(string="Arrival Date", readonly=True) | ||
|
||
manual_description = fields.Html() | ||
|
||
def _get_depends_start_date(self): | ||
return ["manual_start_date"] | ||
|
||
def _get_depends_origin_partner_id(self): | ||
return ["manual_origin_partner_id"] | ||
|
||
def _get_depends_destination_partner_id(self): | ||
return ["manual_destination_partner_id"] | ||
|
||
def _get_depends_amount_untaxed(self): | ||
return ["manual_amount_untaxed"] | ||
|
||
def _get_depends_total_weight(self): | ||
return ["manual_total_weight"] | ||
|
||
@api.depends("origin_partner_id", "destination_partner_id", "start_date") | ||
def _compute_name(self): | ||
for request in self: | ||
request.name = ( | ||
f"{request.origin_partner_id.joint_buying_code}" | ||
f" -> {request.destination_partner_id.joint_buying_code}" | ||
f" ({request.start_date})" | ||
) | ||
|
||
@api.depends(lambda x: x._get_depends_start_date()) | ||
def _compute_start_date(self): | ||
for request in self: | ||
request.start_date = request.manual_start_date | ||
|
||
@api.depends(lambda x: x._get_depends_origin_partner_id()) | ||
def _compute_origin_partner_id(self): | ||
for request in self: | ||
request.origin_partner_id = request.manual_origin_partner_id | ||
|
||
@api.depends(lambda x: x._get_depends_destination_partner_id()) | ||
def _compute_destination_partner_id(self): | ||
for request in self: | ||
request.destination_partner_id = request.manual_destination_partner_id | ||
|
||
@api.depends(lambda x: x._get_depends_amount_untaxed()) | ||
def _compute_amount_untaxed(self): | ||
for request in self: | ||
request.amount_untaxed = request.manual_amount_untaxed | ||
|
||
@api.depends(lambda x: x._get_depends_total_weight()) | ||
def _compute_weight(self): | ||
for request in self: | ||
request.total_weight = request.manual_total_weight | ||
|
||
def _set_tour_lines(self, tour_lines): | ||
self.ensure_one() | ||
# If lines are valid | ||
if ( | ||
tour_lines | ||
and tour_lines[-1].arrival_point_id == self.destination_partner_id | ||
): | ||
line_vals = [] | ||
previous_tour_id = False | ||
for i, tour_line in enumerate(tour_lines): | ||
# Compute if it is a loading at the beginning of the tour line | ||
if previous_tour_id != tour_line.tour_id.id: | ||
start_action_type = "loading" | ||
else: | ||
start_action_type = "no" | ||
previous_tour_id = tour_line.tour_id.id | ||
|
||
# Compute if it is an unloading at the end of the tour line | ||
if i < len(tour_lines) - 1: | ||
if tour_line.tour_id != tour_lines[i + 1].tour_id: | ||
arrival_action_type = "unloading" | ||
else: | ||
arrival_action_type = "no" | ||
else: | ||
arrival_action_type = "unloading" | ||
line_vals.append( | ||
{ | ||
"start_action_type": start_action_type, | ||
"arrival_action_type": arrival_action_type, | ||
"tour_line_id": tour_line.id, | ||
} | ||
) | ||
|
||
vals = { | ||
"arrival_date": max(tour_lines.mapped("arrival_date")), | ||
"state": "computed", | ||
"line_ids": [(5,)] + [(0, 0, x) for x in line_vals], | ||
} | ||
else: | ||
vals = { | ||
"arrival_date": False, | ||
"state": "not_computable", | ||
"line_ids": [(5,)], | ||
} | ||
self.write(vals) | ||
|
||
def button_compute_tour(self): | ||
Wizard = self.env["joint.buying.wizard.find.route"] | ||
results = Wizard.compute_tours(self) | ||
for request in self: | ||
request._set_tour_lines(results[request][1]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<report | ||
id="action_report_joint_buying_tour" | ||
string="Tour" | ||
model="joint.buying.tour" | ||
report_type="qweb-pdf" | ||
file="joint_buying_base.report_joint_buying_tour" | ||
name="joint_buying_base.report_joint_buying_tour" | ||
print_report_name="('Tour %s' % (object.name)).replace('/', '_')" | ||
/> | ||
|
||
</odoo> |
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
Oops, something went wrong.