예제 #1
0
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))
예제 #2
0
    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
예제 #3
0
    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)
예제 #4
0
    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')
예제 #5
0
    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,
        )
예제 #6
0
파일: views.py 프로젝트: FNSdev/gitrello
    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,
        )
예제 #7
0
    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
예제 #8
0
 def get_production_price(self, obj):
     return round(BoardService().get_price_for_model(model=obj), 2)
예제 #9
0
    def create(self, validated_data):
        BoardService().add_missing_scans(last_scan=validated_data)

        return super().create(validated_data)
예제 #10
0
    def get(self, request, company, format=None):
        response = BoardService().get_production_for(company_code=company)

        return Response(response)
예제 #11
0
 def get_production_price(self, obj):
     return BoardService().get_price_for_board(board=obj)
예제 #12
0
 def get_production_history(self, obj):
     return BoardService().get_board_production_history(barcode=obj.barcode)
예제 #13
0
 def get_customer(self, obj):
     return BoardService().get_board_customer(barcode=obj.barcode)
예제 #14
0
    def get(self, request, code, format=None):
        response = BoardService().get_stock_for(company_code=code)

        return Response(response)
예제 #15
0
    def get(self, request, format=None):
        response = BoardService().get_stock()

        return Response(response)
예제 #16
0
 def test_create_board_organization_not_found(self):
     with self.assertRaises(OrganizationNotFoundException):
         _ = BoardService.create_board(name='board', organization_id=-1)
예제 #17
0
 def create(self, validated_data):
     return BoardService().create_new_board(**validated_data)
예제 #18
0
    def get(self, request, format=None):
        response = BoardService().get_production()

        return Response(response)