Skip to content

Commit

Permalink
0.7.6: getting all countries
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Bendtsen committed Dec 21, 2024
1 parent 71198b8 commit 5b9cbbb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
Binary file added dist/dolibarrpy-0.7.6.tar.gz
Binary file not shown.
55 changes: 55 additions & 0 deletions dolibarrpy/Dolibarrpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ class ProjectFilter():
sqlfilters: Optional[str] = None # Syntax example "(t.statut:=:1)
properties: Optional[str] = None # Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names

@dataclass
class countryFilter():
sortfield: Optional[str] = None
sortorder: Optional[str] = None
limit: Optional[int] = None
page: Optional[int] = None
namefilter: Optional[str] = None # To filter the countries by name
lang: Optional[str] = None # Code of the language the label of the countries must be translated to
sqlfilters: Optional[str] = None # Syntax example "(t.statut:=:1)

@dataclass
class MemberFilter():
sortfield: Optional[str] = None
Expand Down Expand Up @@ -2251,6 +2261,51 @@ def get_setup_dictionary_currencies(self):
result = self.call_get_api('setup', 'dictionary/currencies')
return result

def find_all_countries(self, from_countryFilter = None):
"""
@endpoint 'get /setup/dictionary/countries'
Get all countries
@param from_countryFilter:
@return: list of a countries
"""
if self.debug:
ic()
ic(from_countryFilter)
if from_countryFilter is None:
search_filter = countryFilter()
else:
search_filter = from_countryFilter
all_countries=[]
page = 0
while True:
some_countries = self.find_some_countries(search_filter, page)
if "error" in some_countries:
break
elif [] == some_countries:
break
elif {} == some_countries:
break
else:
page += 1
if some_countries == all_countries:
break
all_countries = all_countries + list(some_countries)
return all_countries

def find_some_countries(self, from_countryFilter = None, page = 0):
if self.debug:
ic()
ic(page)
ic(from_countryFilter)
if from_countryFilter is None:
search_filter = countryFilter()
else:
search_filter = from_countryFilter
search_filter = replace(search_filter, page=page)
params = asdict(search_filter)
result = self.call_list_api('setup/dictionary/countries', params)
return result

# CATEGORIES
def find_all_categories(self, from_categoryFilter = None):
"""
Expand Down
2 changes: 1 addition & 1 deletion implementation_status.csv
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
0 get /setup/dictionary/availability
0 get /setup/dictionary/civilities
0 get /setup/dictionary/contact_types
0 get /setup/dictionary/countries
1 get /setup/dictionary/countries
0 get /setup/dictionary/countries/{id}
0 get /setup/dictionary/countries/byCode/{code}
0 get /setup/dictionary/countries/byISO/{iso}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name='dolibarrpy',
packages=['dolibarrpy'],
version="0.7.5",
version="0.7.6",
license='MIT',
description='Python wrapper for Dolibarr API',
long_description='This project is a python wrapper for the API for Dolibarr ERP & CRM found at dolibarr.org. It is not yet complete, but most major GET endpoints has been implemented. In the beginning I will mostly focus on implementing the API endpoints that I use.',
Expand Down

0 comments on commit 5b9cbbb

Please sign in to comment.