Esempio n. 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))
Esempio n. 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
Esempio n. 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)
Esempio n. 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')
Esempio n. 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,
        )
Esempio n. 6
0
    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,
        )
Esempio n. 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
Esempio n. 8
0
 def get_production_price(self, obj):
     return round(BoardService().get_price_for_model(model=obj), 2)
Esempio n. 9
0
    def create(self, validated_data):
        BoardService().add_missing_scans(last_scan=validated_data)

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

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

        return Response(response)
Esempio n. 15
0
    def get(self, request, format=None):
        response = BoardService().get_stock()

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

        return Response(response)