1 | """ |
||
2 | byceps.services.shop.order.models.sequence |
||
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
4 | |||
5 | :Copyright: 2006-2020 Jochen Kupperschmidt |
||
6 | :License: Modified BSD, see LICENSE for details. |
||
7 | """ |
||
8 | |||
9 | 1 | from typing import Optional |
|
10 | |||
11 | 1 | from .....database import db, generate_uuid |
|
12 | 1 | from .....util.instances import ReprBuilder |
|
13 | |||
14 | 1 | from ...shop.transfer.models import ShopID |
|
15 | |||
16 | |||
17 | 1 | View Code Duplication | class OrderNumberSequence(db.Model): |
1 ignored issue
–
show
Duplication
introduced
by
Loading history...
|
|||
18 | """A shop-specific, unique order number sequence.""" |
||
19 | |||
20 | 1 | __tablename__ = 'shop_order_number_sequences' |
|
21 | |||
22 | 1 | id = db.Column(db.Uuid, default=generate_uuid, primary_key=True) |
|
23 | 1 | shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), index=True, nullable=False) |
|
24 | 1 | prefix = db.Column(db.UnicodeText, unique=True, nullable=False) |
|
25 | 1 | value = db.Column(db.Integer, default=0, nullable=False) |
|
26 | |||
27 | 1 | def __init__( |
|
28 | self, |
||
29 | shop_id: ShopID, |
||
30 | prefix: str, |
||
31 | *, |
||
32 | value: Optional[int] = 0, |
||
33 | ) -> None: |
||
34 | 1 | if value is None: |
|
35 | 1 | value = 0 |
|
36 | |||
37 | 1 | self.shop_id = shop_id |
|
38 | 1 | self.prefix = prefix |
|
39 | 1 | self.value = value |
|
40 | |||
41 | 1 | 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 |