Landed cost voucher: fixes for serialized item

This commit is contained in:
Nabin Hait
2015-03-27 15:38:31 +05:30
parent 712440c045
commit 54c865e77c
7 changed files with 37 additions and 18 deletions

View File

@@ -14,7 +14,7 @@ class NegativeStockError(frappe.ValidationError): pass
_exceptions = frappe.local('stockledger_exceptions')
# _exceptions = []
def make_sl_entries(sl_entries, is_amended=None, allow_negative_stock=False):
def make_sl_entries(sl_entries, is_amended=None, allow_negative_stock=False, via_landed_cost_voucher=False):
if sl_entries:
from erpnext.stock.utils import update_bin
@@ -28,14 +28,14 @@ def make_sl_entries(sl_entries, is_amended=None, allow_negative_stock=False):
sle['actual_qty'] = -flt(sle['actual_qty'])
if sle.get("actual_qty") or sle.get("voucher_type")=="Stock Reconciliation":
sle_id = make_entry(sle, allow_negative_stock)
sle_id = make_entry(sle, allow_negative_stock, via_landed_cost_voucher)
args = sle.copy()
args.update({
"sle_id": sle_id,
"is_amended": is_amended
})
update_bin(args, allow_negative_stock)
update_bin(args, allow_negative_stock, via_landed_cost_voucher)
if cancel:
delete_cancelled_entry(sl_entries[0].get('voucher_type'), sl_entries[0].get('voucher_no'))
@@ -46,11 +46,12 @@ def set_as_cancel(voucher_type, voucher_no):
where voucher_no=%s and voucher_type=%s""",
(now(), frappe.session.user, voucher_type, voucher_no))
def make_entry(args, allow_negative_stock=False):
def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False):
args.update({"doctype": "Stock Ledger Entry"})
sle = frappe.get_doc(args)
sle.ignore_permissions = 1
sle.allow_negative_stock=allow_negative_stock
sle.via_landed_cost_voucher = via_landed_cost_voucher
sle.insert()
sle.submit()
return sle.name
@@ -59,7 +60,9 @@ def delete_cancelled_entry(voucher_type, voucher_no):
frappe.db.sql("""delete from `tabStock Ledger Entry`
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
def update_entries_after(args, allow_zero_rate=False, allow_negative_stock=False, verbose=1):
def update_entries_after(args, allow_zero_rate=False, allow_negative_stock=False,
via_landed_cost_voucher=False, verbose=1):
"""
update valution rate and qty after transaction
from the current time-bucket onwards
@@ -91,7 +94,7 @@ def update_entries_after(args, allow_zero_rate=False, allow_negative_stock=False
stock_value_difference = 0.0
for sle in entries_to_fix:
if sle.serial_no or not allow_negative_stock:
if (sle.serial_no and not via_landed_cost_voucher) or not allow_negative_stock:
# validate negative stock for serialized items, fifo valuation
# or when negative stock is not allowed for moving average
if not validate_negative_stock(qty_after_transaction, sle):