BoxVendor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 35
loc 35
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A from_id() 3 3 1
A from_number_fuzzy() 3 3 1
A __init__() 5 5 1

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
from .model import *
2
from . import vendor
3
from . import box
4
5 View Code Duplication
class BoxVendor(Base):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6
    __tablename__ = 'box_vendors'
7
8
    id          = Column(Integer, primary_key=True, nullable=False)
9
    vendor_id   = Column(Integer, ForeignKey("vendors.id"), nullable=False)
10
    box_id      = Column(Integer, ForeignKey("boxes.id"), nullable=False)
11
    item_number = Column(String(255), nullable=False)
12
13
    enabled     = Column(Boolean, default=True, nullable=False)
14
15
    vendor      = relationship(
16
                      vendor.Vendor,
17
                      primaryjoin="and_(BoxVendor.vendor_id==Vendor.id, BoxVendor.enabled==True)",
18
                      backref="boxes"
19
                  )
20
    box         = relationship(
21
                      box.Box,
22
                      primaryjoin="and_(BoxVendor.box_id==Box.id, BoxVendor.enabled==True)",
23
                      backref="vendors"
24
                  )
25
26
27
    def __init__(self, vendor, box, item_number, enabled=True):
28
        self.vendor_id   = vendor.id
29
        self.box_id      = box.id
30
        self.item_number = item_number
31
        self.enabled     = enabled
32
33
    @classmethod
34
    def from_id(cls, id):
35
        return DBSession.query(cls).filter(cls.id == id).one()
36
37
    @classmethod
38
    def from_number_fuzzy(cls, number):
39
        return DBSession.query(cls).filter(cls.item_number.like('%{}%'.format(number))).all()
40