Merge pull request #4899 from nabinhait/seriailized_stock_valuation
Seriailized stock valuation
This commit is contained in:
commit
e670525c55
@ -250,3 +250,4 @@ erpnext.patches.v6_19.comment_feed_communication
|
|||||||
erpnext.patches.v6_21.fix_reorder_level
|
erpnext.patches.v6_21.fix_reorder_level
|
||||||
erpnext.patches.v6_21.rename_material_request_fields
|
erpnext.patches.v6_21.rename_material_request_fields
|
||||||
erpnext.patches.v6_23.update_stopped_status_to_closed
|
erpnext.patches.v6_23.update_stopped_status_to_closed
|
||||||
|
erpnext.patches.v6_24.repost_valuation_rate_for_serialized_items
|
0
erpnext/patches/v6_24/__init__.py
Normal file
0
erpnext/patches/v6_24/__init__.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
|
from frappe.utils import today
|
||||||
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
from erpnext.stock.stock_ledger import update_entries_after
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
try:
|
||||||
|
year_start_date = get_fiscal_year(today())[1]
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
if year_start_date:
|
||||||
|
items = frappe.db.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry`
|
||||||
|
where ifnull(serial_no, '') != '' and actual_qty > 0 and incoming_rate=0""", as_dict=1)
|
||||||
|
|
||||||
|
for d in items:
|
||||||
|
try:
|
||||||
|
update_entries_after({
|
||||||
|
"item_code": d.item_code,
|
||||||
|
"warehouse": d.warehouse,
|
||||||
|
"posting_date": year_start_date
|
||||||
|
}, allow_zero_rate=True)
|
||||||
|
except:
|
||||||
|
pass
|
@ -212,24 +212,23 @@ class update_entries_after(object):
|
|||||||
# wrong incoming rate
|
# wrong incoming rate
|
||||||
incoming_rate = self.valuation_rate
|
incoming_rate = self.valuation_rate
|
||||||
|
|
||||||
elif incoming_rate == 0:
|
stock_value_change = 0
|
||||||
if flt(sle.actual_qty) < 0:
|
if incoming_rate:
|
||||||
# In case of delivery/stock issue, get average purchase rate
|
stock_value_change = actual_qty * incoming_rate
|
||||||
# of serial nos of current entry
|
elif actual_qty < 0:
|
||||||
incoming_rate = flt(frappe.db.sql("""select avg(purchase_rate)
|
# In case of delivery/stock issue, get average purchase rate
|
||||||
from `tabSerial No` where name in (%s)""" % (", ".join(["%s"]*len(serial_no))),
|
# of serial nos of current entry
|
||||||
tuple(serial_no))[0][0])
|
stock_value_change = -1 * flt(frappe.db.sql("""select sum(purchase_rate)
|
||||||
|
from `tabSerial No` where name in (%s)""" % (", ".join(["%s"]*len(serial_no))),
|
||||||
|
tuple(serial_no))[0][0])
|
||||||
|
|
||||||
if incoming_rate and not self.valuation_rate:
|
new_stock_qty = self.qty_after_transaction + actual_qty
|
||||||
self.valuation_rate = incoming_rate
|
if new_stock_qty > 0:
|
||||||
else:
|
new_stock_value = (self.qty_after_transaction * self.valuation_rate) + stock_value_change
|
||||||
new_stock_qty = self.qty_after_transaction + actual_qty
|
if new_stock_value > 0:
|
||||||
if new_stock_qty > 0:
|
# calculate new valuation rate only if stock value is positive
|
||||||
new_stock_value = self.qty_after_transaction * self.valuation_rate + actual_qty * incoming_rate
|
# else it remains the same as that of previous entry
|
||||||
if new_stock_value > 0:
|
self.valuation_rate = new_stock_value / new_stock_qty
|
||||||
# calculate new valuation rate only if stock value is positive
|
|
||||||
# else it remains the same as that of previous entry
|
|
||||||
self.valuation_rate = new_stock_value / new_stock_qty
|
|
||||||
|
|
||||||
def get_moving_average_values(self, sle):
|
def get_moving_average_values(self, sle):
|
||||||
actual_qty = flt(sle.actual_qty)
|
actual_qty = flt(sle.actual_qty)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user