Skip to content

Commit 103c083

Browse files
committed
Merge branch '17.0' into 606-fix-farmer-registry-demo
2 parents eda56a5 + cf7a6b8 commit 103c083

File tree

26 files changed

+614
-155
lines changed

26 files changed

+614
-155
lines changed

spp_area/models/area_import.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,32 @@ def create_import_raw(self, vals, column_indexes, row, sheet):
202202
}
203203
)
204204

205+
def check_all_languages_activated(self, columns, area_level):
206+
"""Check if all languages in the specified columns are activated.
207+
208+
Args:
209+
columns (list): The list of column names to check.
210+
area_level (int): The administrative area level to check within the column names.
211+
212+
Raises:
213+
ValidationError: If any language is not active.
214+
"""
215+
self.ensure_one()
216+
prefix = f"ADM{area_level}_"
217+
active_langs = self.env["res.lang"].search([("active", "=", True)]).mapped("iso_code")
218+
219+
for col in columns:
220+
if col.startswith(prefix):
221+
lang = col.split("_", 1)[1]
222+
if len(lang) == 2 and lang.lower() not in active_langs:
223+
raise ValidationError(
224+
_(
225+
"Language with ISO Code %s is not active.\n"
226+
"Please request the administrator to enable the desired language."
227+
)
228+
% lang.upper()
229+
)
230+
205231
def import_data(self):
206232
"""
207233
The `import_data` function imports data from an Excel file, processes it, and updates the record
@@ -237,6 +263,8 @@ def import_data(self):
237263
# get column list of sheet
238264
columns = sheet.row_values(0)
239265

266+
rec.check_all_languages_activated(columns, area_level)
267+
240268
column_indexes = rec.get_column_indexes(columns, area_level)
241269

242270
# Get the required values for area in each row

spp_area/tests/test_area_import.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
22

3+
from odoo.exceptions import ValidationError
4+
35
from .common import AreaImportTestMixin
46

57
_logger = logging.getLogger(__name__)
@@ -17,8 +19,13 @@ def test_02_reset_to_uploaded(self):
1719
self.assertEqual(self.area_import_id.state, "Uploaded")
1820

1921
def test_03_import_data(self):
20-
self.area_import_id.import_data()
22+
with self.assertRaises(ValidationError):
23+
self.area_import_id.import_data()
2124

25+
lang = self.env["res.lang"].with_context(active_test=False).search([("iso_code", "=", "ar")])
26+
lang.active = True
27+
28+
self.area_import_id.import_data()
2229
raw_data_ids = self.area_import_id.raw_data_ids
2330

2431
self.assertEqual(len(raw_data_ids.ids), self.area_import_id.tot_rows_imported)
@@ -31,6 +38,12 @@ def test_03_import_data(self):
3138

3239
def test_04_validate_raw_data(self):
3340
# Greater than or equal to 400 rows
41+
with self.assertRaises(ValidationError):
42+
self.area_import_id.import_data()
43+
44+
lang = self.env["res.lang"].with_context(active_test=False).search([("iso_code", "=", "ar")])
45+
lang.active = True
46+
3447
self.area_import_id.import_data()
3548
self.area_import_id.validate_raw_data()
3649

@@ -63,6 +76,11 @@ def test_04_validate_raw_data(self):
6376

6477
def test_05_save_to_area(self):
6578
# Greater than or equal to 400 rows
79+
with self.assertRaises(ValidationError):
80+
self.area_import_id.import_data()
81+
lang = self.env["res.lang"].with_context(active_test=False).search([("iso_code", "=", "ar")])
82+
lang.active = True
83+
6684
self.area_import_id.import_data()
6785
self.area_import_id.save_to_area()
6886

spp_dashboard_base/__init__.py

Whitespace-only changes.

spp_dashboard_base/__manifest__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
2+
3+
4+
{
5+
"name": "OpenSPP Dashboard: Base",
6+
"category": "OpenSPP",
7+
"version": "17.0.1.0.0",
8+
"sequence": 1,
9+
"author": "OpenSPP.org",
10+
"website": "https://github.com/OpenSPP/openspp-modules",
11+
"license": "LGPL-3",
12+
"development_status": "Beta",
13+
"maintainers": ["reichie020212"],
14+
"depends": [
15+
"base",
16+
],
17+
"data": [],
18+
"assets": {
19+
"web.assets_backend": [
20+
"spp_dashboard_base/static/src/dashboard/**/*",
21+
"spp_dashboard_base/static/src/chart/**/*",
22+
"spp_dashboard_base/static/src/card_board/**/*",
23+
],
24+
},
25+
"demo": [],
26+
"images": [],
27+
"application": False,
28+
"installable": True,
29+
"auto_install": False,
30+
}

spp_dashboard_base/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
12.3 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @odoo-module **/
2+
3+
import {Component} from "@odoo/owl";
4+
5+
export class CardBoardComponent extends Component {}
6+
7+
CardBoardComponent.template = "spp_dashboard_base.CardBoardTemplate";
8+
CardBoardComponent.props = {
9+
title: {type: String, optional: true},
10+
data: {type: [String, Number], optional: true},
11+
size: {type: String, optional: true},
12+
};
13+
CardBoardComponent.defaultProps = {
14+
title: "Title",
15+
data: "Data",
16+
size: "col-md-4",
17+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates>
3+
<t t-name="spp_dashboard_base.CardBoardTemplate">
4+
<div t-att-class="props.size" style="padding-top: 30px;">
5+
<div
6+
class="oh-card"
7+
style="box-shadow: 2px 4px 8px 2px rgba(0, 0, 0, 0.2); display: flex; justify-content: center; align-items: center; height: 100px;"
8+
role="button"
9+
>
10+
<div class="oh-card-body" style="padding: 5px; width: 100%; box-sizing: border-box;">
11+
<div
12+
class="stat-widget-one"
13+
style="display: flex; justify-content: center; align-items: center; height: 100%;"
14+
>
15+
<div class="stat_content" style="text-align: center; font-weight: bold;">
16+
<div style="font-size: 17px;">
17+
<t t-esc="props.data" />
18+
</div>
19+
<div class="stat-head" style="font-size: 14px;"><t t-esc="props.title" /></div>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
</t>
26+
</templates>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/** @odoo-module **/
2+
3+
import {Component, onMounted, onWillStart, useRef} from "@odoo/owl";
4+
import {loadBundle} from "@web/core/assets";
5+
6+
export class ChartComponent extends Component {
7+
setup() {
8+
onMounted(() => this.renderChart());
9+
this.canvasRef = useRef("canvas");
10+
11+
this.chartTitle = "";
12+
const chartTypesWithTitle = ["pie", "doughnut"];
13+
if (chartTypesWithTitle.includes(this.props.chart_type)) {
14+
this.chartTitle = this.props.data_label;
15+
}
16+
17+
onWillStart(async () => {
18+
return Promise.all([
19+
// Load external JavaScript and CSS libraries.
20+
loadBundle({
21+
jsLibs: [
22+
// "/awesome_dashboard/static/lib/chart-js.4.4.4/chart.umd.min.js",
23+
"https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.min.js",
24+
],
25+
}),
26+
]);
27+
});
28+
}
29+
30+
renderChart() {
31+
const ctx = this.canvasRef.el.getContext("2d");
32+
33+
new Chart(ctx, {
34+
type: this.props.chart_type,
35+
data: {
36+
labels: this.props.labels,
37+
datasets: [
38+
{
39+
label: this.props.data_label,
40+
data: this.props.data,
41+
backgroundColor: this.props.backgroundColor,
42+
hoverOffset: 2,
43+
},
44+
],
45+
},
46+
options: {...this.props.options},
47+
});
48+
}
49+
}
50+
51+
ChartComponent.template = "spp_dashboard_base.ChartComponentTemplate";
52+
ChartComponent.props = {
53+
chart_type: {type: String, optional: true},
54+
labels: {type: Array, optional: true},
55+
data_label: {type: String, optional: true},
56+
data: {type: Array, optional: true},
57+
backgroundColor: {type: Array, optional: true},
58+
options: {type: Object, optional: true},
59+
size: {type: String, optional: true},
60+
};
61+
ChartComponent.defaultProps = {
62+
chart_type: "pie",
63+
labels: ["Red", "Blue", "Yellow"],
64+
data_label: "Number of Colors",
65+
data: [300, 50, 150],
66+
backgroundColor: ["rgb(255, 99, 132)", "rgb(54, 162, 235)", "rgb(255, 205, 86)"],
67+
options: {
68+
maintainAspectRatio: true,
69+
aspectRatio: 2,
70+
},
71+
size: "col-md-6",
72+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates>
3+
<t t-name="spp_dashboard_base.ChartComponentTemplate">
4+
<style>
5+
.pie-chart-container {
6+
border: 2px solid #000;
7+
border-radius: 10px;
8+
margin-top : 2em;
9+
}
10+
</style>
11+
<div class="container" t-att-class="props.size">
12+
<div class="pie-chart-container">
13+
<h3 style="text-align: center;"><t t-esc="chartTitle" /></h3>
14+
<canvas id="myChart" t-ref="canvas" />
15+
</div>
16+
</div>
17+
</t>
18+
</templates>

0 commit comments

Comments
 (0)