mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 21:19:19 +00:00
[minor] make gl entry through bean and testcases
This commit is contained in:
@@ -49,6 +49,13 @@ class TestDeliveryNote(unittest.TestCase):
|
||||
dn.insert()
|
||||
dn.submit()
|
||||
|
||||
stock_value, stock_value_difference = webnotes.conn.get_value("Stock Ledger Entry",
|
||||
{"voucher_type": "Delivery Note", "voucher_no": dn.doc.name,
|
||||
"item_code": "_Test Item"}, ["stock_value", "stock_value_difference"])
|
||||
self.assertEqual(stock_value, 0)
|
||||
self.assertEqual(stock_value_difference, -375)
|
||||
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Delivery Note' and voucher_no=%s
|
||||
order by account desc""", dn.doc.name, as_dict=1)
|
||||
|
||||
@@ -39,6 +39,17 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
stock_value, stock_value_difference = webnotes.conn.get_value("Stock Ledger Entry",
|
||||
{"voucher_type": "Purchase Receipt", "voucher_no": pr.doc.name,
|
||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
|
||||
["stock_value", "stock_value_difference"])
|
||||
self.assertEqual(stock_value, 375)
|
||||
self.assertEqual(stock_value_difference, 375)
|
||||
|
||||
bin_stock_value = webnotes.conn.get_value("Bin", {"item_code": "_Test Item",
|
||||
"warehouse": "_Test Warehouse - _TC"}, "stock_value")
|
||||
self.assertEqual(bin_stock_value, 375)
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s
|
||||
order by account desc""", pr.doc.name, as_dict=1)
|
||||
|
||||
@@ -39,6 +39,9 @@ class DocType(DocListController):
|
||||
from accounts.utils import validate_fiscal_year
|
||||
validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, self.meta.get_label("posting_date"))
|
||||
|
||||
def on_submit(self):
|
||||
self.validate_serial_no()
|
||||
|
||||
#check for item quantity available in stock
|
||||
def actual_amt_check(self):
|
||||
if self.doc.batch_no:
|
||||
@@ -79,10 +82,7 @@ class DocType(DocListController):
|
||||
msgprint("Warehouse: '%s' does not exist in the system. Please check." % self.doc.fields.get(k), raise_exception = 1)
|
||||
|
||||
def validate_item(self):
|
||||
item_det = webnotes.conn.sql("""select name, has_batch_no, docstatus,
|
||||
is_stock_item, has_serial_no, serial_no_series
|
||||
from tabItem where name=%s""",
|
||||
self.doc.item_code, as_dict=True)[0]
|
||||
item_det = self.get_item_details()
|
||||
|
||||
if item_det.is_stock_item != 'Yes':
|
||||
webnotes.throw("""Item: "%s" is not a Stock Item.""" % self.doc.item_code)
|
||||
@@ -96,10 +96,15 @@ class DocType(DocListController):
|
||||
if not webnotes.conn.sql("""select name from `tabBatch`
|
||||
where item='%s' and name ='%s' and docstatus != 2""" % (self.doc.item_code, self.doc.batch_no)):
|
||||
webnotes.throw("'%s' is not a valid Batch Number for Item '%s'" % (self.doc.batch_no, self.doc.item_code))
|
||||
|
||||
def get_item_details(self):
|
||||
return webnotes.conn.sql("""select name, has_batch_no, docstatus,
|
||||
is_stock_item, has_serial_no, serial_no_series
|
||||
from tabItem where name=%s""",
|
||||
self.doc.item_code, as_dict=True)[0]
|
||||
|
||||
self.validate_serial_no(item_det)
|
||||
|
||||
def validate_serial_no(self, item_det):
|
||||
def validate_serial_no(self):
|
||||
item_det = self.get_item_details()
|
||||
if item_det.has_serial_no=="No":
|
||||
if self.doc.serial_no:
|
||||
webnotes.throw(_("Serial Number should be blank for Non Serialized Item" + ": " + self.doc.item),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-01-29 19:25:42",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-08-20 15:02:48",
|
||||
"modified": "2013-08-23 12:23:18",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -224,6 +224,14 @@
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "stock_value_difference",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Stock Value Difference",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "stock_queue",
|
||||
|
||||
@@ -46,7 +46,7 @@ def make_entry(args):
|
||||
sle = webnotes.bean([args])
|
||||
sle.ignore_permissions = 1
|
||||
sle.insert()
|
||||
# sle.submit()
|
||||
sle.submit()
|
||||
return sle.doc.name
|
||||
|
||||
def delete_cancelled_entry(voucher_type, voucher_no):
|
||||
@@ -74,12 +74,13 @@ def update_entries_after(args, verbose=1):
|
||||
qty_after_transaction = flt(previous_sle.get("qty_after_transaction"))
|
||||
valuation_rate = flt(previous_sle.get("valuation_rate"))
|
||||
stock_queue = json.loads(previous_sle.get("stock_queue") or "[]")
|
||||
stock_value = flt(previous_sle.get("stock_value"))
|
||||
prev_stock_value = stock_value = flt(previous_sle.get("stock_value"))
|
||||
|
||||
entries_to_fix = get_sle_after_datetime(previous_sle or \
|
||||
{"item_code": args["item_code"], "warehouse": args["warehouse"]}, for_update=True)
|
||||
|
||||
valuation_method = get_valuation_method(args["item_code"])
|
||||
stock_value_difference = 0.0
|
||||
|
||||
for sle in entries_to_fix:
|
||||
if sle.serial_no or not cint(webnotes.conn.get_default("allow_negative_stock")):
|
||||
@@ -107,12 +108,15 @@ def update_entries_after(args, verbose=1):
|
||||
else:
|
||||
stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in stock_queue))
|
||||
|
||||
stock_value_difference = stock_value - prev_stock_value
|
||||
prev_stock_value = stock_value
|
||||
|
||||
# update current sle
|
||||
webnotes.conn.sql("""update `tabStock Ledger Entry`
|
||||
set qty_after_transaction=%s, valuation_rate=%s, stock_queue=%s,
|
||||
stock_value=%s where name=%s""",
|
||||
stock_value=%s, stock_value_difference=%s where name=%s""",
|
||||
(qty_after_transaction, valuation_rate,
|
||||
json.dumps(stock_queue), stock_value, sle.name))
|
||||
json.dumps(stock_queue), stock_value, stock_value_difference, sle.name))
|
||||
|
||||
if _exceptions:
|
||||
_raise_exceptions(args, verbose)
|
||||
|
||||
Reference in New Issue
Block a user