Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions spp_drims/data/config_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<field name="value">4</field>
</record>

<record id="default_sla_hours_high" model="ir.config_parameter">
<field name="key">drims.sla.hours.high</field>
<record id="default_sla_hours_urgent" model="ir.config_parameter">
<field name="key">drims.sla.hours.urgent</field>
<field name="value">8</field>
</record>

Expand All @@ -22,11 +22,6 @@
<field name="value">24</field>
</record>

<record id="default_sla_hours_low" model="ir.config_parameter">
<field name="key">drims.sla.hours.low</field>
<field name="value">48</field>
</record>

<record id="default_sla_warning_threshold_pct" model="ir.config_parameter">
<field name="key">drims.sla.warning_threshold_pct</field>
<field name="value">75</field>
Expand Down
59 changes: 47 additions & 12 deletions spp_drims/models/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,59 @@
"""
DRIMS Constants

This module defines vocabulary namespace URIs and other constants used across
the DRIMS module. Using constants ensures consistency and makes URIs easier
to maintain.
Vocabulary namespace URIs and the code values within them, used across the DRIMS
module so that neither has to be written as a bare string.

**Every code constant is named after the code it holds.** Four constants used to
be named for a concept that had no matching code in the shipped vocabulary data
(``PRIORITY_LOW``/``MEDIUM``/``HIGH`` and ``DRIMS_TYPE_TRANSFER``), so anything
comparing against them silently never matched — a ``search`` for a non-existent
code returns an empty set rather than raising. Mirroring the code in the name
removes the guesswork (OP#1165).

``CODE_NAMESPACES`` at the bottom records which vocabulary each group of code
constants belongs to. ``spp_drims/tests/test_constants.py`` walks it and asserts
every constant resolves to a real ``spp.vocabulary.code``, so a typo or a renamed
code fails the build instead of quietly never matching. Add new groups there.
"""

# Vocabulary Namespace Base URI
VOCAB_BASE = "urn:openspp:vocab:drims"

# Vocabulary Namespace URIs
VOCAB_AGENCY_TYPES = f"{VOCAB_BASE}:agency-types"
VOCAB_ALERT_TYPES = f"{VOCAB_BASE}:alert-types"
VOCAB_DONOR_TYPES = f"{VOCAB_BASE}:donor-types"
VOCAB_COORDINATION_MODES = f"{VOCAB_BASE}:coordination-modes"
VOCAB_DISTRIBUTION_TYPES = f"{VOCAB_BASE}:distribution-types"
VOCAB_DONATION_STATES = f"{VOCAB_BASE}:donation-states"
VOCAB_DONOR_TYPES = f"{VOCAB_BASE}:donor-types"
VOCAB_DRIMS_TYPES = f"{VOCAB_BASE}:drims-types"
VOCAB_HAZARD_TYPES = f"{VOCAB_BASE}:hazard-types"
VOCAB_ITEM_CATEGORIES = f"{VOCAB_BASE}:item-categories"
VOCAB_ITEM_CONDITIONS = f"{VOCAB_BASE}:item-conditions"
VOCAB_ITEM_DISPOSITIONS = f"{VOCAB_BASE}:item-dispositions"
VOCAB_ORGANIZATION_ROLES = f"{VOCAB_BASE}:organization-roles"
VOCAB_PERSONNEL_ROLES = f"{VOCAB_BASE}:personnel-roles"
VOCAB_POD_STATUSES = f"{VOCAB_BASE}:pod-statuses"
VOCAB_PRIORITY_LEVELS = f"{VOCAB_BASE}:priority-levels"
VOCAB_REQUEST_STATES = f"{VOCAB_BASE}:request-states"
VOCAB_RESTRICTIONS = f"{VOCAB_BASE}:restrictions"
VOCAB_RETURN_CONDITIONS = f"{VOCAB_BASE}:return-conditions"
VOCAB_RETURN_REASONS = f"{VOCAB_BASE}:return-reasons"
VOCAB_TRANSPORT_MODES = f"{VOCAB_BASE}:transport-modes"
VOCAB_ITEM_CONDITIONS = f"{VOCAB_BASE}:item-conditions"
VOCAB_ITEM_DISPOSITIONS = f"{VOCAB_BASE}:item-dispositions"

# Common state codes
# Request state codes (spp.drims.request)
STATE_DRAFT = "draft"
STATE_SUBMITTED = "submitted"
STATE_APPROVED = "approved"
STATE_REJECTED = "rejected"
STATE_ALLOCATED = "allocated"
STATE_DISPATCHED = "dispatched"
STATE_DELIVERED = "delivered"
STATE_FULFILLED = "fulfilled"
STATE_CANCELLED = "cancelled"

# Donation state codes
# Donation state codes (spp.drims.donation)
DONATION_STATE_ANNOUNCED = "announced"
DONATION_STATE_RECEIVED = "received"
DONATION_STATE_INSPECTED = "inspected"
Expand All @@ -42,17 +65,29 @@
# DRIMS type codes (for stock.picking classification)
DRIMS_TYPE_DONATION_RECEIPT = "donation_receipt"
DRIMS_TYPE_REQUEST_DISPATCH = "request_dispatch"
DRIMS_TYPE_TRANSFER = "transfer"
DRIMS_TYPE_INTERNAL_TRANSFER = "internal_transfer"
DRIMS_TYPE_RETURN = "return"

# Alert type codes
ALERT_LOW_STOCK = "low_stock"
ALERT_EXPIRY = "expiry"
ALERT_SLA_BREACH = "sla_breach"
ALERT_SLA_WARNING = "sla_warning"
ALERT_CRITICAL_SHORTAGE = "critical_shortage"
ALERT_QUALITY_ISSUE = "quality_issue"

# Priority level codes
PRIORITY_LOW = "low"
PRIORITY_MEDIUM = "medium"
PRIORITY_HIGH = "high"
PRIORITY_ROUTINE = "routine"
PRIORITY_URGENT = "urgent"
PRIORITY_CRITICAL = "critical"

#: Which vocabulary each group of code constants draws from, keyed by the name
#: prefix. Walked by ``test_constants.py`` to prove every constant resolves.
#: Keep this in step when adding a group, or the new group goes unchecked.
CODE_NAMESPACES = {
"STATE_": VOCAB_REQUEST_STATES,
"DONATION_STATE_": VOCAB_DONATION_STATES,
"DRIMS_TYPE_": VOCAB_DRIMS_TYPES,
"ALERT_": VOCAB_ALERT_TYPES,
"PRIORITY_": VOCAB_PRIORITY_LEVELS,
}
2 changes: 1 addition & 1 deletion spp_drims/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def _compute_sla_status(self):

SLA thresholds are configurable via Settings > DRIMS Configuration
(requires spp_studio_drims module) or System Parameters:
- drims.sla.hours.critical/high/routine/low
- drims.sla.hours.critical/urgent/routine
- drims.sla.warning_threshold_pct
"""
now = fields.Datetime.now()
Expand Down
9 changes: 7 additions & 2 deletions spp_drims/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ def get_approval_sla_hours(self, priority_code):
"""Get approval SLA hours for a given priority code.

Args:
priority_code: One of 'critical', 'high', 'routine', 'low'
priority_code: a code from the DRIMS priority-levels vocabulary —
'critical', 'urgent' or 'routine'

Returns:
int: Hours allowed to approve requests of this priority
"""
# nosemgrep: odoo-sudo-without-context — standard Odoo pattern for system parameter access
ICP = self.env["ir.config_parameter"].sudo()
defaults = {"critical": 4, "high": 8, "routine": 24, "low": 48}
# Keyed by the codes the priority-levels vocabulary actually ships.
# This used to name 'high' and 'low', which no priority has, so an
# urgent request fell through to the routine default of 24 hours
# instead of 8 and nothing said so (OP#1165).
defaults = {"critical": 4, "urgent": 8, "routine": 24}
param_key = f"drims.sla.hours.{priority_code}"
return int(ICP.get_param(param_key, defaults.get(priority_code, 24)))

Expand Down
1 change: 1 addition & 0 deletions spp_drims/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
from . import common
from . import test_activity_feed
from . import test_constants
from . import test_alert
from . import test_allocation_preview_wizard
from . import test_approval
Expand Down
Loading
Loading