Commit efdc7ee9 by aa.gusti

perbaikan maps.pt

1 parent f587ac36
# from sqlalchemy import Column, Integer, SmallInteger, ForeignKey, UniqueConstraint, String
# from sqlalchemy.orm import relationship, backref
#
# from . import Base, NamaModel, TABLE_ARGS
#
#
# class Rekening(NamaModel, Base):
# __tablename__ = 'rekening'
# # level_id = Column(SmallInteger, default=1)
# parent_id = Column(Integer, ForeignKey('rekening.id'), )
# path = Column(String(255))
# status = Column(SmallInteger, default=1)
# category = Column(String(32))
# children = relationship(
# "Rekening", backref=backref('parent_id', remote_side='Rekening.id'))
# parent = relationship("Rekening", remote_side=[parent_id])
# __table_args__ = (
# UniqueConstraint('kode', name='rekening_uq'), TABLE_ARGS)
#
# @classmethod
# def get_next_level(cls, cid):
# return cls.query_id(cid).first().level_id + 1
from datetime import datetime
from sqlalchemy import Column, String, Integer, ForeignKey
from opensipkd.base.models import Kelurahan, Kecamatan, Kota, Provinsi
from . import Partner
from ..models import DBSession, Base
from ..models import (NamaModel,
TABLE_ARGS)
class Company(Base, NamaModel):
__tablename__ = 'company'
kategori = Column(String(32))
partner_id = Column(Integer, ForeignKey(Partner.id))
logo = Column(String(255))
alamat = Column(String(255))
alamat2 = Column(String(255))
kelurahan_id = Column(Integer, ForeignKey(Kelurahan.id))
kecamatan_id = Column(Integer, ForeignKey(Kecamatan.id))
kota_id = Column(Integer, ForeignKey(Kota.id))
provinsi_id = Column(Integer, ForeignKey(Provinsi.id))
__table_args__ = (TABLE_ARGS,)
@classmethod
def save(cls, values, user, row=None, **kwargs):
if not row:
row = Company()
row.created = datetime.now()
row.create_uid = user.id
row.from_dict(values)
row.updated = datetime.now()
row.update_uid = user.id
row.status = 'status' in values and values['status'] and 1 or 0
DBSession.add(row)
DBSession.flush()
return row
@classmethod
def kategori_get(cls):
return (("kota", "Kota"),
("kab", "Kabupaten"),
("prov", "Provinsi"))
from sqlalchemy import (
Column,
Integer,
ForeignKey, UniqueConstraint, String
)
from sqlalchemy.orm import relationship
from ..models import NamaModel, Base, TABLE_ARGS
class Provinsi(Base, NamaModel):
__tablename__ = 'provinsi'
__table_args__ = (
UniqueConstraint('kode'),
TABLE_ARGS
)
class Kota(Base, NamaModel):
__tablename__ = 'kota'
provinsi_id = Column(Integer, ForeignKey(Provinsi.id))
__table_args__ = (
UniqueConstraint('provinsi_id', 'kode'),
TABLE_ARGS
)
provinsi = relationship('Provinsi', backref='kota')
class Kecamatan(Base, NamaModel):
__tablename__ = 'kecamatan'
kota_id = Column(Integer, ForeignKey(Kota.id))
__table_args__ = (
UniqueConstraint('kota_id', 'kode'),
TABLE_ARGS
)
kota = relationship('Kota', backref='kecamatan')
class Kelurahan(Base, NamaModel):
__tablename__ = 'kelurahan'
kecamatan_id = Column(Integer, ForeignKey(Kecamatan.id))
__table_args__ = (
UniqueConstraint('kecamatan_id', 'kode'),
TABLE_ARGS
)
kecamatan = relationship('Kecamatan', backref='kelurahan')
class AlamatModel(object):
alamat = Column(String(255))
alamat2 = Column(String(255))
kelurahan_id = Column(Integer, ForeignKey(Kelurahan.id))
kecamatan_id = Column(Integer, ForeignKey(Kecamatan.id))
kota_id = Column(Integer, ForeignKey(Kota.id))
provinsi_id = Column(Integer, ForeignKey(Provinsi.id))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!