Skip to content

Commit

Permalink
[REM] volume by product category
Browse files Browse the repository at this point in the history
(not needed anymore by the client)
  • Loading branch information
victor-champonnois committed Mar 14, 2024
1 parent 01162db commit 5582c73
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 171 deletions.
1 change: 0 additions & 1 deletion sale_order_volume/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"views/shopping_cart.xml",
"reports/report_saleorder.xml",
"views/res_config_settings_views.xml",
"security/ir.model.access.csv",
],
"demo": ["demo/demo.xml"],
"installable": True,
Expand Down
1 change: 0 additions & 1 deletion sale_order_volume/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import product_category_volume
from . import res_config_settings
from . import sale_order_line
from . import sale_order
16 changes: 0 additions & 16 deletions sale_order_volume/models/product_category_volume.py

This file was deleted.

54 changes: 0 additions & 54 deletions sale_order_volume/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# © 2016 Robin Keunen, Coop IT Easy SCRL.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from collections import defaultdict

from odoo import api, fields, models

Expand All @@ -25,12 +24,6 @@ class SaleOrder(models.Model):
string="Order # Pallets", compute="_compute_order_volume", store=True
)

volume_per_category = fields.One2many(
comodel_name="product.category.volume",
inverse_name="sale_order_id",
string="Volume per Product Category",
)

@api.depends("order_line", "order_line.volume")
def _compute_order_volume(self):

Expand All @@ -52,50 +45,3 @@ def get_default_pallet_volume(self):
.get_param("sale_order_volume.pallet_volume")
or 0
)

def compute_order_product_category_volumes(self):
self.ensure_one()

order_lines = self.order_line.filtered(lambda ol: ol.state not in ["cancel"])

volume_per_category = defaultdict(float)
for order_line in order_lines:
category_id = order_line.product_id.categ_id.id
volume_per_category[category_id] += order_line.volume

existing_categories = {
vpc.category_id.id: vpc for vpc in self.volume_per_category
}

for category_id, volume in volume_per_category.items():
pallet_count = _compute_pallet_count(
volume, float(self.get_default_pallet_volume())
)
# TODO: what if there is an existing category_id of which no
# products are in the order anymore?
if category_id in existing_categories:
existing_categories[category_id].volume = volume
existing_categories[category_id].pallet_count = pallet_count
else:
vals = {
"sale_order_id": self.id,
"category_id": category_id,
"volume": volume,
"pallet_count": pallet_count,
}
self.env["product.category.volume"].create(vals)

return self.volume_per_category

def compute_product_category_volumes(self):
for order in self:
order.compute_order_product_category_volumes()

def write(self, values):
ret = super(SaleOrder, self).write(values)
# fixme : don't put this in write, because it does not update
# the volume by category directly when changing the SO lines.
# with Odoo 16 and the "invisible save" flow, it's disturbing.
# use a computed field instead.
self.compute_product_category_volumes()
return ret
2 changes: 1 addition & 1 deletion sale_order_volume/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Computes the volume of products (and its corresponding number of pallets) per category ordered and display it on
Computes the volume of products (and its corresponding number of pallets) ordered and display it on

- sale order page,
- sale order report,
Expand Down
50 changes: 17 additions & 33 deletions sale_order_volume/reports/report_saleorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,23 @@
inherit_id="sale.report_saleorder_document"
>
<div name="total" position="after">
<table class="table table-condensed" name="volume-per-category">
<thead>
<tr>
<th>Category</th>
<th class="text-right">Volume (m³)</th>
<th class="text-right"># Pallets</th>
</tr>
</thead>
<tbody class="sale_tbody">
<t t-foreach="doc.volume_per_category" t-as="line">
<tr>
<td>
<span t-field="line.category_id" />
</td>
<td class="text-right">
<span t-field="line.volume" />
</td>
<td class="text-right">
<span t-field="line.pallet_count" />
</td>
</tr>
</t>
<tr class="border-black">
<td>
<strong>Total</strong>
</td>
<td class="text-right">
<strong>
<span t-field="doc.volume" />
</strong>
</td>
</tr>
</tbody>
<table name="volume" class="table table-condensed">

<tr id="order_total_volume">
<td><strong>Volume (m³)</strong></td>
<td>
<span t-field="doc.pallet_count" />
</td>
</tr>
<tr id="order_pallets">
<td><strong># Pallets (1 pallet = <t
t-out="doc.get_default_pallet_volume()"
/> m³)</strong></td>
<td>
<span t-field="doc.volume" />
</td>
</tr>

</table>
</div>
</template>
Expand Down
3 changes: 0 additions & 3 deletions sale_order_volume/security/ir.model.access.csv

This file was deleted.

16 changes: 2 additions & 14 deletions sale_order_volume/tests/test_sale_order_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,11 @@ class SaleOrderVolumeCase(TransactionCase):
def test_sale_order_volumes(self):
sale_order = self.browse_ref("sale.sale_order_4")
product = self.browse_ref("product.product_delivery_01")
service_cat = self.browse_ref("product.product_category_3")
office_furniture_cat = self.browse_ref("product.product_category_5")

# trigger
order_line = sale_order.order_line.filtered(lambda ol: ol.product_id == product)
order_line.product_uom_qty = 3

# assert
service_volume = sale_order.volume_per_category.filtered(
lambda vpc: vpc.category_id == service_cat
)
office_furniture_volume = sale_order.volume_per_category.filtered(
lambda vpc: vpc.category_id == office_furniture_cat
)

self.assertEqual(service_volume.volume, 0)
self.assertEqual(service_volume.pallet_count, 0)
self.assertEqual(office_furniture_volume.volume, 15.6)
self.assertEqual(sale_order.volume, 15.6)
# (15.6 (volume) // 1.75 (pallet volume)) + 1 = 9
self.assertEqual(office_furniture_volume.pallet_count, 9)
self.assertEqual(sale_order.pallet_count, 9)
8 changes: 0 additions & 8 deletions sale_order_volume/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
<field name="volume" />
<field name="pallet_count" />
</group>
<group>
<field name="volume_per_category">
<tree name="volume_per_category">
<field name="category_id" />
<field name="volume" />
</tree>
</field>
</group>
</page>
</xpath>
</field>
Expand Down
71 changes: 31 additions & 40 deletions sale_order_volume/views/shopping_cart.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<template id="volume_per_category">
<template id="cart_volume">
<div
id="cart_volume_per_category"
id="cart_volume"
t-att-class="extra_class or ''"
t-if="website_sale_order and website_sale_order.website_order_line"
>
<table class="table">
<thead>
<tr>
<th class="col-md-2 col-3 noborder">Volume (m³)</th>
<th class="col-md-2 col-3 noborder"># Pallets</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-xl-left noborder">
<span
t-field="website_sale_order.volume"
style="white-space: nowrap;"
/>
</td>

<td class="text-xl-right noborder">
<span
t-field="website_sale_order.pallet_count"
style="white-space: nowrap;"
/>
</td>

</tr>
</tbody>
</table>
<p id="pallet_footnote"><i>1 pallet = <t
<tr id="order_total_volume">
<td class="text-end border-0">Volume (m³)</td>
<td class="text-xl-end border-0">
<span
t-field="website_sale_order.volume"
style="white-space: nowrap;"
/>
</td>
</tr>
<tr id="order_pallets">
<td class="text-end border-0"># Pallets (1 pallet = <t
t-out="website_sale_order.get_default_pallet_volume()"
/> m³</i></p>
/> m³)</td>
<td class="text-xl-end border-0">
<span
t-field="website_sale_order.pallet_count"
style="white-space: nowrap;"
/>
</td>
</tr>

</div>
</template>

<template id="short_cart_summary" inherit_id="website_sale.short_cart_summary">
<div class="card-body" position="after">
<div class="card-body">
<h4 class="d-none d-xl-block">Order Volume</h4>
<div>
<t t-call="sale_order_volume.volume_per_category">
</t>
</div>
</div>
</div>
<template id="volume_total" inherit_id="website_sale.total">
<xpath expr="//div[@id='cart_total']//table/tr[last()]" position="after">
<tr id="order_total_volume">
<td class="text-xl-end border-0">
<t t-call="sale_order_volume.cart_volume">
</t>
</td>
</tr>
</xpath>
</template>
</odoo>

0 comments on commit 5582c73

Please sign in to comment.