Passed
Push — main ( 57d628...c66ff9 )
by Jochen
04:13
created

byceps.services.shop.order.dbmodels.line_item   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 58
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A LineItem.__init__() 0 22 1
1
"""
2
byceps.services.shop.order.dbmodels.line_item
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2021 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from decimal import Decimal
10
11 1
from .....database import db, generate_uuid
12
13 1
from ...article.dbmodels.article import Article as DbArticle
14 1
from ...article.transfer.models import ArticleNumber
15
16 1
from .order import Order
17
18
19 1
class LineItem(db.Model):
20
    """A line item that belongs to an order."""
21
22 1
    __tablename__ = 'shop_order_items'
23
24 1
    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
25 1
    order_number = db.Column(db.UnicodeText, db.ForeignKey('shop_orders.order_number'), index=True, nullable=False)
26 1
    order = db.relationship(Order, backref='items')
27 1
    article_number = db.Column(db.UnicodeText, db.ForeignKey('shop_articles.item_number'), index=True, nullable=False)
28 1
    article = db.relationship(DbArticle, backref='line_items')
29 1
    description = db.Column(db.UnicodeText, nullable=False)
30 1
    unit_price = db.Column(db.Numeric(6, 2), nullable=False)
31 1
    tax_rate = db.Column(db.Numeric(3, 3), nullable=False)
32 1
    quantity = db.Column(db.Integer, db.CheckConstraint('quantity > 0'), nullable=False)
33 1
    line_amount = db.Column(db.Numeric(7, 2), nullable=False)
34 1
    shipping_required = db.Column(db.Boolean, nullable=False)
35
36 1
    def __init__(
37
        self,
38
        order: Order,
39
        article_number: ArticleNumber,
40
        description: str,
41
        unit_price: Decimal,
42
        tax_rate: Decimal,
43
        quantity: int,
44
        line_amount: Decimal,
45
        shipping_required: bool,
46
    ) -> None:
47
        # Require order instance rather than order number as argument
48
        # because line items are created together with the order – and
49
        # until the order is created, there is no order number assigned.
50 1
        self.order = order
51 1
        self.article_number = article_number
52 1
        self.description = description
53 1
        self.unit_price = unit_price
54 1
        self.tax_rate = tax_rate
55 1
        self.quantity = quantity
56 1
        self.line_amount = line_amount
57
        self.shipping_required = shipping_required
58