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

byceps.services.shop.article.models.number_sequence   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 64.58 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 29
dl 31
loc 48
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ArticleNumberSequence.__repr__() 7 7 1
A ArticleNumberSequence.__init__() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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