ItemVendor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A from_id() 3 3 1
A __init__() 5 5 1
A from_number_fuzzy() 3 3 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 item
4
5 View Code Duplication
class ItemVendor(Base):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6
    __tablename__ = 'item_vendors'
7
8
    id          = Column(Integer, primary_key=True, nullable=False)
9
    vendor_id   = Column(Integer, ForeignKey("vendors.id"), nullable=False)
10
    item_id     = Column(Integer, ForeignKey("items.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_(ItemVendor.vendor_id==Vendor.id, ItemVendor.enabled==True)",
18
                      backref="items"
19
                  )
20
    item         = relationship(
21
                      item.Item,
22
                      primaryjoin="and_(ItemVendor.item_id==Item.id, ItemVendor.enabled==True)",
23
                      backref="vendors"
24
                  )
25
26
    def __init__(self, vendor, item, item_number, enabled=True):
27
        self.vendor_id   = vendor.id
28
        self.item_id     = item.id
29
        self.item_number = item_number
30
        self.enabled     = enabled
31
32
    @classmethod
33
    def from_id(cls, id):
34
        return DBSession.query(cls).filter(cls.id == id).one()
35
36
    @classmethod
37
    def from_number_fuzzy(cls, number):
38
        return DBSession.query(cls).filter(cls.item_number.like('%{}%'.format(number))).all()
39