Get valuation rate in manufacturing/repack entry
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index fd673a3..e4bab8e 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -206,7 +206,7 @@
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 @@
# 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 @@
# 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:
- 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)
+ 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:
+ 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
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 0095bbb..f50c184 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -22,16 +22,16 @@
self.update_parent_account()
def update_parent_account(self):
-
+
if not getattr(self, "__islocal", None) \
and (self.create_account_under != frappe.db.get_value("Warehouse", self.name, "create_account_under")):
-
+
self.validate_parent_account()
-
- warehouse_account = frappe.db.get_value("Account",
- {"account_type": "Warehouse", "company": self.company, "master_name": self.name},
+
+ warehouse_account = frappe.db.get_value("Account",
+ {"account_type": "Warehouse", "company": self.company, "master_name": self.name},
["name", "parent_account"])
-
+
if warehouse_account and warehouse_account[1] != self.create_account_under:
acc_doc = frappe.get_doc("Account", warehouse_account[0])
acc_doc.parent_account = self.create_account_under
@@ -64,19 +64,19 @@
def validate_parent_account(self):
if not self.company:
frappe.throw(_("Warehouse {0}: Company is mandatory").format(self.name))
-
+
if not self.create_account_under:
parent_account = frappe.db.get_value("Account",
{"account_name": "Stock Assets", "company": self.company})
-
+
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))
-
+
def on_trash(self):
# delete bin