2012-05-01 21:40:01 +00:00
|
|
|
import uuid
|
2020-10-07 15:18:43 +00:00
|
|
|
|
2018-07-07 11:01:44 +00:00
|
|
|
from datetime import datetime
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2020-10-07 15:18:43 +00:00
|
|
|
from brewman.models.master import Product
|
2019-04-06 04:13:12 +00:00
|
|
|
from sqlalchemy import (
|
|
|
|
Boolean,
|
2020-10-07 15:18:43 +00:00
|
|
|
Column,
|
|
|
|
Date,
|
2019-04-06 04:13:12 +00:00
|
|
|
DateTime,
|
|
|
|
ForeignKey,
|
2020-10-07 15:18:43 +00:00
|
|
|
Integer,
|
|
|
|
Numeric,
|
|
|
|
Unicode,
|
2020-05-21 07:41:47 +00:00
|
|
|
UniqueConstraint,
|
2019-04-06 04:13:12 +00:00
|
|
|
)
|
2020-10-07 15:18:43 +00:00
|
|
|
from sqlalchemy.dialects.postgresql import BYTEA, UUID
|
2013-04-17 08:38:09 +00:00
|
|
|
from sqlalchemy.ext.hybrid import hybrid_property
|
2020-10-07 15:18:43 +00:00
|
|
|
from sqlalchemy.orm import Session, backref, relationship, synonym
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2018-07-07 11:01:44 +00:00
|
|
|
from .meta import Base
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2013-04-17 08:38:09 +00:00
|
|
|
|
2012-11-28 07:58:16 +00:00
|
|
|
class VoucherType:
|
2020-05-21 19:45:25 +00:00
|
|
|
def __init__(self, id_, name):
|
|
|
|
self.id = id_
|
2012-11-28 07:58:16 +00:00
|
|
|
self.name = name
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def list(cls):
|
2020-05-21 19:45:25 +00:00
|
|
|
list_ = [
|
2019-04-06 04:13:12 +00:00
|
|
|
VoucherType(1, "Journal"),
|
|
|
|
VoucherType(2, "Purchase"),
|
|
|
|
VoucherType(3, "Issue"),
|
|
|
|
VoucherType(4, "Payment"),
|
|
|
|
VoucherType(5, "Receipt"),
|
|
|
|
VoucherType(6, "Purchase Return"),
|
|
|
|
VoucherType(7, "Opening Accounts"),
|
|
|
|
VoucherType(8, "Opening Batches"),
|
|
|
|
VoucherType(9, "Verification"),
|
|
|
|
VoucherType(10, "Opening Balance"),
|
|
|
|
VoucherType(11, "Closing Balance"),
|
2020-05-21 07:41:47 +00:00
|
|
|
VoucherType(12, "Employee Benefit"),
|
2020-05-12 15:22:07 +00:00
|
|
|
VoucherType(13, "Incentive"),
|
2019-04-06 04:13:12 +00:00
|
|
|
]
|
2020-05-21 19:45:25 +00:00
|
|
|
return list_
|
2012-11-28 07:58:16 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def by_name(cls, name):
|
2020-05-21 19:45:25 +00:00
|
|
|
list_ = cls.list()
|
|
|
|
for item in list_:
|
2012-11-28 07:58:16 +00:00
|
|
|
if item.name == name:
|
|
|
|
return item
|
|
|
|
|
|
|
|
@classmethod
|
2020-05-21 19:45:25 +00:00
|
|
|
def by_id(cls, id_):
|
|
|
|
list_ = cls.list()
|
|
|
|
for item in list_:
|
|
|
|
if item.id == id_:
|
2012-11-28 07:58:16 +00:00
|
|
|
return item
|
|
|
|
|
|
|
|
|
2012-05-01 21:40:01 +00:00
|
|
|
class Voucher(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "vouchers"
|
|
|
|
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
2020-05-21 07:41:47 +00:00
|
|
|
date = Column("date", Date, nullable=False, index=True)
|
2019-04-06 04:13:12 +00:00
|
|
|
narration = Column("narration", Unicode(1000), nullable=False)
|
|
|
|
is_reconciled = Column("is_reconciled", Boolean, nullable=False)
|
2020-05-21 07:41:47 +00:00
|
|
|
reconcile_date = Column("reconcile_date", Date, nullable=False)
|
2019-04-06 04:13:12 +00:00
|
|
|
is_starred = Column("is_starred", Boolean, nullable=False)
|
|
|
|
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
|
|
|
last_edit_date = Column("last_edit_date", DateTime(timezone=True), nullable=False)
|
|
|
|
_type = Column("voucher_type", Integer, nullable=False)
|
2020-10-07 16:59:24 +00:00
|
|
|
user_id = Column(
|
|
|
|
"user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"), nullable=False
|
|
|
|
)
|
2019-04-06 04:13:12 +00:00
|
|
|
posted = Column("is_posted", Boolean, nullable=False)
|
2020-06-30 06:02:09 +00:00
|
|
|
poster_id = Column("poster_id", UUID(as_uuid=True), ForeignKey("auth_users.id"))
|
2019-04-06 04:13:12 +00:00
|
|
|
|
|
|
|
user = relationship("User", primaryjoin="User.id==Voucher.user_id", cascade=None)
|
2020-10-07 16:59:24 +00:00
|
|
|
poster = relationship(
|
|
|
|
"User", primaryjoin="User.id==Voucher.poster_id", cascade=None
|
|
|
|
)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
2020-05-14 09:09:19 +00:00
|
|
|
journals = relationship(
|
2020-10-07 15:18:43 +00:00
|
|
|
"Journal",
|
|
|
|
back_populates="voucher",
|
|
|
|
cascade="delete, delete-orphan",
|
|
|
|
cascade_backrefs=False,
|
2020-05-14 09:09:19 +00:00
|
|
|
)
|
2020-05-21 07:41:47 +00:00
|
|
|
|
2020-05-14 09:09:19 +00:00
|
|
|
inventories = relationship(
|
2020-10-07 15:18:43 +00:00
|
|
|
"Inventory",
|
|
|
|
back_populates="voucher",
|
|
|
|
cascade="delete, delete-orphan",
|
|
|
|
cascade_backrefs=False,
|
2020-05-14 09:09:19 +00:00
|
|
|
)
|
2020-05-21 07:41:47 +00:00
|
|
|
employee_benefits = relationship(
|
2020-10-07 15:18:43 +00:00
|
|
|
"EmployeeBenefit",
|
|
|
|
backref="voucher",
|
|
|
|
cascade="delete, delete-orphan",
|
|
|
|
cascade_backrefs=False,
|
|
|
|
)
|
|
|
|
incentives = relationship(
|
|
|
|
"Incentive",
|
|
|
|
backref="voucher",
|
|
|
|
cascade="delete, delete-orphan",
|
|
|
|
cascade_backrefs=False,
|
2019-04-06 04:13:12 +00:00
|
|
|
)
|
2014-08-30 12:16:43 +00:00
|
|
|
|
2012-05-01 21:40:01 +00:00
|
|
|
def _get_type(self):
|
|
|
|
return self._type
|
|
|
|
# for item in VoucherType.list():
|
|
|
|
# if self._type == item.id:
|
|
|
|
# return item
|
|
|
|
|
|
|
|
def _set_type(self, value):
|
|
|
|
if type(value) == int:
|
|
|
|
self._type = value
|
|
|
|
else:
|
|
|
|
self._type = value.id
|
|
|
|
|
|
|
|
type = property(_get_type, _set_type)
|
2019-04-06 04:13:12 +00:00
|
|
|
type = synonym("_type", descriptor=type)
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2019-04-06 04:13:12 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
date=None,
|
|
|
|
is_reconciled=False,
|
|
|
|
reconcile_date=None,
|
|
|
|
is_starred=None,
|
|
|
|
narration="",
|
|
|
|
posted=False,
|
|
|
|
creation_date=None,
|
|
|
|
last_edit_date=None,
|
2020-05-21 07:41:47 +00:00
|
|
|
type_=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
user_id=None,
|
|
|
|
poster_id=None,
|
|
|
|
):
|
2012-05-01 21:40:01 +00:00
|
|
|
self.date = date
|
2018-07-07 11:01:44 +00:00
|
|
|
self.is_reconciled = is_reconciled
|
2020-05-21 07:41:47 +00:00
|
|
|
self.reconcile_date = reconcile_date or date
|
2018-07-07 11:01:44 +00:00
|
|
|
self.is_starred = is_starred if is_starred is not None else False
|
2012-05-01 21:40:01 +00:00
|
|
|
self.narration = narration
|
|
|
|
self.posted = posted
|
2020-05-21 07:41:47 +00:00
|
|
|
self.creation_date = creation_date or datetime.utcnow()
|
|
|
|
self.last_edit_date = last_edit_date or datetime.utcnow()
|
|
|
|
self.type = type_
|
2012-05-01 21:40:01 +00:00
|
|
|
self.user_id = user_id
|
|
|
|
self.poster_id = poster_id
|
|
|
|
|
2012-11-06 15:07:53 +00:00
|
|
|
|
2012-05-01 21:40:01 +00:00
|
|
|
class Journal(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "journals"
|
|
|
|
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
2020-05-10 15:06:19 +00:00
|
|
|
debit = Column("debit", Integer)
|
|
|
|
amount = Column("amount", Numeric)
|
2020-10-07 16:59:24 +00:00
|
|
|
voucher_id = Column(
|
|
|
|
"voucher_id",
|
|
|
|
UUID(as_uuid=True),
|
|
|
|
ForeignKey("vouchers.id"),
|
|
|
|
nullable=False,
|
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
account_id = Column(
|
|
|
|
"account_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False
|
|
|
|
)
|
|
|
|
cost_centre_id = Column(
|
|
|
|
"cost_centre_id",
|
|
|
|
UUID(as_uuid=True),
|
|
|
|
ForeignKey("cost_centres.id"),
|
|
|
|
nullable=False,
|
|
|
|
)
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2020-05-14 05:56:28 +00:00
|
|
|
voucher = relationship("Voucher", back_populates="journals")
|
|
|
|
account = relationship("AccountBase", back_populates="journals")
|
|
|
|
|
2012-05-01 21:40:01 +00:00
|
|
|
@hybrid_property
|
|
|
|
def signed_amount(self):
|
|
|
|
return self.debit * self.amount
|
|
|
|
|
|
|
|
@property
|
|
|
|
def __name__(self):
|
|
|
|
return self.name
|
|
|
|
|
2019-04-06 04:13:12 +00:00
|
|
|
def __init__(
|
2020-10-07 15:18:43 +00:00
|
|
|
self,
|
|
|
|
id_=None,
|
|
|
|
debit=None,
|
|
|
|
amount=None,
|
|
|
|
voucher_id=None,
|
|
|
|
account_id=None,
|
|
|
|
cost_centre_id=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
):
|
2020-05-29 20:28:17 +00:00
|
|
|
self.id = id_
|
2012-05-01 21:40:01 +00:00
|
|
|
self.debit = debit
|
|
|
|
self.amount = amount
|
|
|
|
self.voucher_id = voucher_id
|
2018-07-07 11:01:44 +00:00
|
|
|
self.account_id = account_id
|
2015-02-12 12:12:46 +00:00
|
|
|
self.cost_centre_id = cost_centre_id
|
2012-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
|
2020-05-21 07:41:47 +00:00
|
|
|
class EmployeeBenefit(Base):
|
|
|
|
__tablename__ = "employee_benefit"
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
2020-10-07 16:59:24 +00:00
|
|
|
voucher_id = Column(
|
|
|
|
"voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False
|
|
|
|
)
|
|
|
|
journal_id = Column(
|
|
|
|
"journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False
|
|
|
|
)
|
2020-05-10 15:06:19 +00:00
|
|
|
gross_salary = Column("gross_salary", Integer)
|
|
|
|
days_worked = Column("days_worked", Integer)
|
|
|
|
esi_ee = Column("esi_employee", Integer)
|
|
|
|
pf_ee = Column("pf_employee", Integer)
|
|
|
|
esi_er = Column("esi_employer", Integer)
|
|
|
|
pf_er = Column("pf_employer", Integer)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
|
|
|
journal = relationship(
|
2020-10-07 15:18:43 +00:00
|
|
|
Journal,
|
|
|
|
backref=backref("employee_benefit", uselist=False),
|
|
|
|
cascade=None,
|
|
|
|
cascade_backrefs=False,
|
2019-04-06 04:13:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2020-05-21 07:41:47 +00:00
|
|
|
id_=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
voucher_id=None,
|
|
|
|
journal_id=None,
|
|
|
|
journal=None,
|
|
|
|
gross_salary=None,
|
|
|
|
days_worked=None,
|
|
|
|
esi_ee=None,
|
|
|
|
pf_ee=None,
|
|
|
|
esi_er=None,
|
|
|
|
pf_er=None,
|
|
|
|
):
|
2020-05-21 07:41:47 +00:00
|
|
|
self.id = id_
|
2012-11-28 07:58:16 +00:00
|
|
|
self.voucher_id = voucher_id
|
|
|
|
self.gross_salary = gross_salary
|
|
|
|
self.days_worked = days_worked
|
|
|
|
self.esi_ee = esi_ee
|
|
|
|
self.pf_ee = pf_ee
|
|
|
|
self.esi_er = esi_er
|
|
|
|
self.pf_er = pf_er
|
2020-06-01 15:10:52 +00:00
|
|
|
if journal is None:
|
|
|
|
self.journal_id = journal_id
|
|
|
|
else:
|
2012-11-28 07:58:16 +00:00
|
|
|
self.journal = journal
|
2012-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
|
2020-05-12 15:22:07 +00:00
|
|
|
class Incentive(Base):
|
|
|
|
__tablename__ = "incentives"
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
2020-10-07 16:59:24 +00:00
|
|
|
voucher_id = Column(
|
|
|
|
"voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False
|
|
|
|
)
|
|
|
|
journal_id = Column(
|
|
|
|
"journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False
|
|
|
|
)
|
2020-05-23 04:15:02 +00:00
|
|
|
days_worked = Column("days_worked", Numeric(precision=5, scale=1), nullable=False)
|
2019-04-06 04:13:12 +00:00
|
|
|
points = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
|
|
|
|
2020-10-07 15:18:43 +00:00
|
|
|
journal = relationship(
|
|
|
|
Journal,
|
|
|
|
backref=backref("incentive", uselist=False),
|
|
|
|
cascade=None,
|
|
|
|
cascade_backrefs=False,
|
|
|
|
)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
|
|
|
def __init__(
|
2020-10-07 15:18:43 +00:00
|
|
|
self,
|
|
|
|
id_=None,
|
|
|
|
voucher_id=None,
|
|
|
|
journal_id=None,
|
|
|
|
journal=None,
|
|
|
|
days_worked=None,
|
|
|
|
points=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
):
|
2020-05-23 04:15:02 +00:00
|
|
|
self.id = id_
|
2015-02-12 12:12:46 +00:00
|
|
|
self.voucher_id = voucher_id
|
2020-05-23 04:15:02 +00:00
|
|
|
if journal is None:
|
|
|
|
self.journal_id = journal_id
|
2020-06-01 15:10:52 +00:00
|
|
|
else:
|
|
|
|
self.journal = journal
|
2015-02-12 12:12:46 +00:00
|
|
|
self.days_worked = days_worked
|
|
|
|
self.points = points
|
|
|
|
|
|
|
|
|
2012-05-01 21:40:01 +00:00
|
|
|
class Inventory(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "inventories"
|
2020-05-10 15:06:19 +00:00
|
|
|
__table_args__ = (UniqueConstraint("voucher_id", "batch_id"),)
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
2020-10-07 16:59:24 +00:00
|
|
|
voucher_id = Column(
|
|
|
|
"voucher_id",
|
|
|
|
UUID(as_uuid=True),
|
|
|
|
ForeignKey("vouchers.id"),
|
|
|
|
nullable=False,
|
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
product_id = Column(
|
|
|
|
"product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False
|
|
|
|
)
|
|
|
|
batch_id = Column(
|
|
|
|
"batch_id", UUID(as_uuid=True), ForeignKey("batches.id"), nullable=False
|
|
|
|
)
|
2020-05-10 15:06:19 +00:00
|
|
|
quantity = Column("quantity", Numeric)
|
|
|
|
rate = Column("rate", Numeric)
|
|
|
|
tax = Column("tax", Numeric)
|
|
|
|
discount = Column("discount", Numeric)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
2020-05-14 06:48:45 +00:00
|
|
|
voucher = relationship("Voucher", back_populates="inventories")
|
|
|
|
|
2019-04-06 04:13:12 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
2020-05-14 06:48:45 +00:00
|
|
|
id_=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
voucher_id=None,
|
|
|
|
product_id=None,
|
|
|
|
batch_id=None,
|
|
|
|
quantity=None,
|
|
|
|
rate=None,
|
|
|
|
tax=None,
|
|
|
|
discount=None,
|
|
|
|
batch=None,
|
2020-05-23 04:15:02 +00:00
|
|
|
product=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
):
|
2020-05-14 06:48:45 +00:00
|
|
|
self.id = id_
|
2012-05-01 21:40:01 +00:00
|
|
|
self.voucher_id = voucher_id
|
2020-05-21 07:41:47 +00:00
|
|
|
if product is None:
|
|
|
|
self.product_id = product_id
|
2020-06-01 15:10:52 +00:00
|
|
|
else:
|
|
|
|
self.product = product
|
2020-05-21 07:41:47 +00:00
|
|
|
if batch is None:
|
|
|
|
self.batch_id = batch_id
|
2020-06-01 15:10:52 +00:00
|
|
|
else:
|
|
|
|
self.batch = batch
|
2012-05-01 21:40:01 +00:00
|
|
|
self.quantity = quantity
|
|
|
|
self.rate = rate
|
|
|
|
self.tax = tax
|
|
|
|
self.discount = discount
|
|
|
|
|
|
|
|
@hybrid_property
|
|
|
|
def amount(self):
|
|
|
|
return self.quantity * self.rate * (1 + self.tax) * (1 - self.discount)
|
|
|
|
|
|
|
|
|
|
|
|
class Batch(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "batches"
|
|
|
|
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
2020-05-21 07:41:47 +00:00
|
|
|
name = Column("name", Date, nullable=False)
|
2020-10-07 16:59:24 +00:00
|
|
|
product_id = Column(
|
|
|
|
"product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False
|
|
|
|
)
|
2020-05-10 15:06:19 +00:00
|
|
|
quantity_remaining = Column("quantity_remaining", Numeric)
|
|
|
|
rate = Column("rate", Numeric)
|
|
|
|
tax = Column("tax", Numeric)
|
|
|
|
discount = Column("discount", Numeric)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
2020-10-07 16:59:24 +00:00
|
|
|
inventories = relationship(
|
|
|
|
"Inventory", backref="batch", cascade=None, cascade_backrefs=False
|
|
|
|
)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
|
|
|
def __init__(
|
2020-10-07 15:18:43 +00:00
|
|
|
self,
|
|
|
|
name=None,
|
|
|
|
product_id=None,
|
|
|
|
quantity_remaining=None,
|
|
|
|
rate=None,
|
|
|
|
tax=None,
|
|
|
|
discount=None,
|
|
|
|
product=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
):
|
2012-05-01 21:40:01 +00:00
|
|
|
self.name = name
|
|
|
|
self.product_id = product_id
|
|
|
|
self.quantity_remaining = quantity_remaining
|
|
|
|
self.rate = rate
|
|
|
|
self.tax = tax
|
|
|
|
self.discount = discount
|
2020-05-21 07:41:47 +00:00
|
|
|
if product is None:
|
|
|
|
self.product_id = product_id
|
2020-06-01 15:10:52 +00:00
|
|
|
else:
|
|
|
|
self.product = product
|
2012-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
def amount(self):
|
2020-10-07 16:59:24 +00:00
|
|
|
return (
|
|
|
|
self.quantity_remaining * self.rate * (1 + self.tax) * (1 - self.discount)
|
|
|
|
)
|
2012-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
@classmethod
|
2020-05-29 20:28:17 +00:00
|
|
|
def list(cls, name, include_nil, date, db: Session):
|
|
|
|
query = db.query(Batch).join(Batch.product)
|
2012-09-10 12:22:24 +00:00
|
|
|
if not include_nil:
|
2012-05-01 21:40:01 +00:00
|
|
|
query = query.filter(cls.quantity_remaining > 0)
|
2013-10-01 09:10:16 +00:00
|
|
|
if date is not None:
|
|
|
|
query = query.filter(cls.name <= date)
|
2012-05-01 21:40:01 +00:00
|
|
|
for item in name.split():
|
2020-05-29 20:28:17 +00:00
|
|
|
query = query.filter(Product.name.ilike(f"%{item}%"))
|
2013-06-21 10:50:50 +00:00
|
|
|
return query.order_by(Product.name).order_by(cls.name).all()
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2013-10-14 17:53:00 +00:00
|
|
|
@classmethod
|
|
|
|
def suspense(cls):
|
2019-04-06 04:13:12 +00:00
|
|
|
return uuid.UUID("a955790e-93cf-493c-a816-c7d92b127383")
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2013-11-20 12:54:38 +00:00
|
|
|
|
2012-05-01 21:40:01 +00:00
|
|
|
class Attendance(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "attendances"
|
|
|
|
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
|
|
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
2020-05-14 16:19:22 +00:00
|
|
|
date = Column("date", Date, nullable=False)
|
2020-05-10 15:06:19 +00:00
|
|
|
attendance_type = Column("attendance_type", Integer)
|
|
|
|
amount = Column("amount", Numeric)
|
|
|
|
creation_date = Column("creation_date", DateTime(timezone=True))
|
2020-06-30 06:02:09 +00:00
|
|
|
user_id = Column("user_id", UUID(as_uuid=True), ForeignKey("auth_users.id"))
|
2020-05-10 15:06:19 +00:00
|
|
|
is_valid = Column("is_valid", Boolean)
|
2019-04-06 04:13:12 +00:00
|
|
|
|
|
|
|
user = relationship("User", primaryjoin="User.id==Attendance.user_id")
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2020-05-29 20:28:17 +00:00
|
|
|
id_=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
employee_id=None,
|
|
|
|
date=None,
|
|
|
|
attendance_type=None,
|
|
|
|
amount=None,
|
|
|
|
creation_date=None,
|
|
|
|
user_id=None,
|
|
|
|
is_valid=None,
|
|
|
|
):
|
2020-05-29 20:28:17 +00:00
|
|
|
self.id = id_
|
2012-05-01 21:40:01 +00:00
|
|
|
self.employee_id = employee_id
|
|
|
|
self.date = date
|
|
|
|
self.attendance_type = attendance_type
|
2012-10-25 19:33:57 +00:00
|
|
|
self.amount = amount if amount is not None else 0
|
2020-05-29 20:28:17 +00:00
|
|
|
self.creation_date = creation_date or datetime.utcnow()
|
2012-05-01 21:40:01 +00:00
|
|
|
self.user_id = user_id
|
2012-10-25 19:33:57 +00:00
|
|
|
self.is_valid = is_valid if is_valid is not None else True
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2020-05-29 20:28:17 +00:00
|
|
|
def create(self, db: Session):
|
2019-04-06 04:13:12 +00:00
|
|
|
old = (
|
2020-05-29 20:28:17 +00:00
|
|
|
db.query(Attendance)
|
2019-04-06 04:13:12 +00:00
|
|
|
.filter(Attendance.date == self.date)
|
|
|
|
.filter(Attendance.employee_id == self.employee_id)
|
|
|
|
.filter(Attendance.is_valid == True)
|
|
|
|
.first()
|
|
|
|
)
|
2012-11-30 17:23:16 +00:00
|
|
|
if old is None or old.attendance_type != self.attendance_type:
|
|
|
|
if old is not None:
|
|
|
|
old.is_valid = False
|
2020-06-01 15:10:52 +00:00
|
|
|
db.add(self)
|
2012-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
|
2013-10-03 10:12:43 +00:00
|
|
|
class Fingerprint(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "fingerprints"
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
|
|
employee_id = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
|
2020-05-10 15:06:19 +00:00
|
|
|
date = Column("date", DateTime)
|
2012-05-01 21:40:01 +00:00
|
|
|
|
2020-06-01 15:10:52 +00:00
|
|
|
def __init__(self, id_=None, employee_id=None, date=None):
|
|
|
|
self.id = id_
|
2013-04-14 11:09:55 +00:00
|
|
|
self.employee_id = employee_id
|
2012-05-01 21:40:01 +00:00
|
|
|
self.date = date
|
|
|
|
self.fingerprint_type = 0
|
|
|
|
|
2014-06-03 11:42:52 +00:00
|
|
|
|
|
|
|
class DbImage(Base):
|
2019-04-06 04:13:12 +00:00
|
|
|
__tablename__ = "images"
|
|
|
|
|
2020-06-30 06:02:09 +00:00
|
|
|
id = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
|
|
resource_id = Column("resource_id", UUID(as_uuid=True), nullable=False)
|
2019-04-06 04:13:12 +00:00
|
|
|
resource_type = Column("resource_type", Unicode(255), nullable=False)
|
|
|
|
image = Column("image", BYTEA, nullable=False)
|
|
|
|
thumbnail = Column("thumbnail", BYTEA, nullable=False)
|
|
|
|
creation_date = Column("creation_date", DateTime(timezone=True), nullable=False)
|
|
|
|
|
|
|
|
def __init__(
|
2020-10-07 15:18:43 +00:00
|
|
|
self,
|
|
|
|
resource_id=None,
|
|
|
|
resource_type=None,
|
|
|
|
image=None,
|
|
|
|
thumbnail=None,
|
|
|
|
creation_date=None,
|
|
|
|
id_=None,
|
2019-04-06 04:13:12 +00:00
|
|
|
):
|
2014-06-03 11:42:52 +00:00
|
|
|
self.resource_id = resource_id
|
|
|
|
self.resource_type = resource_type
|
|
|
|
self.image = image
|
|
|
|
self.thumbnail = thumbnail
|
2020-05-29 20:28:17 +00:00
|
|
|
self.creation_date = creation_date or datetime.utcnow()
|
|
|
|
self.id = id_
|