@@ -89,7 +89,7 @@ class SPPAPIPath(models.Model):
8989 # Read
9090 filter_domain = fields .Char (default = "[]" )
9191 field_ids = fields .Many2many ("ir.model.fields" , domain = "[('model_id', '=', model_id)]" , string = "Fields" )
92- limit = fields .Integer (string = "Limit of results" , default = 500 )
92+ limit = fields .Integer (string = "Limit of results" , default = 500 , help = "Limit of results per page" )
9393 # Create / Update
9494 warning_required = fields .Boolean (compute = "_compute_warning_required" , compute_sudo = True )
9595 api_field_ids = fields .One2many ("spp_api.field" , "path_id" , string = "API Fields" , copy = True )
@@ -663,15 +663,39 @@ def search_treatment_kwargs(self, kwargs):
663663 """
664664 self .ensure_one ()
665665
666- # Limit
667- limit = kwargs .get ("limit" , 0 )
668- max_limit = self .limit if self .limit else MAX_LIMIT
669- kwargs ["limit" ] = limit if (limit and limit <= max_limit ) else max_limit
670-
671- # Offset
672- kwargs ["offset" ] = kwargs .get ("start_from" , 0 )
666+ backward_compat = False
673667 if "start_from" in kwargs :
674- del kwargs ["start_from" ]
668+ backward_compat = True
669+
670+ if backward_compat :
671+ limit = kwargs .get ("limit" , 0 )
672+ max_limit = self .limit if self .limit else MAX_LIMIT
673+ kwargs ["limit" ] = limit if (limit and limit <= max_limit ) else max_limit
674+ kwargs ["offset" ] = kwargs .get ("start_from" , 0 )
675+ if "start_from" in kwargs :
676+ del kwargs ["start_from" ]
677+ else :
678+ # Page
679+ page = int (kwargs .get ("page" , 1 ))
680+
681+ # Get defined limit first in spp_api.path
682+ # if limit is defined in kwargs (query parameter), use it; else use self.limit or MAX_LIMIT
683+ max_limit = self .limit if self .limit else MAX_LIMIT
684+ limit = kwargs .get ("limit" , max_limit )
685+
686+ # Validate limit
687+ try :
688+ limit = int (limit )
689+ if limit <= 0 or limit > max_limit :
690+ limit = max_limit
691+ except (ValueError , TypeError ):
692+ limit = max_limit
693+
694+ kwargs ["limit" ] = limit
695+
696+ # Offset
697+ offset = (page - 1 ) * limit
698+ kwargs ["offset" ] = offset
675699
676700 # Domain
677701 kwargs ["domain" ] = self .get_domain (kwargs )
0 commit comments