Skip to content

Commit

Permalink
[IMP] add new 'Loaded Weight' and 'Loaded Amount Untaxed' on joint.bu…
Browse files Browse the repository at this point in the history
…ying.tour model. Add graph and pivot view to display the new values
  • Loading branch information
legalsylvain committed Apr 5, 2024
1 parent 8e37957 commit 49f1c14
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 21 deletions.
40 changes: 30 additions & 10 deletions joint_buying_base/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-05 08:43+0000\n"
"PO-Revision-Date: 2024-04-05 08:43+0000\n"
"POT-Creation-Date: 2024-04-05 10:18+0000\n"
"PO-Revision-Date: 2024-04-05 10:18+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -16,7 +16,7 @@ msgstr ""
"Plural-Forms: \n"

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:260
#: code:addons/joint_buying_base/models/joint_buying_tour.py:288
#, python-format
msgid "%s (copy)"
msgstr "%s (copie)"
Expand All @@ -32,19 +32,19 @@ msgid "<b>Company Address:</b>"
msgstr "<b>Adresse de la société:</b>"

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:191
#: code:addons/joint_buying_base/models/joint_buying_tour.py:205
#, python-format
msgid "<i>Delivery and pick-up</i>"
msgstr "<i>Livraison et retrait</i>"

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:187
#: code:addons/joint_buying_base/models/joint_buying_tour.py:201
#, python-format
msgid "<i>Truck loading</i>"
msgstr "<i>Chargement du camion</i>"

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:189
#: code:addons/joint_buying_base/models/joint_buying_tour.py:203
#, python-format
msgid "<i>Truck unloading</i>"
msgstr "<i>Déchargement du camion</i>"
Expand All @@ -65,7 +65,7 @@ msgid "<span class=\"oe_inline\"> ( On </span>"
msgstr "<span class=\"oe_inline\"> ( Dans </span>"

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:184
#: code:addons/joint_buying_base/models/joint_buying_tour.py:198
#, python-format
msgid "<span style='color: green'><b>Pause</b></span>"
msgstr ""
Expand Down Expand Up @@ -102,7 +102,17 @@ msgstr "<strong>Durée</strong>"

#. module: joint_buying_base
#: model_terms:ir.ui.view,arch_db:joint_buying_base.report_joint_buying_tour_document
msgid "<strong>Payload (kg)</strong>"
msgid "<strong>Loaded Amount Untaxed</strong>"
msgstr "Montant HT chargé"

#. module: joint_buying_base
#: model_terms:ir.ui.view,arch_db:joint_buying_base.report_joint_buying_tour_document
msgid "<strong>Loaded Weight</strong>"
msgstr "Poids chargé"

#. module: joint_buying_base
#: model_terms:ir.ui.view,arch_db:joint_buying_base.report_joint_buying_tour_document
msgid "<strong>Payload</strong>"
msgstr "<strong>Charge Utile (kg)</strong>"

#. module: joint_buying_base
Expand Down Expand Up @@ -516,7 +526,7 @@ msgid "Distance"
msgstr ""

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:125
#: code:addons/joint_buying_base/models/joint_buying_tour.py:139
#, python-format
msgid "Draft Tour"
msgstr "Tournée en brouillon"
Expand Down Expand Up @@ -852,7 +862,7 @@ msgid "Journey"
msgstr "Trajet"

#. module: joint_buying_base
#: code:addons/joint_buying_base/models/joint_buying_tour.py:179
#: code:addons/joint_buying_base/models/joint_buying_tour.py:193
#, python-format
msgid "Journey from %s to %s"
msgstr "Trajet de %s à %s"
Expand Down Expand Up @@ -921,6 +931,16 @@ msgstr "Ligne"
msgid "Load"
msgstr "Charger"

#. module: joint_buying_base
#: model:ir.model.fields,field_description:joint_buying_base.field_joint_buying_tour__loaded_amount_untaxed
msgid "Loaded Amount Untaxed"
msgstr "Montant HT chargé"

#. module: joint_buying_base
#: model:ir.model.fields,field_description:joint_buying_base.field_joint_buying_tour__loaded_weight
msgid "Loaded Weight"
msgstr "Poids chargé"

#. module: joint_buying_base
#: model_terms:ir.ui.view,arch_db:joint_buying_base.report_joint_buying_tour_document_request_lines
msgid "Loading"
Expand Down
28 changes: 28 additions & 0 deletions joint_buying_base/models/joint_buying_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from odoo import _, api, fields, models

from odoo.addons import decimal_precision as dp

from .res_partner import _JOINT_BUYING_PARTNER_CONTEXT


Expand Down Expand Up @@ -100,6 +102,18 @@ class JointBuyingTour(models.Model):
" passes through the current company.",
)

loaded_weight = fields.Float(
compute="_compute_loaded_data",
digits=dp.get_precision("Stock Weight"),
store=True,
)

loaded_amount_untaxed = fields.Float(
compute="_compute_loaded_data",
digits=dp.get_precision("Product Price"),
store=True,
)

@api.onchange("type_id")
def _onchange_type_id(self):
if self.type_id and self.type_id.carrier_id:
Expand Down Expand Up @@ -228,6 +242,20 @@ def _compute_points(self):
tour.starting_point_id = journey_lines[0].starting_point_id
tour.arrival_point_id = journey_lines[-1].arrival_point_id

@api.depends(
"line_ids.transport_request_line_ids.request_id.total_weight",
"line_ids.transport_request_line_ids.request_id.amount_untaxed",
)
def _compute_loaded_data(self):
for tour in self:
requests = tour.mapped("line_ids.transport_request_line_ids.request_id")
data = requests.search_read(
domain=[("id", "in", requests.ids)],
fields=["total_weight", "amount_untaxed"],
)
tour.loaded_weight = sum([x["total_weight"] for x in data])
tour.loaded_amount_untaxed = sum([x["amount_untaxed"] for x in data])

@api.depends("line_ids.starting_point_id", "line_ids.arrival_point_id")
def _compute_is_on_my_way(self):
current_partner = self.env.user.company_id.joint_buying_partner_id
Expand Down
29 changes: 20 additions & 9 deletions joint_buying_base/reports/report_joint_buying_tour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,37 @@
<span t-field="doc.name"/>
</h2>

<div class="row mt32 mb32" id="informations">
<div class="col-auto mw-100 mb-2">
<div class="row mt16">
<div class="w-50">
<strong>Starting Point</strong>
<p class="m-0" t-field="doc.starting_point_id.name"/>
</div>
<div class="col-auto mw-100 mb-2">
<div class="w-25">
<strong>Start Date</strong>
<p class="m-0" t-field="doc.start_date"/>
</div>
<div class="col-auto mw-100 mb-2">
<div class="w-25">
<strong>Payload</strong>
<p class="m-0"><span t-esc="doc.carrier_id.payload"/> kg</p>
</div>
</div>

<div class="row mt16 mb16">
<div class="w-25">
<strong>Duration</strong>
<p class="m-0" t-esc="doc.display_time(doc.duration)"/>
</div>
<div class="col-auto mw-100 mb-2">
<div class="w-25">
<strong>Distance</strong>
<p class="m-0" t-field="doc.distance"/>
<p class="m-0"><span t-esc="doc.distance"/> km</p>
</div>
<div class="w-25">
<strong>Loaded Weight</strong>
<p class="m-0"><span t-esc="doc.loaded_weight"/> kg</p>
</div>
<div class="col-auto mw-100 mb-2">
<strong>Payload (kg)</strong>
<p class="m-0" t-esc="doc.carrier_id.payload"/>
<div class="w-25">
<strong>Loaded Amount Untaxed</strong>
<p class="m-0"><span t-esc="doc.loaded_amount_untaxed"/> €</p>
</div>
</div>

Expand Down
30 changes: 28 additions & 2 deletions joint_buying_base/views/view_joint_buying_tour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="arrival_point_id" attrs="{'invisible': [('is_loop', '=', True)]}"/>
<field name="duration" widget="float_time"/>
<field name="distance"/>
<field name="loaded_weight"/>
<field name="loaded_amount_untaxed"/>
<field name="stop_qty"/>
<field name="cost"/>
</group>
Expand Down Expand Up @@ -161,12 +163,36 @@ There may be traffic jams, delays, unforeseen events, etc...
</field>
</record>

<record id="view_joint_buying_tour_pivot" model="ir.ui.view">
<field name="model">joint.buying.tour</field>
<field name="arch" type="xml">
<pivot>
<field name="start_date" interval="month" type="row"/>
<field name="carrier_id" type="col"/>
<field name="loaded_weight" type="measure"/>
<field name="loaded_amount_untaxed" type="measure"/>
</pivot>
</field>
</record>

<record id="view_joint_buying_tour_graph" model="ir.ui.view">
<field name="model">joint.buying.tour</field>
<field name="arch" type="xml">
<graph stacked="True">
<field name="start_date" type="row"/>
<field name="carrier_id" type="col"/>
<field name="loaded_weight" type="measure"/>
<field name="loaded_amount_untaxed" type="measure"/>
</graph>
</field>
</record>

<record id="action_joint_buying_tour_my" model="ir.actions.act_window">
<field name="name">My Tours</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">joint.buying.tour</field>
<field name="view_type">form</field>
<field name="view_mode">calendar,tree,form</field>
<field name="view_mode">calendar,tree,pivot,graph,form</field>
<field name="domain">[('is_on_my_way', '=', True)]</field>
</record>

Expand All @@ -182,7 +208,7 @@ There may be traffic jams, delays, unforeseen events, etc...
<field name="type">ir.actions.act_window</field>
<field name="res_model">joint.buying.tour</field>
<field name="view_type">form</field>
<field name="view_mode">calendar,tree,form</field>
<field name="view_mode">calendar,tree,pivot,graph,form</field>
</record>


Expand Down

0 comments on commit 49f1c14

Please sign in to comment.