Refactor payment model and enhance error handling in PCPD view

1 parent 32935e41
from datetime import timedelta, datetime from pyexpat import model
import sys import sys
from opensipkd.base.models import ( from opensipkd.base import models
Base, CommonModel, DefaultModel, NamaModel, KodeModel, from sqlalchemy import (Column, Integer, DateTime, String, Float,
TABLE_ARGS BigInteger, SmallInteger, Date, Time,
)
from sqlalchemy import (Column, Integer, DateTime, String, Text, ForeignKey, Float,
Boolean, BigInteger, SmallInteger, desc, asc, Date, Time,
UniqueConstraint, func, literal_column) UniqueConstraint, func, literal_column)
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import engine_from_config from sqlalchemy import engine_from_config
...@@ -20,11 +17,34 @@ from pyramid.paster import ( ...@@ -20,11 +17,34 @@ from pyramid.paster import (
setup_logging, setup_logging,
) )
from ..tools import create_now
PCDBSession = scoped_session(sessionmaker()) PCDBSession = scoped_session(sessionmaker())
PCBase = declarative_base() PCBase = declarative_base()
class DefaultModel(models.DefaultModel):
@classmethod
def count(cls, db_session=PCDBSession):
return super().count(db_session)
@classmethod
def query(cls, db_session=PCDBSession, filters=None):
return super().query(db_session, filters)
@classmethod
def query_from(cls, columns=None, filters=None, db_session=PCDBSession):
return super().query_from(columns, filters, db_session)
@classmethod
def query_id(cls, row_id, db_session=PCDBSession):
return super.query_id(row_id, db_session)
@classmethod
def delete(cls, row_id, db_session=PCDBSession):
super().delete(row_id, db_session)
@classmethod
def flush(cls, row, db_session=PCDBSession):
super().flush(row, db_session)
class PaymentPBB(PCBase, DefaultModel): class PaymentPBB(PCBase, DefaultModel):
__tablename__ = 'pbb_report' __tablename__ = 'pbb_report'
...@@ -74,7 +94,7 @@ class PaymentPBB(PCBase, DefaultModel): ...@@ -74,7 +94,7 @@ class PaymentPBB(PCBase, DefaultModel):
# baru dari db BPHTB # baru dari db BPHTB
class PaymentBPHTB(PCBase, CommonModel): class PaymentBPHTB(PCBase, models.CommonModel):
__tablename__ = 'bphtb_report' __tablename__ = 'bphtb_report'
__table_args__ = {'schema': 'public'} __table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
...@@ -114,7 +134,7 @@ class PaymentBPHTB(PCBase, CommonModel): ...@@ -114,7 +134,7 @@ class PaymentBPHTB(PCBase, CommonModel):
# baru PAD # baru PAD
class PaymentPAD(PCBase, CommonModel): class PaymentPAD(PCBase, models.CommonModel):
__tablename__ = 'pad_report' __tablename__ = 'pad_report'
__table_args__ = {'schema': 'public'} __table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
...@@ -168,7 +188,7 @@ class PaymentPAD(PCBase, CommonModel): ...@@ -168,7 +188,7 @@ class PaymentPAD(PCBase, CommonModel):
# baru PAD # baru PAD
class PaymentWEBR(PCBase, CommonModel): class PaymentWEBR(PCBase, models.CommonModel):
__tablename__ = 'webr_report' __tablename__ = 'webr_report'
__table_args__ = {'schema': 'public'} __table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
...@@ -208,7 +228,7 @@ class PaymentWEBR(PCBase, CommonModel): ...@@ -208,7 +228,7 @@ class PaymentWEBR(PCBase, CommonModel):
return qry return qry
class TargetJNS(PCBase, CommonModel): class TargetJNS(PCBase, models.CommonModel):
__tablename__ = 'target_jenis' __tablename__ = 'target_jenis'
__table_args__ = {'schema': 'public'} __table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
...@@ -244,6 +264,7 @@ class Targets(PCBase, DefaultModel): ...@@ -244,6 +264,7 @@ class Targets(PCBase, DefaultModel):
m11 = Column(BigInteger) m11 = Column(BigInteger)
m12 = Column(BigInteger) m12 = Column(BigInteger)
status = Column(SmallInteger) status = Column(SmallInteger)
@classmethod @classmethod
def query_from(cls, columns=None, filters=None, db_session=PCDBSession): def query_from(cls, columns=None, filters=None, db_session=PCDBSession):
query = db_session.query().select_from(cls) query = db_session.query().select_from(cls)
......
...@@ -287,7 +287,11 @@ class Views(BaseView): ...@@ -287,7 +287,11 @@ class Views(BaseView):
week, weekTrx, weekly, weeklyTrx, weeklyAcc, weeklyAccTrx = \ week, weekTrx, weekly, weeklyTrx, weeklyAcc, weeklyAccTrx = \
self.get_daily_data(PembayaranSppt, field, None, filter_exp) self.get_daily_data(PembayaranSppt, field, None, filter_exp)
ytd_target = self.get_targets("pbb") try:
ytd_target = self.get_targets("pbb")
except:
ytd_target = 0
ytd_persen = round(ytd/ytd_target * 100, 2) if ytd_target > 0 else 0 ytd_persen = round(ytd/ytd_target * 100, 2) if ytd_target > 0 else 0
return {"today": amt, return {"today": amt,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!