Skip to content

Commit 9d5be72

Browse files
Update pickup_request.py and related improvements
1 parent 94d801b commit 9d5be72

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
Binary file not shown.

records_management/models/pickup_request.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ def _check_request_date(self):
7575
Ensure the request date is not in the past.
7676
"""
7777
for rec in self:
78-
if rec.request_date and fields.Date.from_string(rec.request_date) < fields.Date.from_string(fields.Date.today()):
78+
if rec.request_date and rec.request_date < fields.Date.to_date(fields.Date.today()):
7979
raise ValidationError("The request date cannot be in the past.")
8080

81+
@api.constrains('item_ids', 'customer_id')
8182
def _check_item_customer(self):
8283
"""
83-
Ensure all selected items belong to the selected customer.
84+
Constraint: Ensure all selected items belong to the selected customer.
8485
"""
8586
for rec in self:
8687
if rec.customer_id and rec.item_ids:
@@ -102,15 +103,14 @@ def action_done(self):
102103
for rec in self:
103104
rec.state = 'done'
104105

105-
# Security rules should be defined in the corresponding XML security files.
106-
# Example: records_management/security/ir.model.access.csv
107-
# See: records_management/security/ir.model.access.csv for access rights configuration.
106+
# Security rules should be defined in the appropriate XML security files.
107+
# See your module's security configuration for access rights setup.
108108

109-
# Dynamically filter available items based on selected customer
110109
@api.onchange('customer_id')
111110
def _onchange_customer_id(self):
112111
"""
113112
Dynamically filter items based on the selected customer.
113+
Also clears item_ids if no customer is selected.
114114
"""
115115
if self.customer_id:
116116
return {
@@ -119,6 +119,7 @@ def _onchange_customer_id(self):
119119
}
120120
}
121121
else:
122+
self.item_ids = [(5, 0, 0)] # Clear all selected items
122123
return {
123124
'domain': {
124125
'item_ids': []

0 commit comments

Comments
 (0)