Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MasterDataDelistingCreateUpdateSerializer(GenericCreateUpdateSerializer):
- create = MasterDataDelistingCreateSerializer()
- update = MasterDataDelistingUpdateSerializer()
- model_dashboard_class = MasterDataDelisting
- def create_one(self, data: dict) -> None:
- master_data_element_id = data.get('master_data_element_id')
- master_data_element = MasterDataElement.objects.filter(id=master_data_element_id)
- if master_data_element.exists():
- raise
- master_data_element = master_data_element.first()
- master_data_delisting = self.model_dashboard_class.objects.create(
- date=data.get('date'),
- master_data_element=master_data_element,
- hierarchy_id=master_data_element.level.hierarchy_id,
- is_archived=False,
- )
- master_data_element.switch_status(
- manual_status_id=MasterDataElementStatus.Options.DELISTING.value,
- calculated_status_id=MasterDataElementStatus.Options.DELISTING.value,
- )
- return master_data_delisting
- def update_one(self, data: dict) -> None:
- instance = self.model_dashboard_class.objects.filter(
- id=data.get('id'),
- ).first()
- date = data.get('date')
- is_archived = data.get('is_archived')
- status_id = data.get('status_id')
- if date:
- instance.date = date
- instance.save()
- if is_archived is not None:
- instance.is_archived = not instance.is_archived
- instance.save()
- master_data_element = instance.master_data_element
- if status_id:
- master_data_element.switch_status(
- calculated_status_id=status_id,
- manual_status_id=status_id,
- )
- return instance
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement