Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-941: Draft, basic BE code for reseting pricelists. #43

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions location/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def async_mutate(cls, user, **data):
new_parent = Location.objects.get(uuid=np_uuid) if np_uuid else None
np_level = LocationConfig.location_types.index(new_parent.type) if new_parent else -1
location.parent = new_parent
# if location.type in ['D', 'R']:
# detach_pricelist_in_location(location_id=location.id)
if np_level < level - 1 or np_level >= level:
tree_reset_types(new_parent, location, np_level + 1)
location.save()
Expand All @@ -197,6 +199,25 @@ def async_mutate(cls, user, **data):
'detail': str(exc)}]


def detach_pricelist_in_location(location_id):
from medical_pricelist.services import set_pricelist_deleted
HF_list = HealthFacility.objects.filter(location_id=location_id, validity_to=None)
pricelists_items = HealthFacility.select_related('items_pricelist').filter(location_id=location_id,
validity_to=None)
pricelists_services = HealthFacility.select_related('services_pricelist').filter(location_id=location_id,
validity_to=None)
for health_facility in HF_list:
health_facility.services_pricelist =None
health_facility.items_pricelist = None
health_facility.save()

for pricelists_item in pricelists_items:
set_pricelist_deleted(pricelists_item)

for pricelists_service in pricelists_services:
set_pricelist_deleted(pricelists_service)


class HealthFacilityCodeInputType(graphene.String):

@staticmethod
Expand Down