Completed
Push — main ( 84e7fd...b765c6 )
by Jochen
04:23
created

ArticleNumberSequence.__repr__()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 7
loc 7
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
"""
2
byceps.services.shop.article.models.sequence
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2020 Jochen Kupperschmidt
6
:License: Modified BSD, see LICENSE for details.
7
"""
8
9
from typing import Optional
10
11
from .....database import db, generate_uuid
12
from .....util.instances import ReprBuilder
13
14
from ...shop.transfer.models import ShopID
15
16
17 View Code Duplication
class ArticleNumberSequence(db.Model):
0 ignored issues
show
Duplication introduced by Jochen Kupperschmidt
This code seems to be duplicated in your project.
Loading history...
18
    """A shop-specific, unique article number sequence."""
19
20
    __tablename__ = 'shop_article_number_sequences'
21
22
    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
23
    shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), index=True, nullable=False)
24
    prefix = db.Column(db.UnicodeText, unique=True, nullable=False)
25
    value = db.Column(db.Integer, default=0, nullable=False)
26
27
    def __init__(
28
        self,
29
        shop_id: ShopID,
30
        prefix: str,
31
        *,
32
        value: Optional[int] = 0,
33
    ) -> None:
34
        if value is None:
35
            value = 0
36
37
        self.shop_id = shop_id
38
        self.prefix = prefix
39
        self.value = value
40
41
    def __repr__(self) -> str:
42
        return ReprBuilder(self) \
43
            .add_with_lookup('id') \
44
            .add('shop', self.shop_id) \
45
            .add_with_lookup('prefix') \
46
            .add_with_lookup('value') \
47
            .build()
48