Skip to content

Commit

Permalink
[WIIIIIIP] joint_buying_product : Add tour report
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 2, 2023
1 parent 2086ce6 commit 2c0c8a2
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 6 deletions.
7 changes: 7 additions & 0 deletions joint_buying_base/models/joint_buying_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,10 @@ def see_steps(self):
action["view_mode"] = "leaflet_map,tree,form"
action["domain"] = [("id", "in", steps.ids)]
return action

@api.multi
def display_time(self, time):
return (
f"{str(int(time)).rjust(2, '0')}"
f":{str(int((time % 1) * 60)).rjust(2, '0')}"
)
1 change: 1 addition & 0 deletions joint_buying_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"views/view_joint_buying_transport_request_line.xml",
"views/view_res_partner.xml",
"reports/report_joint_buying_purchase_order_grouped.xml",
"reports/report_joint_buying_tour.xml",
"reports/report.xml",
"data/ir_cron.xml",
"data/ir_config_parameter.xml",
Expand Down
7 changes: 4 additions & 3 deletions joint_buying_product/models/joint_buying_tour_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
class JointBuyingTourLine(models.Model):
_inherit = "joint.buying.tour.line"

transport_request_ids = fields.Many2many(
comodel_name="joint.buying.transport.request",
string="Transport Requests",
transport_request_line_ids = fields.One2many(
comodel_name="joint.buying.transport.request.line",
string="Transport Lines",
inverse_name="tour_line_id",
)

load = fields.Float(
Expand Down
5 changes: 3 additions & 2 deletions joint_buying_product/models/joint_buying_transport_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021-Today: GRAP (http://www.grap.coop)
# 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).

Expand Down Expand Up @@ -106,7 +106,8 @@ class JointBuyingTransportRequest(models.Model):

arrival_date = fields.Datetime(string="Arrival Date", readonly=True)

# Compute Section
manual_description = fields.Html()

@api.depends("origin_partner_id", "destination_partner_id", "start_date")
def _compute_name(self):
for request in self:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021-Today: GRAP (http://www.grap.coop)
# 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).

Expand Down Expand Up @@ -57,3 +57,15 @@ class JointBuyingTransportRequestLine(models.Model):
)

distance = fields.Float(related="tour_line_id.distance")

def get_report_information(self):
self.ensure_one()
if self.request_id.order_id:
order_lines = self.mapped("request_id.order_id.line_ids").filtered(
lambda x: x.qty != 0
)
return {
"all": [
(x.product_id, f"{x.qty} x {x.uom_id.name}") for x in order_lines
]
}
10 changes: 10 additions & 0 deletions joint_buying_product/reports/report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@
print_report_name="('%s - %s - Grouped Order (%s)' % (object.name, object.supplier_id.name, object.deposit_date)).replace('/', '_')"
/>

<report
id="action_report_joint_buying_tour"
string="Tour"
model="joint.buying.tour"
report_type="qweb-pdf"
file="joint_buying_product.report_joint_buying_tour"
name="joint_buying_product.report_joint_buying_tour"
print_report_name="('Tour %s' % (object.name)).replace('/', '_')"
/>

</odoo>
197 changes: 197 additions & 0 deletions joint_buying_product/reports/report_joint_buying_tour.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_joint_buying_tour_document_request_lines">
<t t-foreach="request_lines" t-as="request_line">
<tr>
<td>
<div style="background-color:#FFA;">
<h5>
<t>
<span t-esc="request_line.request_id.order_id.supplier_id.name"/>
</t>
<span style="font-weight:bold">
- For <t t-esc="request_line.request_id.destination_partner_id.joint_buying_code" />
</span>
<span style="color:#888;"
t-if="request_line.request_id.order_id and request_line.request_id.order_id.supplier_id != request_line.request_id.origin_partner_id">
(From <t t-esc="request_line.request_id.origin_partner_id.joint_buying_code" />)
</span>
<span style="color:#888;" id="total_weight">
<t t-esc="request_line.request_id.total_weight" /> kg
</span>
</h5>
</div>
<span style="margin:0px;font-size: 12px;line-height:12px;" >
<t t-set="all_infos" t-value="request_line.get_report_information()" />
<t t-foreach="all_infos.keys()" t-as="key">
<span t-if="all_infos[key]" style="display: block; clear:both;">
<t t-foreach="all_infos[key]" t-as="line_info">
<span t-esc="line_info[0].name"/>
<span style="color:#888;" t-esc="' (' + line_info[1] + ') '" />
</t>
</span>
</t>
</span>
</td>
</tr>
</t>
</template>

<template id="report_joint_buying_tour_document">
<t t-call="web.internal_layout">
<t t-set="doc" t-value="doc.with_context(lang=doc.starting_point_id.lang)" />
<!-- -->
<!-- Summary -->
<!-- -->
<div class="page">
<h2>
<span>Tour # </span>
<span t-field="doc.name"/>
</h2>

<div class="row mt32 mb32" id="informations">
<div class="col-auto mw-100 mb-2">
<strong>Starting Point</strong>
<p class="m-0" t-field="doc.starting_point_id.name"/>
</div>
<div class="col-auto mw-100 mb-2">
<strong>Start Date</strong>
<p class="m-0" t-field="doc.start_date"/>
</div>
<div class="col-auto mw-100 mb-2">
<strong>Duration</strong>
<p class="m-0" t-esc="doc.display_time(doc.duration)"/>
</div>
<div class="col-auto mw-100 mb-2">
<strong>Distance</strong>
<p class="m-0" t-field="doc.distance"/>
</div>
<div class="col-auto mw-100 mb-2">
<strong>Payload (kg)</strong>
<p class="m-0" t-esc="doc.carrier_id.payload"/>
</div>
</div>

<table class="table table-sm o_main_table">
<thead>
<tr>
<th class="text-center">Time</th>
<th class="text-left">Description</th>
<th class="text-center">Load</th>
<th class="text-center">Duration</th>
<th class="text-right">Distance</th>
</tr>
</thead>
<tbody>
<t t-foreach="doc.line_ids" t-as="line">
<tr>
<td class="text-center">
<span t-esc="doc.display_time(line.start_hour)"/> - <span t-esc="doc.display_time(line.arrival_hour)"/>
</td>
<td class="text-left">
<t t-if="line.sequence_type == 'journey'">
Journey to <span t-field="line.arrival_point_id.name"/>
</t>
<t t-elif="line.sequence_type =='handling'">
Handling
</t>
<t t-else="">
Pause
</t>
</td>
<td class="text-center">
<t t-if="line.sequence_type == 'journey'">
<t t-if="doc.carrier_id.payload != 0 and line.load > doc.carrier_id.payload">
<span style="text-decoration: underline;color:red;" t-esc="round(line.load)"/> kg
<span style="color:#888;">
(+<t t-esc="round((line.load - doc.carrier_id.payload) / doc.carrier_id.payload * 100)"/> %)
</span>
</t>
<t t-else="">
<span t-esc="round(line.load)"/> kg
</t>
</t>
</td>
<td class="text-center">
<span t-esc="doc.display_time(line.duration)"/>
</td>
<td class="text-right">
<t t-if="line.sequence_type == 'journey'">
<span t-esc="round(line.distance, 1)"/> km
</t>
</td>
</tr>
</t>
</tbody>
</table>
</div>


<h3>
0 / <span t-esc="doc.stop_qty + 1" /> -
<span t-field="doc.starting_point_id.name"/>
</h3>

<!-- -->
<!-- Detail for each line -->
<!-- -->
<t t-set="i" t-value="0"/>

<t t-foreach="doc.line_ids" t-as="tour_line">
<div class="page">
<t t-if="tour_line.sequence_type == 'journey'">
<t t-set="i" t-value="i+1"/>
<!-- -->
<!-- LOADING PART -->
<!-- -->

<t t-set="request_lines" t-value="tour_line.mapped('transport_request_line_ids').filtered(lambda x: x.start_action_type == 'loading').sorted(key=lambda r: (r.request_id.destination_partner_id.joint_buying_code, r.request_id.origin_partner_id.joint_buying_code))" />

<t t-if="request_lines">

<table class="table table-sm o_main_table">
<tbody>
<tr style="background-color:#EEE">
<th class="text-center" colspan="2"><h4>Loading</h4></th>
</tr>
<t t-call="joint_buying_product.report_joint_buying_tour_document_request_lines" />
</tbody>
</table>
</t>

<h3>
<span t-esc="i" /> / <span t-esc="doc.stop_qty + 1" /> -
<span t-field="tour_line.arrival_point_id.name"/>
</h3>

<!-- -->
<!-- UNLOADING PART -->
<!-- -->

<t t-set="request_lines" t-value="tour_line.mapped('transport_request_line_ids').filtered(lambda x: x.arrival_action_type == 'unloading').sorted(key=lambda r: (r.request_id.destination_partner_id.joint_buying_code, r.request_id.origin_partner_id.joint_buying_code))" />

<t t-if="request_lines">
<table class="table table-sm o_main_table">
<tbody>
<tr style="background-color:#EEE">
<th class="text-center" colspan="2"><h4>Unloading</h4></th>
</tr>
<t t-call="joint_buying_product.report_joint_buying_tour_document_request_lines" />
</tbody>
</table>
</t>
</t>
</div>
</t>
</t>
</template>

<template id="report_joint_buying_tour">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="joint_buying_product.report_joint_buying_tour_document" t-lang="doc.starting_point_id.lang"/>
</t>
</t>
</template>

</odoo>

0 comments on commit 2c0c8a2

Please sign in to comment.