Merge pull request #2139 from nabinhait/hotfix
Repost stock reconciliation and valuation rate in repack entry
This commit is contained in:
commit
714b3ef7f8
31
erpnext/patches/v4_2/repost_stock_reconciliation.py
Normal file
31
erpnext/patches/v4_2/repost_stock_reconciliation.py
Normal file
@ -0,0 +1,31 @@
|
||||
# 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
|
||||
import json
|
||||
|
||||
def execute():
|
||||
existing_allow_negative_stock = frappe.db.get_default("allow_negative_stock")
|
||||
frappe.db.set_default("allow_negative_stock", 1)
|
||||
|
||||
head_row = ["Item Code", "Warehouse", "Quantity", "Valuation Rate"]
|
||||
stock_reco_to_be_reposted = []
|
||||
for d in frappe.db.sql("""select name, reconciliation_json from `tabStock Reconciliation`
|
||||
where docstatus=1 and creation > '2014-03-01'""", as_dict=1):
|
||||
data = json.loads(d.reconciliation_json)
|
||||
for row in data[data.index(head_row)+1:]:
|
||||
if row[3] in ["", None]:
|
||||
stock_reco_to_be_reposted.append(d.name)
|
||||
break
|
||||
|
||||
for dn in stock_reco_to_be_reposted:
|
||||
reco = frappe.get_doc("Stock Reconciliation", dn)
|
||||
reco.docstatus = 2
|
||||
reco.on_cancel()
|
||||
|
||||
reco.docstatus = 1
|
||||
reco.validate()
|
||||
reco.on_submit()
|
||||
|
||||
frappe.db.set_default("allow_negative_stock", existing_allow_negative_stock)
|
@ -206,7 +206,7 @@ class StockEntry(StockController):
|
||||
def set_total_amount(self):
|
||||
self.total_amount = sum([flt(item.amount) for item in self.get("mtn_details")])
|
||||
|
||||
def get_stock_and_rate(self):
|
||||
def get_stock_and_rate(self, force=False):
|
||||
"""get stock and incoming rate on posting date"""
|
||||
|
||||
raw_material_cost = 0.0
|
||||
@ -237,7 +237,7 @@ class StockEntry(StockController):
|
||||
|
||||
# get incoming rate
|
||||
if not d.bom_no:
|
||||
if not flt(d.incoming_rate) or d.s_warehouse or self.purpose == "Sales Return":
|
||||
if not flt(d.incoming_rate) or d.s_warehouse or self.purpose == "Sales Return" or force:
|
||||
incoming_rate = flt(self.get_incoming_rate(args), self.precision("incoming_rate", d))
|
||||
if incoming_rate > 0:
|
||||
d.incoming_rate = incoming_rate
|
||||
@ -247,13 +247,18 @@ class StockEntry(StockController):
|
||||
|
||||
# set incoming rate for fg item
|
||||
if self.purpose == "Manufacture/Repack":
|
||||
number_of_fg_items = len([t.t_warehouse for t in self.get("mtn_details")])
|
||||
|
||||
for d in self.get("mtn_details"):
|
||||
if d.bom_no or (d.t_warehouse and number_of_fg_items == 1):
|
||||
if not flt(d.incoming_rate) or force:
|
||||
operation_cost_per_unit = 0
|
||||
if d.bom_no:
|
||||
if not flt(d.incoming_rate):
|
||||
bom = frappe.db.get_value("BOM", d.bom_no, ["operating_cost", "quantity"], as_dict=1)
|
||||
operation_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity)
|
||||
d.incoming_rate = operation_cost_per_unit + (raw_material_cost / flt(d.transfer_qty))
|
||||
d.amount = flt(d.transfer_qty) * flt(d.incoming_rate)
|
||||
break
|
||||
|
||||
def get_incoming_rate(self, args):
|
||||
incoming_rate = 0
|
||||
|
@ -72,7 +72,7 @@ class Warehouse(Document):
|
||||
if parent_account:
|
||||
self.create_account_under = parent_account
|
||||
else:
|
||||
frappe.throw(_("Please enter parent account group for warehouse account"))
|
||||
frappe.throw(_("Please enter parent account group for warehouse {0}").format(self.name))
|
||||
elif frappe.db.get_value("Account", self.create_account_under, "company") != self.company:
|
||||
frappe.throw(_("Warehouse {0}: Parent account {1} does not bolong to the company {2}")
|
||||
.format(self.name, self.create_account_under, self.company))
|
||||
|
Loading…
Reference in New Issue
Block a user