Example #1
0
class Order_taker_goal(DB.Model):
    """
    order_taker_goal database table definition
    """

    order_taker = DB.Column(DB.Integer,
                            DB.ForeignKey("sys_user.id"),
                            primary_key=True,
                            nullable=False)
    month = DB.Column(DB.Integer, primary_key=True, nullable=False)
    year = DB.Column(DB.Integer, primary_key=True, nullable=False)
    goal_value = DB.Column(DB.Numeric(10, 2), nullable=False)

    def __init__(self, taker, month, year, value):
        self.order_taker = taker
        self.month = month
        self.year = year
        self.goal_value = value

    def request_order_taker_goal_info(self):
        """
        produces a dictionary of all relevant order_taker_goal information
        """

        return {
            "order_taker": self.order_taker,
            "month": self.month,
            "year": self.year,
            "goal_value": self.goal_value
        }

    @staticmethod
    def bootstrap_populate(database):
        """
        database bootstrap function for order_taker_goal
        """

        database.session.add(Order_taker_goal(1, 11, 2020, 20000.00))
        database.session.add(Order_taker_goal(1, 12, 2020, 15000.00))
        database.session.add(Order_taker_goal(4, 11, 2020, 10000.00))
        database.session.add(Order_taker_goal(4, 12, 2020, 11000.00))
        database.session.add(Order_taker_goal(7, 11, 2020, 12000.00))
        database.session.add(Order_taker_goal(7, 12, 2020, 13000.00))

        database.session.commit()
Example #2
0
class Shop_order(DB.Model):
    """
    shop_order database table definition
    """

    id = DB.Column(DB.Integer, primary_key=True, nullable=False)
    shop = DB.Column(DB.Integer, DB.ForeignKey("shop.id"), nullable=False)
    price_due = DB.Column(DB.Numeric(10, 2), nullable=False)
    price_paid = DB.Column(DB.Boolean(), nullable=False)
    memo = DB.Column(DB.String(500), nullable=False)
    date_ordered = DB.Column(DB.DateTime(True), nullable=False)
    date_delivered_projected = DB.Column(DB.DateTime(True), nullable=False)
    date_delivered = DB.Column(DB.DateTime(True), nullable=True)
    order_taker = DB.Column(DB.Integer,
                            DB.ForeignKey("sys_user.id"),
                            nullable=False)
    order_fulfiller = DB.Column(DB.Integer,
                                DB.ForeignKey("sys_user.id"),
                                nullable=True)
    completed = DB.Column(DB.Boolean(), nullable=False)

    def __init__(self, shop, due, paid, memo, ordered, projected, delivered,
                 taker, fulfiller, completed):
        self.shop = shop
        self.price_due = due
        self.price_paid = paid
        self.memo = memo
        self.date_ordered = ordered
        self.date_delivered_projected = projected
        self.date_delivered = delivered
        self.order_taker = taker
        self.order_fulfiller = fulfiller
        self.completed = completed

    def request_shop_order(self, database):
        """
        produces a dictionary of all relevant shop_order information
        """

        shop_entry = (database.session.query(Shop).filter(
            Shop.id == self.shop).all())[0]

        order_taker = (database.session.query(Sys_user).filter(
            Sys_user.id == self.order_taker).all()
                       )[0].request_sys_user_info(database)

        if self.order_fulfiller is not None:
            order_fulfiller = (database.session.query(Sys_user).filter(
                Sys_user.id == self.order_fulfiller).all()
                               )[0].request_sys_user_info(database)
        else:
            order_fulfiller = None

        shop_order_items_query = (
            database.session.query(Shop_order_item).filter(
                Shop_order_item.shop_order == self.id).all())

        shop_order_items = []

        for entry in shop_order_items_query:
            shop_order_items.append(
                entry.request_shop_order_item_info(database))

        return {
            "id": self.id,
            "shop": shop_entry.request_shop_info(database),
            "price_due": float(self.price_due),
            "price_paid": self.price_paid,
            "memo": self.memo,
            "date_ordered": str(self.date_ordered),
            "date_delivered_projected": str(self.date_delivered_projected),
            "date_delivered": self.date_delivered,
            "order_taker": order_taker,
            "order_fulfiller": order_fulfiller,
            "completed": self.completed,
            "shop_order_items": shop_order_items,
        }

    @staticmethod
    def bootstrap_populate(database):
        """
        database bootstrap function for shop_order
        """

        current_time_utc = datetime.datetime.now(datetime.timezone.utc)
        # one week ahead for projected delivery date
        week_forward = current_time_utc + datetime.timedelta(days=7)

        # order placed and paid
        database.session.add(
            Shop_order(1, 40614.00, True, "test 1", current_time_utc,
                       week_forward, None, 1, None, False))
        # order placed and not paid
        database.session.add(
            Shop_order(2, 7928.00, False, "test 2", current_time_utc,
                       week_forward, None, 1, None, False))
        # order placed, paid and delivered
        database.session.add(
            Shop_order(
                3,
                400400.00,
                True,
                "",
                current_time_utc,
                week_forward,
                week_forward,
                1,
                2,
                True,
            ))

        database.session.commit()
Example #3
0
class Company_product(DB.Model):
    """
    company_product database table definition
    """

    id = DB.Column(DB.Integer, primary_key=True, nullable=False)
    company = DB.Column(DB.Integer,
                        DB.ForeignKey("company.id"),
                        nullable=False)
    name = DB.Column(DB.String(100), nullable=False)
    price_buy = DB.Column(DB.Numeric(10, 2), nullable=False)
    price_sell = DB.Column(DB.Numeric(10, 2), nullable=False)
    units_per_price = DB.Column(DB.Integer, nullable=False)
    stock = DB.Column(DB.Integer, nullable=False)
    image_url = DB.Column(DB.String(500), nullable=False)
    description = DB.Column(DB.String(255), nullable=True)

    def __init__(self, company, name, buy, sell, unit, stock, image,
                 description):
        self.company = company
        self.name = name
        self.price_buy = buy
        self.price_sell = sell
        self.units_per_price = unit
        self.stock = stock
        self.image_url = image
        self.description = description

    def request_company_product_info(self, database):
        """
        produces a dictionary of all relevant company_product information
        """

        company = (database.session.query(Company).filter(
            Company.id == self.company).all()
                   )[0].request_company_info(database)

        return {
            "id": self.id,
            "company": company,
            "name": self.name,
            "price_buy": float(self.price_buy),
            "price_sell": float(self.price_sell),
            "units_per_price": self.units_per_price,
            "price_sell_per_unit":
            float(self.price_sell / self.units_per_price),
            "stock": self.stock,
            "image_url": self.image_url,
            "description": self.description
        }

    @staticmethod
    def bootstrap_populate(database):
        """
        database bootstrap function for company_product
        """

        database.session.add(
            Company_product(
                1, "C1 Item 1", 1.00, 2.00, 1, 10,
                "https://www.kindpng.com/picc/m/11-112771_1-number-" +
                "circle-desgin-png-1-2-3.png", None))
        database.session.add(
            Company_product(1, "C1 Item 2", 2.00, 4.00, 2, 12,
                            "https://cdn.picpng.com/2/photo-2-35361.png",
                            "Item 2!"))
        database.session.add(
            Company_product(
                1, "C1 Item 3", 300.00, 600.00, 30, 33,
                "https://blognumbers.files.wordpress.com/2010/09/3.jpg",
                "Big Item 3"))
        database.session.add(
            Company_product(
                1, "C1 Item 4", 44.00, 88.00, 4, 100,
                "https://blognumbers.files.wordpress.com/2010/09/4.jpg", None))

        database.session.add(
            Company_product(
                2, "C2 Item 1", 100.00, 200.00, 1, 22,
                "https://www.kindpng.com/picc/m/11-112771_1-number-" +
                "circle-desgin-png-1-2-3.png", "Big Item"))
        database.session.add(
            Company_product(2, "C2 Item 2", 0.01, 0.02, 1, 33,
                            "https://cdn.picpng.com/2/photo-2-35361.png",
                            "Small Item"))
        database.session.add(
            Company_product(
                2, "C2 Item 3", 10000.00, 20000.00, 1, 5,
                "https://blognumbers.files.wordpress.com/2010/09/3.jpg",
                "Huge Item"))
        database.session.add(
            Company_product(
                2, "C2 Item 4", 4.44, 8.88, 1, 400,
                "https://blognumbers.files.wordpress.com/2010/09/4.jpg", None))

        database.session.commit()