To Upgrade Bengali Data
This commit is contained in:
parent
399d0c88f2
commit
77e3945f1e
@ -2,7 +2,8 @@ from pyramid.security import Everyone
|
||||
from pyramid.security import Authenticated
|
||||
from pyramid.security import Allow
|
||||
from brewman.models.auth import Role
|
||||
|
||||
from brewman.models.master import *
|
||||
from brewman.models.voucher import *
|
||||
class RootFactory(object):
|
||||
@property
|
||||
def __acl__(self):
|
||||
|
@ -11,29 +11,7 @@ Base = declarative_base()
|
||||
def initialize_sql(engine):
|
||||
DBSession.configure(bind=engine)
|
||||
Base.metadata.bind = engine
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
|
||||
def populate():
|
||||
""" Populate initial data and table structure
|
||||
"""
|
||||
pass
|
||||
# try:
|
||||
# Base.metadata.create_all(engine)
|
||||
# session = DBSession()
|
||||
#
|
||||
# home = Sitmap('Home','/', 1)
|
||||
# session.add(home)
|
||||
# login = Sitmap('Login','/Login', 2)
|
||||
# session.add(login)
|
||||
# logout = Sitmap('Logout','/Logout', 3)
|
||||
# session.add(logout)
|
||||
#
|
||||
# session.add(Sitemap('Sub1',/Sub1',1,home.id))
|
||||
# session.add(Sitemap('Sub2',/Sub2',2,home.id))
|
||||
# session.add(Sitemap('Sub3',/Sub3',1,login.id))
|
||||
# session.add(Sitemap('Sub4',/Sub4',1,login.id))
|
||||
#
|
||||
# session.flush()
|
||||
# transaction.commit()
|
||||
# except IntegrityError:
|
||||
# transaction.abort()
|
||||
#
|
||||
|
@ -47,8 +47,10 @@ class GUID(TypeDecorator):
|
||||
def process_result_value(self,value,dialect=None):
|
||||
if value is None:
|
||||
return None
|
||||
else:
|
||||
elif isinstance(value, bytes):
|
||||
return uuid.UUID(bytes=value)
|
||||
|
||||
else:
|
||||
return uuid.UUID(value)
|
||||
|
||||
def is_mutable(self):
|
||||
return False
|
@ -55,7 +55,7 @@ class Voucher(Base):
|
||||
id = Column('VoucherID', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
date = Column('Date', DateTime)
|
||||
reconcilliation_date = Column('ReconcilliationDate', DateTime)
|
||||
narration = Column('Narration', Unicode(255))
|
||||
narration = Column('Narration', Unicode(1000))
|
||||
posted = Column('Posted', Boolean)
|
||||
creation_date = Column('CreationDate', DateTime)
|
||||
last_edit_date = Column('LastEditDate', DateTime)
|
||||
@ -301,12 +301,12 @@ class Fingerprint(Base):
|
||||
__tablename__ = 'entities_fingerprints'
|
||||
|
||||
id = Column('FingerprintID', GUID(), primary_key=True, default=uuid.uuid4)
|
||||
employee_code = Column('EmployeeCode', Integer, ForeignKey('entities_ledgers.Code'))
|
||||
employee_id = Column('EmployeeID', GUID(), ForeignKey('entities_employees.LedgerID'))
|
||||
date = Column('Date', DateTime)
|
||||
|
||||
def __init__(self, id=None, employee_code=None, date=None):
|
||||
def __init__(self, id=None, employee_id=None, date=None):
|
||||
self.id = id
|
||||
self.employee_code = employee_code
|
||||
self.employee_id = employee_id
|
||||
self.date = date
|
||||
self.fingerprint_type = 0
|
||||
|
||||
@ -320,7 +320,7 @@ class Fingerprint(Base):
|
||||
|
||||
def create(self):
|
||||
old = DBSession.query(Fingerprint).filter(Fingerprint.date == self.date)\
|
||||
.filter(Fingerprint.employee_code == self.employee_code).first()
|
||||
.filter(Fingerprint.employee_id == self.employee_id).first()
|
||||
if old is None:
|
||||
DBSession.add(self)
|
||||
return self
|
||||
|
@ -1,13 +1,19 @@
|
||||
import os
|
||||
import re
|
||||
import uuid
|
||||
from pyramid.response import Response
|
||||
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
import transaction
|
||||
from brewman.models import DBSession
|
||||
from brewman.models.auth import User, Group
|
||||
from brewman.models.auth import User, Group, Role, Client, user_group, role_group
|
||||
from brewman.models.master import ProductGroup, CostCenter, Ledger, Employee, Product
|
||||
|
||||
from brewman.models.validation_exception import TryCatchFunction
|
||||
from brewman.models.voucher import Inventory, Voucher, Journal, Attendance, Batch, SalaryDeduction
|
||||
|
||||
from brewman.models.validation_exception import ValidationError, TryCatchFunction
|
||||
|
||||
@view_config(route_name='user_list', renderer='brewman:templates/angular_base.mako', permission='Users')
|
||||
@view_config(request_method='GET', route_name='user_id', renderer='brewman:templates/angular_base.mako',
|
||||
@ -84,8 +90,11 @@ def show_blank(request):
|
||||
return user_info(None)
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='api_user', renderer='json', request_param='list', permission='Users')
|
||||
# @view_config(request_method='GET', route_name='api_user', renderer='json', request_param='list', permission='Users')
|
||||
# for import
|
||||
@view_config(request_method='GET', route_name='api_user', renderer='json', request_param='list')
|
||||
def show_list(request):
|
||||
populate_from_old()
|
||||
list = User.list()
|
||||
users = []
|
||||
for item in list:
|
||||
@ -114,3 +123,30 @@ def user_info(id):
|
||||
return account
|
||||
|
||||
|
||||
def make_session(connection_string):
|
||||
engine = create_engine(connection_string, echo=False, convert_unicode=True)
|
||||
Session = sessionmaker(bind=engine)
|
||||
return Session(), engine
|
||||
|
||||
def copy(source, destination, table):
|
||||
for i in source.query(table).all():
|
||||
destination.merge(i)
|
||||
destination.commit()
|
||||
|
||||
def populate_from_old():
|
||||
""" Populate initial data and table structure
|
||||
"""
|
||||
source, sengine = make_session('sqlite:///' + os.getcwd() + '/database/brewman1.db')
|
||||
destination, dengine = make_session('postgresql://postgres:123456@localhost:5432/brewman')
|
||||
|
||||
for i in [Group, ProductGroup, CostCenter, Role, Client, User, Voucher, Ledger, Employee, Journal,
|
||||
Product, Attendance, SalaryDeduction, Batch, Inventory]:
|
||||
copy(source, destination, i)
|
||||
|
||||
# for i in source.query(user_group).all():
|
||||
# destination.merge(i)
|
||||
# destination.commit()
|
||||
# for i in source.query(role_group).all():
|
||||
# destination.merge(i)
|
||||
# destination.commit()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
|
||||
from pyramid.view import view_config
|
||||
|
||||
|
@ -86,6 +86,7 @@ def delete(request):
|
||||
if permission is not None:
|
||||
return permission
|
||||
json_voucher = voucher_info(voucher)
|
||||
batches_to_delete = []
|
||||
if voucher.type == VoucherType.by_name('Issue').id:
|
||||
for item in voucher.journals:
|
||||
if item.debit == 1:
|
||||
@ -112,10 +113,12 @@ def delete(request):
|
||||
.filter(Inventory.id != item.id).scalar()
|
||||
if uses > 0:
|
||||
raise ValueError('{0} has been issued and cannot be deleted'.format(item.product.name))
|
||||
DBSession.delete(item.batch)
|
||||
batches_to_delete.append(item.batch)
|
||||
elif voucher.type == VoucherType.by_name('Purchase Return').id:
|
||||
for item in voucher.inventories:
|
||||
item.batch.quantity_remaining += item.quantity
|
||||
for b in batches_to_delete:
|
||||
DBSession.delete(b)
|
||||
DBSession.delete(voucher)
|
||||
transaction.commit()
|
||||
return blank_voucher(additionalInfo=json_voucher)
|
||||
|
Loading…
Reference in New Issue
Block a user