Some minor fixes
This commit is contained in:
parent
a0b967f2cd
commit
4c952f48f8
@ -223,7 +223,8 @@ class BuyingController(StockController):
|
|||||||
})
|
})
|
||||||
if not rm.rate:
|
if not rm.rate:
|
||||||
from erpnext.stock.stock_ledger import get_valuation_rate
|
from erpnext.stock.stock_ledger import get_valuation_rate
|
||||||
rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse)
|
rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse,
|
||||||
|
self.doctype, self.name)
|
||||||
else:
|
else:
|
||||||
rm.rate = bom_item.rate
|
rm.rate = bom_item.rate
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"item_group": "_Test Item Group",
|
"item_group": "_Test Item Group",
|
||||||
"item_name": "_Test Item",
|
"item_name": "_Test Item",
|
||||||
"apply_warehouse_wise_reorder_level": 1,
|
"apply_warehouse_wise_reorder_level": 1,
|
||||||
|
"valuation_rate": 100,
|
||||||
"reorder_levels": [
|
"reorder_levels": [
|
||||||
{
|
{
|
||||||
"material_request_type": "Purchase",
|
"material_request_type": "Purchase",
|
||||||
@ -61,6 +62,7 @@
|
|||||||
"item_code": "_Test Item Home Desktop 100",
|
"item_code": "_Test Item Home Desktop 100",
|
||||||
"item_group": "_Test Item Group Desktops",
|
"item_group": "_Test Item Group Desktops",
|
||||||
"item_name": "_Test Item Home Desktop 100",
|
"item_name": "_Test Item Home Desktop 100",
|
||||||
|
"valuation_rate": 100,
|
||||||
"taxes": [
|
"taxes": [
|
||||||
{
|
{
|
||||||
"doctype": "Item Tax",
|
"doctype": "Item Tax",
|
||||||
|
@ -260,7 +260,8 @@ class update_entries_after(object):
|
|||||||
self.valuation_rate = sle.incoming_rate
|
self.valuation_rate = sle.incoming_rate
|
||||||
|
|
||||||
if not self.valuation_rate:
|
if not self.valuation_rate:
|
||||||
self.valuation_rate = get_valuation_rate(sle, self.allow_zero_rate)
|
self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse,
|
||||||
|
sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
|
||||||
|
|
||||||
def get_fifo_values(self, sle):
|
def get_fifo_values(self, sle):
|
||||||
incoming_rate = flt(sle.incoming_rate)
|
incoming_rate = flt(sle.incoming_rate)
|
||||||
@ -285,7 +286,8 @@ class update_entries_after(object):
|
|||||||
while qty_to_pop:
|
while qty_to_pop:
|
||||||
if not self.stock_queue:
|
if not self.stock_queue:
|
||||||
# Get valuation rate from last sle if exists or from valuation rate field in item master
|
# Get valuation rate from last sle if exists or from valuation rate field in item master
|
||||||
_rate = get_valuation_rate(sle, self.allow_zero_rate)
|
_rate = get_valuation_rate(sle.item_code, sle.warehouse,
|
||||||
|
sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
|
||||||
self.stock_queue.append([0, _rate])
|
self.stock_queue.append([0, _rate])
|
||||||
|
|
||||||
index = None
|
index = None
|
||||||
@ -405,32 +407,32 @@ def get_stock_ledger_entries(previous_sle, operator=None, order="desc", limit=No
|
|||||||
"order": order
|
"order": order
|
||||||
}, previous_sle, as_dict=1, debug=debug)
|
}, previous_sle, as_dict=1, debug=debug)
|
||||||
|
|
||||||
def get_valuation_rate(sle, allow_zero_rate=False):
|
def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, allow_zero_rate=False):
|
||||||
# Get valuation rate from last sle for the same item and warehouse
|
# Get valuation rate from last sle for the same item and warehouse
|
||||||
last_valuation_rate = frappe.db.sql("""select valuation_rate
|
last_valuation_rate = frappe.db.sql("""select valuation_rate
|
||||||
from `tabStock Ledger Entry`
|
from `tabStock Ledger Entry`
|
||||||
where item_code = %s and warehouse = %s
|
where item_code = %s and warehouse = %s
|
||||||
and valuation_rate > 0
|
and valuation_rate > 0
|
||||||
order by posting_date desc, posting_time desc, name desc limit 1""", (sle.item_code, sle.warehouse))
|
order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse))
|
||||||
|
|
||||||
if not last_valuation_rate:
|
if not last_valuation_rate:
|
||||||
# Get valuation rate from last sle for the item against any warehouse
|
# Get valuation rate from last sle for the item against any warehouse
|
||||||
last_valuation_rate = frappe.db.sql("""select valuation_rate
|
last_valuation_rate = frappe.db.sql("""select valuation_rate
|
||||||
from `tabStock Ledger Entry`
|
from `tabStock Ledger Entry`
|
||||||
where item_code = %s and valuation_rate > 0
|
where item_code = %s and valuation_rate > 0
|
||||||
order by posting_date desc, posting_time desc, name desc limit 1""", sle.item_code)
|
order by posting_date desc, posting_time desc, name desc limit 1""", item_code)
|
||||||
|
|
||||||
valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0
|
valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0
|
||||||
|
|
||||||
if not valuation_rate:
|
if not valuation_rate:
|
||||||
# If negative stock allowed, and item delivered without any incoming entry,
|
# If negative stock allowed, and item delivered without any incoming entry,
|
||||||
# syste does not found any SLE, then take valuation rate from Item
|
# syste does not found any SLE, then take valuation rate from Item
|
||||||
valuation_rate = frappe.db.get_value("Item", sle.item_code, "valuation_rate")
|
valuation_rate = frappe.db.get_value("Item", item_code, "valuation_rate")
|
||||||
|
|
||||||
if not allow_zero_rate and not valuation_rate \
|
if not allow_zero_rate and not valuation_rate \
|
||||||
and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
|
and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
|
||||||
|
|
||||||
frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries (for booking expenses). Please create an incoming stock transaction or mention valuation rate in Item record, and then try submiting {1} {2}")
|
frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries (for booking expenses). Please create an incoming stock transaction or mention valuation rate in Item record, and then try submiting {1} {2}")
|
||||||
.format(sle.item_code, sle.voucher_type, sle.voucher_no))
|
.format(item_code, voucher_type, voucher_no))
|
||||||
|
|
||||||
return valuation_rate
|
return valuation_rate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user