def validate_barcode(**kwargs): barcode = kwargs.get('barcode') if len(str(barcode)) < settings.BARCODE_LENGHT: raise ValidationError('barcode: {} is too short'.format(barcode)) if len(str(barcode)) > settings.BARCODE_LENGHT: raise ValidationError('barcode: {} is too long'.format(barcode)) if not BoardService().get_company_from_barcode(barcode=barcode): raise ValidationError('not valid company in barcode'.format(barcode)) if not BoardService().get_model_from_barcode(barcode=barcode): raise ValidationError( 'not valid board model in barcode'.format(barcode))
def update(self, instance, validated_data): components = validated_data.pop('components', None) super().update(instance, validated_data) if components: BoardService().update_components(model=instance, components=components) return instance
def test_create_board_name_not_unique(self): organization_membership = OrganizationMembershipFactory( role=OrganizationMemberRole.OWNER) board = BoardFactory( organization_id=organization_membership.organization_id, ) with self.assertRaises(BoardAlreadyExistsException): _ = BoardService.create_board( name=board.name, organization_id=organization_membership.organization_id)
def create_records(self, order, data): records = [] for record in data: layout = None if 'layout' in record: layout = BoardService().get_layout(**record['layout']) records.append( OrderRecord(order=order, board_model=record.get('board_model'), quantity=record.get('quantity'), layout=layout)) try: OrderRecord.objects.bulk_create(records) except: # TODO raise ServiceException('cannot create order records')
def test_create_board(self): organization_membership = OrganizationMembershipFactory( role=OrganizationMemberRole.OWNER) with patch.object(BoardMembershipService, 'create_board_membership') as mocked_add_member: board = BoardService.create_board( name='board', organization_id=organization_membership.organization_id) self.assertIsNotNone(board) self.assertEqual(board.name, 'board') self.assertEqual(board.organization.id, organization_membership.organization_id) mocked_add_member.assert_called_with( board_id=board.id, organization_membership_id=organization_membership.id, )
def post(self, request, *args, **kwargs): serializer = CreateBoardSerializer(data=request.data) serializer.is_valid(raise_exception=True) permissions = PermissionsService.get_organization_permissions( organization_id=serializer.validated_data['organization_id'], user_id=request.user.id, ) if not permissions.can_mutate: raise PermissionDeniedException board = BoardService.create_board(**serializer.validated_data) CategoryService.create_category(name=CategoryService.NOT_SORTED, board_id=board.id) response_serializer = CreateBoardResponseSerializer(instance=board) return Response( status=201, data=response_serializer.data, )
def create(self, validated_data): components = validated_data.pop('components') model = BoardService().create_new_model(**validated_data) BoardService().update_components(model=model, components=components) return model
def get_production_price(self, obj): return round(BoardService().get_price_for_model(model=obj), 2)
def create(self, validated_data): BoardService().add_missing_scans(last_scan=validated_data) return super().create(validated_data)
def get(self, request, company, format=None): response = BoardService().get_production_for(company_code=company) return Response(response)
def get_production_price(self, obj): return BoardService().get_price_for_board(board=obj)
def get_production_history(self, obj): return BoardService().get_board_production_history(barcode=obj.barcode)
def get_customer(self, obj): return BoardService().get_board_customer(barcode=obj.barcode)
def get(self, request, code, format=None): response = BoardService().get_stock_for(company_code=code) return Response(response)
def get(self, request, format=None): response = BoardService().get_stock() return Response(response)
def test_create_board_organization_not_found(self): with self.assertRaises(OrganizationNotFoundException): _ = BoardService.create_board(name='board', organization_id=-1)
def create(self, validated_data): return BoardService().create_new_board(**validated_data)
def get(self, request, format=None): response = BoardService().get_production() return Response(response)