diff --git a/brewman/__init__.py b/brewman/__init__.py index c801b91a..40e16a02 100644 --- a/brewman/__init__.py +++ b/brewman/__init__.py @@ -59,7 +59,7 @@ def main(global_config, **settings): config.add_route('api_account_type_list', '/api/AccountTypes') - add_route(config, 'cost_center', '/CostCenter') + add_route(config, 'cost_centre', '/CostCentre') add_route(config, 'account', '/Account') add_route(config, 'employee', '/Employee') add_route(config, 'user', '/User') @@ -84,6 +84,8 @@ def main(global_config, **settings): config.add_route('api_issues_grid', '/api/Issues/Services/{date}') config.add_route('salary_deduction_id', '/SalaryDeduction/{id}') config.add_route('salary_deduction', '/SalaryDeduction') + config.add_route('service_charge_id', '/ServiceCharge/{id}') + config.add_route('service_charge', '/ServiceCharge') config.add_route('db_image', '/api/DbImage/{id}/{type}') config.add_route('api_voucher_id', '/api/Voucher/{id}') @@ -106,7 +108,6 @@ def main(global_config, **settings): config.add_route('attendance_report', '/AttendanceReport') config.add_route('api_credit_salary', '/api/CreditSalary') - config.add_route('api_credit_service_charge', '/api/CreditServiceCharge') config.add_route('employee_functions', '/EmployeeFunctions') config.add_route('api_fingerprint', '/api/Fingerprint') diff --git a/brewman/models/__init__.py b/brewman/models/__init__.py index efa23be3..4f598804 100644 --- a/brewman/models/__init__.py +++ b/brewman/models/__init__.py @@ -27,7 +27,7 @@ def fixtures(engine): import uuid from brewman.models.messaging import Tag, Thread, Subscriber, thread_tag, Post from brewman.models.voucher import Attendance, Batch, Fingerprint, Inventory, Journal, Product, SalaryDeduction, Voucher, VoucherType - from brewman.models.master import Product, AttendanceType, CostCenter, Employee, Ledger, LedgerBase, LedgerType, ProductGroup, MenuItem, Recipe, RecipeItem + from brewman.models.master import Product, AttendanceType, CostCentre, Employee, Ledger, LedgerBase, LedgerType, ProductGroup, MenuItem, Recipe, RecipeItem from brewman.models.auth import Client, Group, Role, User, role_group, user_group, LoginHistory Base.metadata.create_all(engine) @@ -46,7 +46,7 @@ def fixtures(engine): roles = [Role('Attendance', uuid.UUID('09d05434-a09a-fa45-963b-769a2e3fc667')), Role('Trial Balance', uuid.UUID('3b099fec-ddc5-4243-b30e-afb78d9ca14a')), Role('Cash Flow', uuid.UUID('c4d3ae29-420b-ea4c-ae90-00a356263fd9')), - Role('Cost Centers', uuid.UUID('6fcc1a20-6aec-e840-b334-1632b34aeab8')), + Role('Cost Centres', uuid.UUID('6fcc1a20-6aec-e840-b334-1632b34aeab8')), Role('Users', uuid.UUID('c5b7d9d7-f178-0e45-8ea4-bf4e08ec901b')), Role('Daybook', uuid.UUID('c3edb554-a057-8942-8030-37b8e926d583')), Role('Edit Posted Vouchers', uuid.UUID('d6675817-ddf5-bf40-9de6-fa223eb4aaa6')), @@ -84,18 +84,19 @@ def fixtures(engine): Role('Stock Movement', uuid.UUID('20b707ee-2b59-41ad-be87-76d5fe1efca8')), Role('Purchases', uuid.UUID('cf7019c8-3fd3-45b0-9a42-601029ce5b71')), Role('Dashboard', uuid.UUID('53eecc09-bd06-4890-b6f5-6885dda762d4')), + Role('Service Charge', uuid.UUID('99b56390-96c2-4f3d-8b0f-5ae3c868594f')), Role('Maintenance', uuid.UUID('770532e4-21de-4712-8a6b-4ff9fd63a503'))] for role in roles: DBSession.add(role) groups[0].roles.append(role) - cost_centers = [CostCenter('Overall', uuid.UUID('36f59436-522a-0746-ae94-e0f746bf6c0d'), True), - CostCenter('Purchase', uuid.UUID('7b845f95-dfef-fa4a-897c-f0baf15284a3'), True), - CostCenter('Kitchen', uuid.UUID('b2d398ce-e3cc-c542-9feb-5d7783e899df'), True)] + cost_centres = [CostCentre('Overall', uuid.UUID('36f59436-522a-0746-ae94-e0f746bf6c0d'), True), + CostCentre('Purchase', uuid.UUID('7b845f95-dfef-fa4a-897c-f0baf15284a3'), True), + CostCentre('Kitchen', uuid.UUID('b2d398ce-e3cc-c542-9feb-5d7783e899df'), True)] - for cost_center in cost_centers: - DBSession.add(cost_center) + for cost_centre in cost_centres: + DBSession.add(cost_centre) ledgers = [Ledger(1, 'All Purchases', 2, True, False, uuid.UUID('7b845f95-dfef-fa4a-897c-f0baf15284a3'), uuid.UUID('240dd899-c413-854c-a7eb-67a29d154490'), True), diff --git a/brewman/models/master.py b/brewman/models/master.py index eee8d1c6..3899a81e 100644 --- a/brewman/models/master.py +++ b/brewman/models/master.py @@ -197,15 +197,15 @@ class ProductGroup(Base): return uuid.UUID('e6bf81b9-1e9b-499f-81d5-ab5662e9d9b1') -class CostCenter(Base): - __tablename__ = 'cost_centers' +class CostCentre(Base): + __tablename__ = 'cost_centres' - id = Column('CostCenterID', GUID(), primary_key=True, default=uuid.uuid4) + id = Column('CostCentreID', GUID(), primary_key=True, default=uuid.uuid4) name = Column('Name', Unicode(255), unique=True) is_fixture = Column('IsFixture', Boolean, nullable=False) - ledgers = relationship('LedgerBase', backref='costcenter') - journals = relationship('Journal', backref='costcenter') + ledgers = relationship('LedgerBase', backref='cost_centre') + journals = relationship('Journal', backref='cost_centre') @property def __name__(self): @@ -225,20 +225,20 @@ class CostCenter(Base): return DBSession.query(cls).order_by(cls.name).all() @classmethod - def cost_center_purchase(cls): + def cost_centre_purchase(cls): return uuid.UUID('7b845f95-dfef-fa4a-897c-f0baf15284a3') @classmethod - def cost_center_kitchen(cls): + def cost_centre_kitchen(cls): return uuid.UUID('b2d398ce-e3cc-c542-9feb-5d7783e899df') @classmethod - def cost_center_overall(cls): + def cost_centre_overall(cls): return uuid.UUID('36f59436-522a-0746-ae94-e0f746bf6c0d') @classmethod def overall(cls): - return {'CostCenterID': uuid.UUID('36f59436-522a-0746-ae94-e0f746bf6c0d'), 'Name': 'Overall'} + return {'CostCentreID': uuid.UUID('36f59436-522a-0746-ae94-e0f746bf6c0d'), 'Name': 'Overall'} class LedgerBase(Base): @@ -251,7 +251,7 @@ class LedgerBase(Base): ledger_type = Column('ledger_type', Unicode(50), nullable=False) is_active = Column('IsActive', Boolean) is_reconcilable = Column('IsReconcilable', Boolean) - costcenter_id = Column('CostCenterID', GUID(), ForeignKey('cost_centers.CostCenterID')) + cost_centre_id = Column('CostCentreID', GUID(), ForeignKey('cost_centres.CostCentreID')) is_fixture = Column('IsFixture', Boolean, nullable=False) __mapper_args__ = {'polymorphic_on': ledger_type} @@ -266,14 +266,14 @@ class LedgerBase(Base): def type_object(self): return LedgerType.by_id(self.type) - def __init__(self, code=None, name=None, type=None, is_active=None, is_reconcilable=False, costcenter_id=None, + def __init__(self, code=None, name=None, type=None, is_active=None, is_reconcilable=False, cost_centre_id=None, id=None, is_fixture=False): self.code = code self.name = name self.type = type self.is_active = is_active self.is_reconcilable = is_reconcilable - self.costcenter_id = costcenter_id + self.cost_centre_id = cost_centre_id self.id = id self.is_fixture = is_fixture @@ -351,6 +351,10 @@ class LedgerBase(Base): def service_charge(cls): return {'LedgerID': 'b7eff754-e8ba-e047-ab06-9132c15c7640', 'Name': 'Service Charges'} + @classmethod + def service_charge_id(cls): + return uuid.UUID('b7eff754-e8ba-e047-ab06-9132c15c7640') + @classmethod def esi_pf_expense(cls): return uuid.UUID('d2a1a286-e900-764b-a1a5-9f4b00dbb940') @@ -378,7 +382,7 @@ class Employee(LedgerBase): attendances = relationship('Attendance', backref='employee', cascade=None, cascade_backrefs=False) fingerprints = relationship('Fingerprint', backref='employee', cascade=None, cascade_backrefs=False) - def __init__(self, code=None, name=None, is_active=None, costcenter_id=None, designation=None, salary=None, + def __init__(self, code=None, name=None, is_active=None, cost_centre_id=None, designation=None, salary=None, service_points=None, joining_date=None, leaving_date=None): self.designation = designation self.salary = salary @@ -386,7 +390,7 @@ class Employee(LedgerBase): self.joining_date = joining_date self.leaving_date = leaving_date super().__init__(code=code, name=name, type=10, is_active=is_active, is_reconcilable=False, - costcenter_id=costcenter_id) + cost_centre_id=cost_centre_id) def create(self): code = DBSession.query(func.max(LedgerBase.code)).filter(LedgerBase.type == self.type).one()[0] @@ -403,7 +407,7 @@ class Employee(LedgerBase): @classmethod def list(cls): - return DBSession.query(Employee).order_by(desc(Employee.is_active)).order_by(Ledger.costcenter_id).order_by( + return DBSession.query(Employee).order_by(desc(Employee.is_active)).order_by(Ledger.cost_centre_id).order_by( Employee.designation).order_by(Employee.name).all() @classmethod diff --git a/brewman/models/operations.py b/brewman/models/operations.py index 74b754ab..d1105fa9 100644 --- a/brewman/models/operations.py +++ b/brewman/models/operations.py @@ -1,4 +1,4 @@ -from brewman.models.master import CostCenter +from brewman.models.master import CostCentre from brewman.models.validation_exception import ValidationError __author__ = 'tanshu' @@ -36,7 +36,7 @@ def check_batch_insert(voucher): # Issue purchase = None for item in voucher.journals: - if item.cost_center_id == CostCenter.cost_center_purchase(): + if item.cost_centre_id == CostCentre.cost_centre_purchase(): purchase = item if purchase == None: return @@ -54,7 +54,7 @@ def check_batch_insert(voucher): def issue_new(voucher): - consuming = filter(lambda x: x.cost_center_id == CostCenter.cost_center_purchase(), voucher.journals) + consuming = filter(lambda x: x.cost_centre_id == CostCentre.cost_centre_purchase(), voucher.journals) if not len(consuming): consuming = False elif consuming[0].debit == 1: @@ -74,7 +74,7 @@ def issue_new(voucher): def issue_update(voucher): - consuming = filter(lambda x: x.cost_center_id == CostCenter.cost_center_purchase(), voucher.journals) + consuming = filter(lambda x: x.cost_centre_id == CostCentre.cost_centre_purchase(), voucher.journals) if not len(consuming): consuming = False elif consuming[0].debit == 1: @@ -150,7 +150,7 @@ def journals_valid(voucher): def is_distinct_journal(journals): found = set() for item in journals: - itemHash = hash(item.ledger_id) ^ hash(item.cost_center_id) + itemHash = hash(item.ledger_id) ^ hash(item.cost_centre_id) if itemHash in found: raise ValidationError("Duplicate journals") else: diff --git a/brewman/models/voucher.py b/brewman/models/voucher.py index 9207bf11..3417dd46 100644 --- a/brewman/models/voucher.py +++ b/brewman/models/voucher.py @@ -2,9 +2,8 @@ from datetime import datetime import uuid from sqlalchemy.dialects.postgresql import BYTEA -from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy import Column, Integer, Boolean, Unicode, DateTime, Numeric, ForeignKey, UniqueConstraint, Index +from sqlalchemy import Column, Integer, Boolean, Unicode, DateTime, Numeric, ForeignKey, UniqueConstraint from sqlalchemy.orm import relationship, synonym, backref from brewman.models.guidtype import GUID @@ -32,6 +31,7 @@ class VoucherType: list.append(VoucherType(10, 'Opening Balance')) list.append(VoucherType(11, 'Closing Balance')) list.append(VoucherType(12, 'Salary Deduction')) + list.append(VoucherType(13, 'Service Charge')) return list @classmethod @@ -72,7 +72,8 @@ class Voucher(Base): inventories = relationship('Inventory', backref='voucher', cascade="delete, delete-orphan", cascade_backrefs=False) salary_deductions = relationship('SalaryDeduction', backref='voucher', cascade="delete, delete-orphan", cascade_backrefs=False) - + service_charges = relationship('ServiceCharge', backref='voucher', cascade="delete, delete-orphan", + cascade_backrefs=False) def _get_type(self): @@ -128,7 +129,7 @@ class Journal(Base): amount = Column('Amount', Numeric) voucher_id = Column('VoucherID', GUID(), ForeignKey('vouchers.VoucherID'), nullable=False, index=True) ledger_id = Column('LedgerID', GUID(), ForeignKey('ledgers.LedgerID'), nullable=False) - cost_center_id = Column('CostCenterID', GUID(), ForeignKey('cost_centers.CostCenterID'), nullable=False) + cost_centre_id = Column('CostCentreID', GUID(), ForeignKey('cost_centres.CostCentreID'), nullable=False) @hybrid_property def signed_amount(self): @@ -138,13 +139,13 @@ class Journal(Base): def __name__(self): return self.name - def __init__(self, id=None, debit=None, amount=None, voucher_id=None, ledger_id=None, cost_center_id=None): + def __init__(self, id=None, debit=None, amount=None, voucher_id=None, ledger_id=None, cost_centre_id=None): self.id = id self.debit = debit self.amount = amount self.voucher_id = voucher_id self.ledger_id = ledger_id - self.cost_center_id = cost_center_id + self.cost_centre_id = cost_centre_id @classmethod def by_id(cls, id): @@ -189,6 +190,27 @@ class SalaryDeduction(Base): self.journal = journal +class ServiceCharge(Base): + __tablename__ = 'service_charges' + id = Column('id', GUID(), primary_key=True, default=uuid.uuid4) + voucher_id = Column('voucher_id', GUID(), ForeignKey('vouchers.VoucherID'), nullable=False) + journal_id = Column('journal_id', GUID(), ForeignKey('journals.JournalID'), nullable=False) + days_worked = Column('days_worked', Integer, nullable=False) + points = Column('points', Numeric(precision=5, scale=2), nullable=False) + + journal = relationship(Journal, backref=backref('service_charge', uselist=False), cascade=None, + cascade_backrefs=False) + + def __init__(self, id=None, voucher_id=None, journal_id=None, journal=None, days_worked=None, points=None): + self.id = id + self.voucher_id = voucher_id + self.journal_id = journal_id + self.days_worked = days_worked + self.points = points + if journal_id is None and journal is not None: + self.journal = journal + + class Inventory(Base): __tablename__ = 'inventories' __table_args__ = (UniqueConstraint('VoucherID', 'BatchID'), ) diff --git a/brewman/static/base.html b/brewman/static/base.html index c4e7f3cc..aa28d110 100644 --- a/brewman/static/base.html +++ b/brewman/static/base.html @@ -43,6 +43,7 @@ + @@ -53,7 +54,6 @@ - @@ -62,6 +62,7 @@ + @@ -88,7 +89,7 @@ - + @@ -171,6 +172,7 @@