Check implemented if Account cannot be deleted.
Delete button added to account-detail.html Account.py was not updated to serve api routes, fixed.
This commit is contained in:
parent
7999d4cb9d
commit
9c744cd6d4
@ -26,7 +26,7 @@ class Product(Base):
|
||||
batches = relationship('Batch', backref='product')
|
||||
inventories = relationship('Inventory', backref='product')
|
||||
|
||||
ledger = relationship('Ledger', primaryjoin="Ledger.id==Product.ledger_id")
|
||||
ledger = relationship('Ledger', primaryjoin="Ledger.id==Product.ledger_id", backref='products')
|
||||
|
||||
def __init__(self, code=None, name=None, units=None, fraction=None, fraction_units=None, yeild=None,
|
||||
show_for_purchase=None, product_group_id=None, ledger_id=None, price=None, discontinued=None):
|
||||
@ -205,6 +205,15 @@ class LedgerBase(Base):
|
||||
DBSession.add(self)
|
||||
return self
|
||||
|
||||
def can_delete(self):
|
||||
if self.is_active:
|
||||
return False, 'Account is active'
|
||||
if len(self.journals) > 0:
|
||||
return False, 'Account has journal entries'
|
||||
if len(self.products) > 0:
|
||||
return False, 'Account has products'
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def get_code(cls, type):
|
||||
code = DBSession.query(func.max(LedgerBase.code)).filter(LedgerBase.type == type).one()[0]
|
||||
|
@ -1,6 +1,6 @@
|
||||
CACHE MANIFEST
|
||||
|
||||
# version 2012-12-07.7
|
||||
# version 2012-12-07.8
|
||||
|
||||
CACHE:
|
||||
/partial/404.html
|
||||
|
@ -48,5 +48,9 @@
|
||||
|
||||
<div class="form-actions">
|
||||
<button class="btn btn-primary" ng-click="save()">Save</button>
|
||||
<button class="btn btn-danger" ng-show="account.LedgerID" ng-confirm title="Delete Account"
|
||||
action-text="Are you sure? This cannot be undone."
|
||||
action-button-text="Delete" action-function="delete()"> Delete
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -3,6 +3,7 @@ from pyramid.response import Response
|
||||
|
||||
from pyramid.view import view_config
|
||||
import transaction
|
||||
from brewman.models import DBSession
|
||||
|
||||
from brewman.models.master import CostCenter, Ledger, LedgerType, LedgerBase
|
||||
from brewman.models.validation_exception import ValidationError
|
||||
@ -16,7 +17,7 @@ def html(request):
|
||||
return {}
|
||||
|
||||
|
||||
@view_config(request_method='POST', route_name='account', renderer='json', permission='Accounts')
|
||||
@view_config(request_method='POST', route_name='api_account', renderer='json', permission='Accounts')
|
||||
def save(request):
|
||||
try:
|
||||
item = Ledger(code=0, name=request.json_body['Name'], type=int(request.json_body['Type']),
|
||||
@ -31,7 +32,7 @@ def save(request):
|
||||
return response
|
||||
|
||||
|
||||
@view_config(request_method='POST', route_name='account_id', renderer='json', permission='Accounts')
|
||||
@view_config(request_method='POST', route_name='api_account_id', renderer='json', permission='Accounts')
|
||||
def update(request):
|
||||
try:
|
||||
item = Ledger.by_id(uuid.UUID(request.matchdict['id']))
|
||||
@ -52,15 +53,17 @@ def update(request):
|
||||
return response
|
||||
|
||||
|
||||
@view_config(request_method='DELETE', route_name='account_id', renderer='json', permission='Accounts')
|
||||
@view_config(request_method='DELETE', route_name='api_account_id', renderer='json', permission='Accounts')
|
||||
def delete(request):
|
||||
id = request.matchdict.get('id', None)
|
||||
if id is None:
|
||||
response = Response("Account is Null")
|
||||
response.status_int = 500
|
||||
return response
|
||||
account = Ledger.by_id(uuid.UUID(request.matchdict['id']))
|
||||
can_delete, reason = account.can_delete()
|
||||
if can_delete:
|
||||
DBSession.delete(account)
|
||||
transaction.commit()
|
||||
return account_info(None)
|
||||
else:
|
||||
response = Response("Account deletion not implemented")
|
||||
transaction.abort()
|
||||
response = Response("Cannot delete account because {0}".format(reason))
|
||||
response.status_int = 500
|
||||
return response
|
||||
|
||||
|
@ -7,7 +7,6 @@ import transaction
|
||||
|
||||
from brewman.models.master import CostCenter, Employee, LedgerBase
|
||||
from brewman.models.validation_exception import ValidationError
|
||||
from brewman.views.account import ledger_list
|
||||
|
||||
@view_config(route_name='employee_list', renderer='brewman:templates/angular_base.mako', permission='Authenticated')
|
||||
@view_config(request_method='GET', route_name='employee_id', renderer='brewman:templates/angular_base.mako',
|
||||
|
Loading…
Reference in New Issue
Block a user