<commit_before># -*- coding: utf-8 -*-

"""
byceps.blueprints.shop.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2015 <NAME>
"""

from datetime import datetime
from enum import Enum

from flask import g
from Ranger import Range
from Ranger.src.Range.Cut import Cut
from sqlalchemy.ext.hybrid import hybrid_property

from ...database import BaseQuery, db, generate_uuid
from ...util.instances import ReprBuilder
from ...util.money import EuroAmount

from ..party.models import Party
from ..user.models import User


class ArticleQuery(BaseQuery):

    def for_current_party(self):
        return self.for_party(g.party)

    def for_party(self, party):
        return self.filter_by(party_id=party.id)

    def currently_available(self):
        """Select only articles that are available in between the
        temporal boundaries for this article, if specified.
        """
        now = datetime.now()

        return self \
            .filter(db.or_(
                Article.available_from == None,
                now >= Article.available_from
            )) \
            .filter(db.or_(
                Article.available_until == None,
                now < Article.available_until
            ))


class Article(db.Model):
    """An article that can be bought."""
    __tablename__ = 'shop_articles'
    __table_args__ = (
        db.UniqueConstraint('party_id', 'description'),
    )
    query_class = ArticleQuery

    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
    item_number = db.Column(db.Unicode(20), unique=True)
    party_id = db.Column(db.Unicode(20), db.ForeignKey('parties.id'), index=True, nullable=False)
    party = db.relationship(Party)
    description = db.Column(db.Unicode(80), nullable=False)
    _price = db.Column('price', db.Integer, nullable=False)
    available_from = db.Column(db.DateTime, nullable=True)
    available_until = db.Column(db.DateTime, nullable=True)
    quantity = db.Column(db.Integer, nullable=False)
    max_quantity_per_order = db.Column(db.Integer, nullable=True)
    requires_separate_order = db.Column(db.Boolean, default=False, nullable=False)

    def __init__(self, party, description, price, quantity,
                 *, available_from=None, available_until=None):<commit_msg>Added article field for tax rate.<commit_after># -*- coding: utf-8 -*-

"""
byceps.blueprints.shop.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2015 <NAME>
"""

from datetime import datetime
from enum import Enum

from flask import g
from Ranger import Range
from Ranger.src.Range.Cut import Cut
from sqlalchemy.ext.hybrid import hybrid_property

from ...database import BaseQuery, db, generate_uuid
from ...util.instances import ReprBuilder
from ...util.money import EuroAmount

from ..party.models import Party
from ..user.models import User


class ArticleQuery(BaseQuery):

    def for_current_party(self):
        return self.for_party(g.party)

    def for_party(self, party):
        return self.filter_by(party_id=party.id)

    def currently_available(self):
        """Select only articles that are available in between the
        temporal boundaries for this article, if specified.
        """
        now = datetime.now()

        return self \
            .filter(db.or_(
                Article.available_from == None,
                now >= Article.available_from
            )) \
            .filter(db.or_(
                Article.available_until == None,
                now < Article.available_until
            ))


class Article(db.Model):
    """An article that can be bought."""
    __tablename__ = 'shop_articles'
    __table_args__ = (
        db.UniqueConstraint('party_id', 'description'),
    )
    query_class = ArticleQuery

    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
    item_number = db.Column(db.Unicode(20), unique=True)
    party_id = db.Column(db.Unicode(20), db.ForeignKey('parties.id'), index=True, nullable=False)
    party = db.relationship(Party)
    description = db.Column(db.Unicode(80), nullable=False)
    _price = db.Column('price', db.Integer, nullable=False)
    tax_rate = db.Column(db.Numeric(3, 3))
    available_from = db.Column(db.DateTime, nullable=True)
    available_until = db.Column(db.DateTime, nullable=True)
    quantity = db.Column(db.Integer, nullable=False)
    max_quantity_per_order = db.Column(db.Integer, nullable=True)
    requires_separate_order = db.Column(db.Boolean, default=False, nullable=False)

    def __init__(self, party, description, price, quantity,
                 *, available_from=None, available_until=None):
{'fraction_non_alphanumeric': 0.12187703671518575, 'fraction_numerical': 0.00695198783402129, 'mean_word_length': 3.12914798206278, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5923280', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1324, 'n_words': 319}