Fix: On update issue, it will update price / discount / tax from the batch (if changed)
This commit is contained in:
parent
69071182a3
commit
d2e08d09cc
|
@ -2,13 +2,14 @@ import datetime
|
|||
from decimal import Decimal
|
||||
import uuid
|
||||
from brewman.models import DBSession
|
||||
from brewman.models.master import Product, CostCenter, LedgerBase
|
||||
from brewman.models.master import CostCenter, LedgerBase
|
||||
from brewman.models.operations import journals_valid, inventory_valid
|
||||
from brewman.models.validation_exception import ValidationError
|
||||
from brewman.models.voucher import Voucher, VoucherType, Batch, Inventory, Journal
|
||||
|
||||
__author__ = 'tanshu'
|
||||
|
||||
|
||||
def issue_create_voucher(json, user):
|
||||
dt = datetime.datetime.strptime(json['Date'], '%d-%b-%Y')
|
||||
voucher = Voucher(date=dt, narration=json['Narration'], user_id=user.id, type=VoucherType.by_name('Issue'))
|
||||
|
@ -105,16 +106,16 @@ def issue_update_inventory(voucher, newInventories, batch_consumed):
|
|||
for j in range(len(newInventories), 0, -1):
|
||||
i = newInventories[j - 1]
|
||||
if 'InventoryID' in i and item.id == uuid.UUID(i['InventoryID']):
|
||||
product = Product.by_id(uuid.UUID(i['Product']['ProductID']))
|
||||
batch = Batch.by_id(uuid.UUID(i['Batch']['BatchID']))
|
||||
found = True
|
||||
if item.product_id != product.id:
|
||||
raise ValidationError('Product cannot be changed')
|
||||
if item.batch_id != batch.id:
|
||||
raise ValidationError('Product / Batch cannot be changed')
|
||||
new_quantity = round(Decimal(i['Quantity']), 2)
|
||||
old_quantity = round(Decimal(item.quantity), 2)
|
||||
quantity_remaining = round(Decimal(item.batch.quantity_remaining), 2)
|
||||
if new_quantity <= 0:
|
||||
raise ValidationError("Quantity of {0} cannot be zero".format(item.product.name))
|
||||
if batch_consumed == True and new_quantity - old_quantity > quantity_remaining:
|
||||
if batch_consumed is True and new_quantity - old_quantity > quantity_remaining:
|
||||
raise ValidationError("Maximum quantity available for {0} is {1}".format(item.product.full_name,
|
||||
old_quantity + quantity_remaining))
|
||||
if item.batch.name > voucher.date:
|
||||
|
@ -128,6 +129,10 @@ def issue_update_inventory(voucher, newInventories, batch_consumed):
|
|||
item.batch.quantity_remaining += (new_quantity - old_quantity)
|
||||
|
||||
item.quantity = new_quantity
|
||||
item.rate = batch.rate
|
||||
item.tax = batch.tax
|
||||
item.discount = batch.discount
|
||||
|
||||
newInventories.remove(i)
|
||||
break
|
||||
if not found:
|
||||
|
|
Loading…
Reference in New Issue