Minor fix for moving average
This commit is contained in:
parent
7820b171d3
commit
7c6f990cf9
@ -6,6 +6,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint, flt, cstr, now
|
from frappe.utils import cint, flt, cstr, now
|
||||||
from erpnext.stock.utils import get_valuation_method
|
from erpnext.stock.utils import get_valuation_method
|
||||||
|
from erpnext.controllers.stock_controller import get_valuation_rate
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# future reposting
|
# future reposting
|
||||||
@ -106,8 +107,7 @@ def update_entries_after(args, verbose=1):
|
|||||||
stock_queue = [[qty_after_transaction, valuation_rate]]
|
stock_queue = [[qty_after_transaction, valuation_rate]]
|
||||||
else:
|
else:
|
||||||
if valuation_method == "Moving Average":
|
if valuation_method == "Moving Average":
|
||||||
if flt(sle.actual_qty) > 0:
|
valuation_rate = get_moving_average_values(qty_after_transaction, sle, valuation_rate)
|
||||||
valuation_rate = get_moving_average_values(qty_after_transaction, sle, valuation_rate)
|
|
||||||
else:
|
else:
|
||||||
valuation_rate = get_fifo_values(qty_after_transaction, sle, stock_queue)
|
valuation_rate = get_fifo_values(qty_after_transaction, sle, stock_queue)
|
||||||
|
|
||||||
@ -256,19 +256,18 @@ def get_moving_average_values(qty_after_transaction, sle, valuation_rate):
|
|||||||
incoming_rate = flt(sle.incoming_rate)
|
incoming_rate = flt(sle.incoming_rate)
|
||||||
actual_qty = flt(sle.actual_qty)
|
actual_qty = flt(sle.actual_qty)
|
||||||
|
|
||||||
if not incoming_rate:
|
if flt(sle.actual_qty) > 0:
|
||||||
# If wrong incoming rate
|
if qty_after_transaction < 0 and not valuation_rate:
|
||||||
incoming_rate = valuation_rate
|
# if negative stock, take current valuation rate as incoming rate
|
||||||
|
valuation_rate = incoming_rate
|
||||||
|
|
||||||
elif qty_after_transaction < 0 and not valuation_rate:
|
new_stock_qty = abs(qty_after_transaction) + actual_qty
|
||||||
# if negative stock, take current valuation rate as incoming rate
|
new_stock_value = (abs(qty_after_transaction) * valuation_rate) + (actual_qty * incoming_rate)
|
||||||
valuation_rate = incoming_rate
|
|
||||||
|
|
||||||
new_stock_qty = abs(qty_after_transaction) + actual_qty
|
if new_stock_qty:
|
||||||
new_stock_value = (abs(qty_after_transaction) * valuation_rate) + (actual_qty * incoming_rate)
|
valuation_rate = new_stock_value / flt(new_stock_qty)
|
||||||
|
elif not valuation_rate:
|
||||||
if new_stock_qty:
|
valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse)
|
||||||
valuation_rate = new_stock_value / flt(new_stock_qty)
|
|
||||||
|
|
||||||
return abs(valuation_rate)
|
return abs(valuation_rate)
|
||||||
|
|
||||||
@ -321,7 +320,6 @@ def get_fifo_values(qty_after_transaction, sle, stock_queue):
|
|||||||
|
|
||||||
def intialize_stock_queue(stock_queue, item_code, warehouse):
|
def intialize_stock_queue(stock_queue, item_code, warehouse):
|
||||||
if not stock_queue:
|
if not stock_queue:
|
||||||
from erpnext.controllers.stock_controller import get_valuation_rate
|
|
||||||
estimated_val_rate = get_valuation_rate(item_code, warehouse)
|
estimated_val_rate = get_valuation_rate(item_code, warehouse)
|
||||||
stock_queue.append([0, estimated_val_rate])
|
stock_queue.append([0, estimated_val_rate])
|
||||||
|
|
||||||
|
|||||||
@ -211,15 +211,14 @@ def reset_serial_no_status_and_warehouse(serial_nos=None):
|
|||||||
|
|
||||||
def repost_all_stock_vouchers():
|
def repost_all_stock_vouchers():
|
||||||
vouchers = frappe.db.sql("""select distinct voucher_type, voucher_no
|
vouchers = frappe.db.sql("""select distinct voucher_type, voucher_no
|
||||||
from `tabStock Ledger Entry` order by posting_date, posting_time, name""")
|
from `tabStock Ledger Entry`
|
||||||
|
order by posting_date, posting_time, name""")
|
||||||
|
|
||||||
print len(vouchers)
|
|
||||||
rejected = []
|
rejected = []
|
||||||
# vouchers = [["Delivery Note", "DN00060"]]
|
|
||||||
i = 0
|
i = 0
|
||||||
for voucher_type, voucher_no in vouchers:
|
for voucher_type, voucher_no in vouchers:
|
||||||
i+=1
|
i+=1
|
||||||
print i
|
print i, "/", len(vouchers)
|
||||||
try:
|
try:
|
||||||
for dt in ["Stock Ledger Entry", "GL Entry"]:
|
for dt in ["Stock Ledger Entry", "GL Entry"]:
|
||||||
frappe.db.sql("""delete from `tab%s` where voucher_type=%s and voucher_no=%s"""%
|
frappe.db.sql("""delete from `tab%s` where voucher_type=%s and voucher_no=%s"""%
|
||||||
@ -228,8 +227,8 @@ def repost_all_stock_vouchers():
|
|||||||
doc = frappe.get_doc(voucher_type, voucher_no)
|
doc = frappe.get_doc(voucher_type, voucher_no)
|
||||||
if voucher_type=="Stock Entry" and doc.purpose in ["Manufacture", "Repack"]:
|
if voucher_type=="Stock Entry" and doc.purpose in ["Manufacture", "Repack"]:
|
||||||
doc.get_stock_and_rate(force=1)
|
doc.get_stock_and_rate(force=1)
|
||||||
# elif voucher_type=="Purchase Receipt":
|
elif voucher_type=="Purchase Receipt" and doc.is_subcontracted == "Yes":
|
||||||
# doc.create_raw_materials_supplied("pr_raw_material_details")
|
doc.validate()
|
||||||
|
|
||||||
doc.update_stock_ledger()
|
doc.update_stock_ledger()
|
||||||
doc.make_gl_entries(repost_future_gle=False, allow_negative_stock=True)
|
doc.make_gl_entries(repost_future_gle=False, allow_negative_stock=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user