feat: hide authorizer for rental orders, auto-set sale type

Rental orders no longer show the "Authorizer Required?" question or
the Authorizer field. The sale type is automatically set to 'Rentals'
when creating or confirming a rental order. Validation logic also
skips authorizer checks for rental sale type.

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-02-25 23:33:23 -05:00
parent 3c8f83b8e6
commit 14fe9ab716
51 changed files with 4192 additions and 822 deletions

View File

@@ -479,14 +479,14 @@ class SaleOrder(models.Model):
)
# Authorizer Required field - only for certain sale types
# For: odsp, direct_private, insurance, other, rental
# For: odsp, direct_private, insurance, other (NOT rental)
x_fc_authorizer_required = fields.Selection(
selection=[
('yes', 'Yes'),
('no', 'No'),
],
string='Authorizer Required?',
help='For ODSP, Direct/Private, Insurance, Others, and Rentals - specify if an authorizer is needed.',
help='For ODSP, Direct/Private, Insurance, Others - specify if an authorizer is needed.',
)
# Computed field to determine if authorizer should be shown
@@ -498,21 +498,18 @@ class SaleOrder(models.Model):
@api.depends('x_fc_sale_type', 'x_fc_authorizer_required')
def _compute_show_authorizer(self):
"""Compute whether to show the authorizer field based on sale type and authorizer_required."""
# Sale types that require the "Authorizer Required?" question
optional_auth_types = ('odsp', 'direct_private', 'insurance', 'other', 'rental')
# Sale types where authorizer is always shown/required
optional_auth_types = ('odsp', 'direct_private', 'insurance', 'other')
always_auth_types = ('adp', 'adp_odsp', 'wsib', 'march_of_dimes', 'muscular_dystrophy')
for order in self:
sale_type = order.x_fc_sale_type
if sale_type in always_auth_types:
# Always show authorizer for ADP-related types
if sale_type == 'rental':
order.x_fc_show_authorizer = False
elif sale_type in always_auth_types:
order.x_fc_show_authorizer = True
elif sale_type in optional_auth_types:
# Show authorizer only if user selected "Yes"
order.x_fc_show_authorizer = order.x_fc_authorizer_required == 'yes'
else:
# No sale type selected - don't show
order.x_fc_show_authorizer = False
# Computed field to determine if "Authorizer Required?" question should be shown
@@ -524,7 +521,7 @@ class SaleOrder(models.Model):
@api.depends('x_fc_sale_type')
def _compute_show_authorizer_question(self):
"""Compute whether to show the 'Authorizer Required?' field."""
optional_auth_types = ('odsp', 'direct_private', 'insurance', 'other', 'rental')
optional_auth_types = ('odsp', 'direct_private', 'insurance', 'other')
for order in self:
order.x_fc_show_authorizer_question = order.x_fc_sale_type in optional_auth_types
@@ -5810,19 +5807,19 @@ class SaleOrder(models.Model):
if should_validate_authorizer:
always_auth_types = ('adp', 'adp_odsp', 'wsib', 'march_of_dimes', 'muscular_dystrophy')
optional_auth_types = ('odsp', 'direct_private', 'insurance', 'other', 'rental')
optional_auth_types = ('odsp', 'direct_private', 'insurance', 'other')
for order in self:
sale_type = get_val(order, 'x_fc_sale_type')
if sale_type == 'rental':
continue
auth_id = get_val(order, 'x_fc_authorizer_id')
auth_required = get_val(order, 'x_fc_authorizer_required')
if sale_type in always_auth_types:
# Always required for these types
if not auth_id:
raise UserError("Authorizer is required for this sale type.")
elif sale_type in optional_auth_types and auth_required == 'yes':
# Required only if user selected "Yes"
if not auth_id:
raise UserError("Authorizer is required. You selected 'Yes' for Authorizer Required.")