fix: auto-set rental sale type via onchange and context
is_rental_order is a computed field, not passed in vals during create. Use in_rental_app context flag in create() and add onchange handler so sale type sets to 'Rentals' immediately when toggled in the form. Made-with: Cursor
This commit is contained in:
@@ -836,10 +836,18 @@ class SaleOrder(models.Model):
|
||||
# Auto-set sale type for rental orders
|
||||
# =================================================================
|
||||
|
||||
@api.onchange('is_rental_order')
|
||||
def _onchange_is_rental_order_sale_type(self):
|
||||
if self.is_rental_order and not self.x_fc_sale_type:
|
||||
self.x_fc_sale_type = 'rental'
|
||||
self.x_fc_authorizer_required = 'no'
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
in_rental = self.env.context.get('in_rental_app')
|
||||
for vals in vals_list:
|
||||
if vals.get('is_rental_order') and not vals.get('x_fc_sale_type'):
|
||||
is_rental = vals.get('is_rental_order', in_rental)
|
||||
if is_rental and not vals.get('x_fc_sale_type'):
|
||||
vals['x_fc_sale_type'] = 'rental'
|
||||
vals.setdefault('x_fc_authorizer_required', 'no')
|
||||
return super().create(vals_list)
|
||||
|
||||
Reference in New Issue
Block a user