Fixed: Error is voucher_post and check_delete_permission due to changing from lock_date to lock_info
Fixed (maybe): Save product updated to gather better information in case of an error during save. Signed-off-by: Amritanshu <tanshu@gmail.com>
This commit is contained in:
parent
d566493787
commit
4a65c58aed
brewman/views
@ -26,11 +26,23 @@ def html(request):
|
||||
@view_config(request_method='POST', route_name='api_product', renderer='json', permission='Products')
|
||||
@TryCatchFunction
|
||||
def save(request):
|
||||
item = Product(0, request.json_body['Name'], request.json_body['Units'],
|
||||
Decimal(request.json_body['Fraction']), request.json_body['FractionUnits'],
|
||||
Decimal(request.json_body['Yeild']), request.json_body['ShowForPurchase'],
|
||||
uuid.UUID(request.json_body['ProductGroup']['ProductGroupID']), Ledger.all_purchases(),
|
||||
Decimal(request.json_body['Price']), request.json_body['Discontinued']).create()
|
||||
json = request.json_body
|
||||
name = json.get('Name', '').strip()
|
||||
if name == '':
|
||||
raise ValidationError('Name cannot be blank')
|
||||
units = json.get('Units', '').strip()
|
||||
fraction = Decimal(json.get('Fraction', 0))
|
||||
fraction_units = json.get('FractionUnits', '').strip()
|
||||
yeild = Decimal(json.get('Yeild', 1))
|
||||
show_for_purchase = json.get('ShowForPurchase', True)
|
||||
product_group = json.get('ProductGroup', None)
|
||||
if product_group is None:
|
||||
raise ValidationError('Please choose a product group')
|
||||
product_group_id = uuid.UUID(product_group['ProductGroupID'])
|
||||
price = Decimal(json.get('Price', 0))
|
||||
discontinued = json.get('Discontinued', False)
|
||||
item = Product(0, name, units, fraction, fraction_units, yeild, show_for_purchase, product_group_id,
|
||||
Ledger.all_purchases(), price, discontinued).create()
|
||||
transaction.commit()
|
||||
return product_info(item.id)
|
||||
|
||||
@ -41,8 +53,8 @@ def update(request):
|
||||
item = Product.by_id(uuid.UUID(request.matchdict['id']))
|
||||
if item.is_fixture:
|
||||
raise ValidationError("{0} is a fixture and cannot be edited or deleted.".format(item.full_name))
|
||||
item.name = request.json_body['Name']
|
||||
item.units = request.json_body['Units']
|
||||
item.name = request.json_body['Name'].strip()
|
||||
item.units = request.json_body['Units'].strip()
|
||||
item.fraction = Decimal(request.json_body['Fraction'])
|
||||
item.fraction_units = request.json_body['FractionUnits']
|
||||
item.yeild = Decimal(request.json_body['Yeild'])
|
||||
|
@ -10,6 +10,7 @@ from brewman.models.auth import User
|
||||
from brewman.models.master import LedgerBase, CostCenter, DbSetting
|
||||
from brewman.models.validation_exception import ValidationError, TryCatchFunction
|
||||
from brewman.models.voucher import Voucher, VoucherType, Batch, Inventory
|
||||
from brewman.views import get_lock_info
|
||||
from .issue import issue_create_voucher, issue_update_voucher
|
||||
from .journal import journal_update_voucher, journal_create_voucher
|
||||
from .purchase import purchase_create_voucher, purchase_update_voucher
|
||||
@ -55,9 +56,11 @@ def journal_get(request):
|
||||
def voucher_post(request):
|
||||
user = User.by_id(uuid.UUID(authenticated_userid(request)))
|
||||
voucher = Voucher.by_id(uuid.UUID(request.matchdict['id']))
|
||||
lock_date = get_lock_date()
|
||||
if lock_date >= voucher.date:
|
||||
raise ValidationError("Vouchers upto {0} have been locked.".format(lock_date.strftime('%d-%b-%Y')))
|
||||
start, finish = get_lock_info()
|
||||
if start is not None and start > voucher.date:
|
||||
raise ValidationError("Vouchers before {0} have been locked.".format(start.strftime('%d-%b-%Y')))
|
||||
elif finish is not None and finish < voucher.date:
|
||||
raise ValidationError("Vouchers after {0} have been locked.".format(finish.strftime('%d-%b-%Y')))
|
||||
voucher.posted = True
|
||||
voucher.poster_id = user.id
|
||||
transaction.commit()
|
||||
@ -80,9 +83,13 @@ def check_delete_permissions(request, voucher):
|
||||
response = Response("You are not allowed (0) vouchers".format(VoucherType.by_id(voucher.type).name))
|
||||
response.status_int = 403
|
||||
return response
|
||||
lock_date = get_lock_date()
|
||||
if lock_date >= voucher.date:
|
||||
response = Response("Vouchers upto {0} have been locked.".format(lock_date.strftime('%d-%b-%Y')))
|
||||
start, finish = get_lock_info()
|
||||
if start is not None and start > voucher.date:
|
||||
response = Response("Vouchers before {0} have been locked.".format(start.strftime('%d-%b-%Y')))
|
||||
response.status_int = 403
|
||||
return response
|
||||
elif finish is not None and finish < voucher.date:
|
||||
response = Response("Vouchers after {0} have been locked.".format(finish.strftime('%d-%b-%Y')))
|
||||
response.status_int = 403
|
||||
return response
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user