pharmaship.core.utils

Core utilities functions.

pharmaship.core.utils.add_months(sourcedate: datetime.date, months: int)datetime.date

Add n calendar months to a date.

Only add n-months to a date without changing the day.

Parameters
  • sourcedate (datetime.date) – A datetime.date instance

  • months (int) – number of months to add to sourcedate.

Returns

A datetime.date increased by n months.

Return type

datetime.date

Example

>>> add_months(datetime.date(2020, 1, 31), 3)
datetime.date(2020, 4, 30)
pharmaship.core.utils.end_of_month(date_obj)

Return the end of month date.

The returned date corresponds to the last day of the date_obj’s month.

Parameters

date_obj (datetime.date) – A datetime.date instance.

Returns

The corresponding end-of-month date.

Return type

datetime.date

Example

>>> end_of_month(datetime.date(2020, 1, 13))
datetime.date(2020, 1, 31)
pharmaship.core.utils.get_content_types(app_label='inventory')

Return the dict of content_types id for selected app_label.

Parameters

app_label (str) – Application name to get content_types for. Default: “inventory”

Returns

dictionary with model names as keys and related content_type ID as values.

Return type

dict

Example

>>> get_content_types()
{'allowance': 7, 'article': 25, 'equipment': 8, 'equipmentgroup': 24,
'equipmentreqqty': 23, 'firstaidkit': 9, 'firstaidkititem': 22,
'firstaidkitreqqty': 21, 'laboratoryreqqty': 20, 'location': 10,
'medicine': 19, 'molecule': 11, 'moleculegroup': 18, 'moleculereqqty': 17,
'qtytransaction': 16, 'rescuebag': 15, 'rescuebagreqqty': 14, 'tag': 13,
'telemedicalreqqty': 12}
pharmaship.core.utils.query_count_all(show=False)None

Print the number of DB queries done since its last call.

show: if True, logs the full SQL queries.

pharmaship.core.utils.remove_yaml_pk(yaml_string)

Remove the PK attributes to the serialized objects. YAML Version.

This allows to import different alllowances with for instance the same molecules without generating conflicts of primary key.

Parameters

yaml_string (str) – YAML string to parse.

Returns

YAML string without “pk” attributes.

Return type

str