-webnotes +frappe 💥

This commit is contained in:
Rushabh Mehta
2014-02-14 15:47:51 +05:30
parent 8ae051cb39
commit 793ba6bd37
729 changed files with 5194 additions and 9971 deletions

View File

@@ -2,16 +2,16 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint
from webnotes.utils import cint, flt, cstr, now
import frappe
from frappe import msgprint
from frappe.utils import cint, flt, cstr, now
from erpnext.stock.utils import get_valuation_method
import json
# future reposting
class NegativeStockError(webnotes.ValidationError): pass
class NegativeStockError(frappe.ValidationError): pass
_exceptions = webnotes.local('stockledger_exceptions')
_exceptions = frappe.local('stockledger_exceptions')
# _exceptions = []
def make_sl_entries(sl_entries, is_amended=None):
@@ -42,21 +42,21 @@ def make_sl_entries(sl_entries, is_amended=None):
sl_entries[0].get('voucher_no'))
def set_as_cancel(voucher_type, voucher_no):
webnotes.conn.sql("""update `tabStock Ledger Entry` set is_cancelled='Yes',
frappe.conn.sql("""update `tabStock Ledger Entry` set is_cancelled='Yes',
modified=%s, modified_by=%s
where voucher_no=%s and voucher_type=%s""",
(now(), webnotes.session.user, voucher_type, voucher_no))
(now(), frappe.session.user, voucher_type, voucher_no))
def make_entry(args):
args.update({"doctype": "Stock Ledger Entry"})
sle = webnotes.bean([args])
sle = frappe.bean([args])
sle.ignore_permissions = 1
sle.insert()
sle.submit()
return sle.doc.name
def delete_cancelled_entry(voucher_type, voucher_no):
webnotes.conn.sql("""delete from `tabStock Ledger Entry`
frappe.conn.sql("""delete from `tabStock Ledger Entry`
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
def update_entries_after(args, verbose=1):
@@ -72,7 +72,7 @@ def update_entries_after(args, verbose=1):
}
"""
if not _exceptions:
webnotes.local.stockledger_exceptions = []
frappe.local.stockledger_exceptions = []
previous_sle = get_sle_before_datetime(args)
@@ -89,7 +89,7 @@ def update_entries_after(args, verbose=1):
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")):
if sle.serial_no or not cint(frappe.conn.get_default("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):
@@ -115,17 +115,17 @@ def update_entries_after(args, verbose=1):
stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in stock_queue))
# rounding as per precision
from webnotes.model.meta import get_field_precision
meta = webnotes.get_doctype("Stock Ledger Entry")
from frappe.model.meta import get_field_precision
meta = frappe.get_doctype("Stock Ledger Entry")
stock_value = flt(stock_value, get_field_precision(meta.get_field("stock_value"),
webnotes._dict({"fields": sle})))
frappe._dict({"fields": sle})))
stock_value_difference = stock_value - prev_stock_value
prev_stock_value = stock_value
# update current sle
webnotes.conn.sql("""update `tabStock Ledger Entry`
frappe.conn.sql("""update `tabStock Ledger Entry`
set qty_after_transaction=%s, valuation_rate=%s, stock_queue=%s,
stock_value=%s, stock_value_difference=%s where name=%s""",
(qty_after_transaction, valuation_rate,
@@ -135,9 +135,9 @@ def update_entries_after(args, verbose=1):
_raise_exceptions(args, verbose)
# update bin
if not webnotes.conn.exists({"doctype": "Bin", "item_code": args["item_code"],
if not frappe.conn.exists({"doctype": "Bin", "item_code": args["item_code"],
"warehouse": args["warehouse"]}):
bin_wrapper = webnotes.bean([{
bin_wrapper = frappe.bean([{
"doctype": "Bin",
"item_code": args["item_code"],
"warehouse": args["warehouse"],
@@ -145,7 +145,7 @@ def update_entries_after(args, verbose=1):
bin_wrapper.ignore_permissions = 1
bin_wrapper.insert()
webnotes.conn.sql("""update `tabBin` set valuation_rate=%s, actual_qty=%s,
frappe.conn.sql("""update `tabBin` set valuation_rate=%s, actual_qty=%s,
stock_value=%s,
projected_qty = (actual_qty + indented_qty + ordered_qty + planned_qty - reserved_qty)
where item_code=%s and warehouse=%s""", (valuation_rate, qty_after_transaction,
@@ -165,7 +165,7 @@ def get_sle_before_datetime(args, for_update=False):
["timestamp(posting_date, posting_time) < timestamp(%(posting_date)s, %(posting_time)s)"],
"desc", "limit 1", for_update=for_update)
return sle and sle[0] or webnotes._dict()
return sle and sle[0] or frappe._dict()
def get_sle_after_datetime(args, for_update=False):
"""get Stock Ledger Entries after a particular datetime, for reposting"""
@@ -181,7 +181,7 @@ def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, fo
if not args.get("posting_time"):
args["posting_time"] = "00:00"
return webnotes.conn.sql("""select * from `tabStock Ledger Entry`
return frappe.conn.sql("""select * from `tabStock Ledger Entry`
where item_code = %%(item_code)s
and warehouse = %%(warehouse)s
and ifnull(is_cancelled, 'No')='No'
@@ -202,7 +202,7 @@ def validate_negative_stock(qty_after_transaction, sle):
diff = qty_after_transaction + flt(sle.actual_qty)
if not _exceptions:
webnotes.local.stockledger_exceptions = []
frappe.local.stockledger_exceptions = []
if diff < 0 and abs(diff) > 0.0001:
# negative stock!
@@ -223,7 +223,7 @@ def get_serialized_values(qty_after_transaction, sle, valuation_rate):
elif incoming_rate == 0 or flt(sle.actual_qty) < 0:
# In case of delivery/stock issue, get average purchase rate
# of serial nos of current entry
incoming_rate = flt(webnotes.conn.sql("""select avg(ifnull(purchase_rate, 0))
incoming_rate = flt(frappe.conn.sql("""select avg(ifnull(purchase_rate, 0))
from `tabSerial No` where name in (%s)""" % (", ".join(["%s"]*len(serial_no))),
tuple(serial_no))[0][0])