code changes for single stock entry

This commit is contained in:
pawan 2018-02-07 19:06:18 +05:30
parent 9b7093e4d6
commit 2b885beaee
4 changed files with 31 additions and 35 deletions

View File

@ -284,7 +284,8 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
}
,
callback: function(r) {
frappe.set_route("List", "Stock Entry", "List",{"purchase_order":r.message,"doc_status":0})
var doclist = frappe.model.sync(r.message);
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
}
});
},

View File

@ -435,30 +435,29 @@ def make_rm_stock_entry(purchase_order, rm_items):
item_wh = frappe._dict(frappe.db.sql("""select item_code, description
from `tabItem` where name in ({0})""".
format(", ".join(["%s"] * len(item_code_list))), item_code_list))
stock_entry = frappe.new_doc("Stock Entry")
stock_entry.purpose = "Subcontract"
stock_entry.purchase_order = purchase_order.name
stock_entry.supplier = purchase_order.supplier
stock_entry.supplier_name = purchase_order.supplier_name
stock_entry.supplier_address = purchase_order.supplier_address
stock_entry.address_display = purchase_order.address_display
stock_entry.company = purchase_order.company
stock_entry.from_bom = 1
for item_code in item_code_list:
stock_entry = frappe.new_doc("Stock Entry")
stock_entry.purpose = "Subcontract"
stock_entry.purchase_order = purchase_order.name
stock_entry.supplier = purchase_order.supplier
stock_entry.supplier_name = purchase_order.supplier_name
stock_entry.supplier_address = purchase_order.supplier_address
stock_entry.address_display = purchase_order.address_display
stock_entry.company = purchase_order.company
stock_entry.docstatus = 0
stock_entry.from_bom = 1
po_item = [d for d in purchase_order.items if d.item_code == item_code][0]
stock_entry.fg_completed_qty = po_item.qty
stock_entry.bom_no = po_item.bom
bom_no = po_item.bom
for rm_item_data in rm_items_list:
if rm_item_data["item_code"] == item_code:
items_dict = {rm_item_data["rm_item_code"]:
{"item_name":rm_item_data["item_name"],
"description":item_wh.get(rm_item_data["rm_item_code"]),
'qty':rm_item_data["qty"],
'from_warehouse':rm_item_data["warehouse"],
'stock_uom':rm_item_data["stock_uom"]}}
stock_entry.add_to_stock_entry_detail(items_dict)
stock_entry.save()
{"item_name":rm_item_data["item_name"],
"description":item_wh.get(rm_item_data["rm_item_code"]),
'qty':rm_item_data["qty"],
'from_warehouse':rm_item_data["warehouse"],
'stock_uom':rm_item_data["stock_uom"],
'bom_no':bom_no}}
stock_entry.add_to_stock_entry_detail(items_dict, bom_no)
return stock_entry.as_dict()
else:
frappe.throw(_("No Items selected for transfer"))
return purchase_order.name

View File

@ -586,9 +586,14 @@ def validate_bom_no(item, bom_no):
if bom.docstatus != 1:
if not getattr(frappe.flags, "in_test", False):
frappe.throw(_("BOM {0} must be submitted").format(bom_no))
if item and not (bom.item.lower() == item.lower() or \
bom.item.lower() == cstr(frappe.db.get_value("Item", item, "variant_of")).lower()):
frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
if item:
rm_item_exists = False
for d in bom.items:
if (d.item_code.lower() == item.lower() or \
d.item_code.lower() == cstr(frappe.db.get_value("Item", item, "variant_of")).lower()):
rm_item_exists = True
if not rm_item_exists:
frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
@frappe.whitelist()
def get_children(doctype, parent=None, is_root=False, **filters):

View File

@ -64,13 +64,6 @@ class StockEntry(StockController):
self.calculate_rate_and_amount(update_finished_item_rate=False)
def on_submit(self):
if self.purpose == "Subcontract":
for d in self.items:
if not d.t_warehouse:
if self.to_warehouse:
d.t_warehouse = self.to_warehouse
else:
frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
self.update_stock_ledger()
@ -165,9 +158,7 @@ class StockEntry(StockController):
if self.to_warehouse:
d.t_warehouse = self.to_warehouse
else:
#move validation for sub contract to submit
if self.purpose != "Subcontract":
frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
if self.purpose in ["Manufacture", "Repack"]:
if validate_for_manufacture_repack:
@ -417,7 +408,7 @@ class StockEntry(StockController):
"""validation: finished good quantity should be same as manufacturing quantity"""
items_with_target_warehouse = []
for d in self.get('items'):
if d.bom_no and flt(d.transfer_qty) != flt(self.fg_completed_qty) and (d.t_warehouse != getattr(self, "pro_doc", frappe._dict()).scrap_warehouse):
if self.purpose != "Subcontract" and d.bom_no and flt(d.transfer_qty) != flt(self.fg_completed_qty) and (d.t_warehouse != getattr(self, "pro_doc", frappe._dict()).scrap_warehouse):
frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \
format(d.idx, d.transfer_qty, self.fg_completed_qty))
@ -808,7 +799,7 @@ class StockEntry(StockController):
def add_to_stock_entry_detail(self, item_dict, bom_no=None):
expense_account, cost_center = frappe.db.get_values("Company", self.company, \
["default_expense_account", "cost_center"])[0]
for d in item_dict:
stock_uom = item_dict[d].get("stock_uom") or frappe.db.get_value("Item", d, "stock_uom")