From 77e3945f1e227d4e84b03a0b2e8f986a575c5c85 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Sun, 14 Apr 2013 16:39:55 +0530 Subject: [PATCH] To Upgrade Bengali Data --- brewman/brewman/factories.py | 3 +- brewman/brewman/models/__init__.py | 28 ++----------- brewman/brewman/models/guidtype.py | 6 ++- brewman/brewman/models/voucher.py | 10 ++--- brewman/brewman/views/auth/user.py | 42 +++++++++++++++++-- brewman/brewman/views/reports/unposted.py | 2 +- .../views/services/voucher/__init__.py | 5 ++- 7 files changed, 58 insertions(+), 38 deletions(-) diff --git a/brewman/brewman/factories.py b/brewman/brewman/factories.py index af7cf9cd..c678d871 100644 --- a/brewman/brewman/factories.py +++ b/brewman/brewman/factories.py @@ -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): diff --git a/brewman/brewman/models/__init__.py b/brewman/brewman/models/__init__.py index c7bf3ee6..bee99ef8 100644 --- a/brewman/brewman/models/__init__.py +++ b/brewman/brewman/models/__init__.py @@ -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() -# diff --git a/brewman/brewman/models/guidtype.py b/brewman/brewman/models/guidtype.py index 48a366be..cdc2e8af 100644 --- a/brewman/brewman/models/guidtype.py +++ b/brewman/brewman/models/guidtype.py @@ -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 \ No newline at end of file diff --git a/brewman/brewman/models/voucher.py b/brewman/brewman/models/voucher.py index e5077504..d7c77c67 100644 --- a/brewman/brewman/models/voucher.py +++ b/brewman/brewman/models/voucher.py @@ -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 diff --git a/brewman/brewman/views/auth/user.py b/brewman/brewman/views/auth/user.py index 3f6d06bb..7c03302b 100644 --- a/brewman/brewman/views/auth/user.py +++ b/brewman/brewman/views/auth/user.py @@ -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() + diff --git a/brewman/brewman/views/reports/unposted.py b/brewman/brewman/views/reports/unposted.py index b4b37b75..65cc8292 100644 --- a/brewman/brewman/views/reports/unposted.py +++ b/brewman/brewman/views/reports/unposted.py @@ -1,4 +1,4 @@ -from sqlalchemy.orm import joinedload_all +from sqlalchemy.orm import joinedload_all from pyramid.view import view_config diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py index 8128b1bd..64c2b490 100644 --- a/brewman/brewman/views/services/voucher/__init__.py +++ b/brewman/brewman/views/services/voucher/__init__.py @@ -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)