stpd.py
2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from sqlalchemy import (
Column,
Integer,
DateTime,
ForeignKey,
UniqueConstraint,
Float,
func,
Time)
from sqlalchemy.schema import FetchedValue
from sqlalchemy.orm import (relationship, backref)
from datetime import datetime
from opensipkd.pjdl.models.spt_invoice import PjdlInvoice
from . import PAD_TABLE_ARGS, DefaultModel, Base
from . import (DBSession)
from opensipkd.tools import date_from_str, ymd
class PjdlStpd(Base, DefaultModel):
__tablename__ = 'pad_stpd'
__table_args__ = (
UniqueConstraint('tahun', 'stpdno'),
PAD_TABLE_ARGS
)
id = Column(Integer, primary_key=True)
tahun = Column(Integer, nullable=False)
stpdno = Column(Integer, nullable=False)
stpdtgl = Column(DateTime, nullable=False)
spt_id = Column(Integer, ForeignKey(PjdlInvoice.id), nullable=False, )
jatuhtempotgl = Column(DateTime)
printed = Column(Integer, nullable=False)
stpdcount = Column(Integer, nullable=False)
bunga = Column(Float)
opsen_bunga = Column(Float)
enabled = Column(Integer)
create_date = Column(DateTime)
create_uid = Column(Integer)
write_date = Column(DateTime)
write_uid = Column(Integer)
invoice = relationship(
'PjdlInvoice', primaryjoin='PjdlInvoice.id == PjdlStpd.spt_id', backref='stpd')
@classmethod
def get_join(cls):
result = DBSession.query(cls.spt_id, func.max(cls.id).label('id'),
func.max(cls.stpdno).label('stpdno'),
func.max(cls.stpdcount).label('stpdcount'),
func.max(cls.stpdtgl).label('stpdtgl'),
func.max(cls.jatuhtempotgl).label(
'jatuhtempotgl'),
func.max(cls.bunga).label('bunga')).\
group_by(cls.spt_id).subquery()
return result
@classmethod
def generate_stpdno(cls, tahun=None):
if not tahun:
tahun = datetime.now().year
result = DBSession.query(func.max(cls.stpdno)).\
filter_by(tahun=tahun).scalar()
result = result and result > 0 and result+1 or 1
return result
@classmethod
def get_stpno(self, id=None):
stpno = func.get_stpno(id)
return stpno