frappe/frappe#478 removed more instances of doclist
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index ef17f66..e9e9869 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -736,7 +736,7 @@
from frappe.core.doctype.print_format.print_format import get_html
frappe.sendmail(new_rv.notification_email_address,
subject="New Invoice : " + new_rv.name,
- message = get_html(new_rv.doc, new_rv.doclist, "SalesInvoice"))
+ message = get_html(new_rv.doc, new_rv, "SalesInvoice"))
def notify_errors(inv, customer, owner):
from frappe.utils.user import get_system_managers
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 7804734..e86d6a9 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -41,7 +41,7 @@
out["sales_team"] = [{
"sales_person": d.sales_person,
"sales_designation": d.sales_designation
- } for d in party_bean.doclist.get({"doctype":"Sales Team"})]
+ } for d in party_bean.get("sales_team")]
return out
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index f2e1c08..77b62ca 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -370,7 +370,7 @@
d.get(ref_fieldname))
def check_active_sales_items(obj):
- for d in obj.doclist.get({"parentfield": obj.fname}):
+ for d in obj.get(obj.fname):
if d.item_code:
item = frappe.db.sql("""select docstatus, is_sales_item,
is_service_item, income_account from tabItem where name = %s""",
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 59ce41f..9b3095d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -289,20 +289,15 @@
si = frappe.get_doc(target)
si.is_pos = 0
si.run_method("onload_post_render")
-
- si.set_doclist(si.doclist.get({"parentfield": ["!=", "entries"]}) +
- si.doclist.get({"parentfield": "entries", "qty": [">", 0]}))
-
- if len(si.get("entries")) == 0:
- frappe.msgprint(_("Hey! All these items have already been invoiced."),
- raise_exception=True)
- return si.doclist
+ if len(si.get("entries")) == 0:
+ frappe.msgprint(_("All these items have already been invoiced."),
+ raise_exception=True)
def update_item(source_doc, target_doc, source_parent):
target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0)
- doclist = get_mapped_doc("Delivery Note", source_name, {
+ doc = get_mapped_doc("Delivery Note", source_name, {
"Delivery Note": {
"doctype": "Sales Invoice",
"validation": {
@@ -318,7 +313,8 @@
"against_sales_order": "sales_order",
"serial_no": "serial_no"
},
- "postprocess": update_item
+ "postprocess": update_item,
+ "filter": lambda d: d.qty - invoiced_qty_map.get(d.name, 0)==0
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
@@ -333,7 +329,7 @@
}
}, target_doc, update_accounts)
- return doclist.as_dict()
+ return doc.as_dict()
@frappe.whitelist()
def make_installation_note(source_name, target_doc=None):
diff --git a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
index 3850cec..968969d 100644
--- a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
+++ b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
@@ -40,8 +40,7 @@
for lc in self.get("landed_cost_details"):
amt = flt(lc.amount) * flt(pr_bean.net_total)/ flt(total_amt)
- matched_row = pr_bean.doclist.get({
- "parentfield": "other_charges",
+ matched_row = pr_bean.get("other_charges", {
"category": "Valuation",
"add_deduct_tax": "Add",
"charge_type": "Actual",
@@ -66,8 +65,8 @@
matched_row[0].cost_center = lc.cost_center
pr_bean.run_method("validate")
- for d in pr_bean.doclist:
- d.save()
+ for d in pr_bean.get_all_children():
+ d.db_update()
def get_total_pr_amt(self, purchase_receipts):
return frappe.db.sql("""SELECT SUM(net_total) FROM `tabPurchase Receipt`
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 312a5a3..296dda9 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -191,29 +191,32 @@
"""update requested qty (before ordered_qty is updated)"""
from erpnext.stock.utils import update_bin
for mr_item_name in mr_items:
- mr_item = mr_obj.doclist.getone({"parentfield": "indent_details", "name": mr_item_name})
- se_detail = bean.doclist.getone({"parentfield": "mtn_details",
- "material_request": mr_obj.name, "material_request_item": mr_item_name})
+ mr_item = mr_obj.get("indent_details", {"name": mr_item_name})
+ se_detail = bean.get("mtn_details", {"material_request": mr_obj.name,
+ "material_request_item": mr_item_name})
- mr_item.ordered_qty = flt(mr_item.ordered_qty)
- mr_item.qty = flt(mr_item.qty)
- se_detail.transfer_qty = flt(se_detail.transfer_qty)
+ if mr_item and se_detail:
+ mr_item = mr_item[0]
+ se_detail = se_detail[0]
+ mr_item.ordered_qty = flt(mr_item.ordered_qty)
+ mr_item.qty = flt(mr_item.qty)
+ se_detail.transfer_qty = flt(se_detail.transfer_qty)
- if se_detail.docstatus == 2 and mr_item.ordered_qty > mr_item.qty \
- and se_detail.transfer_qty == mr_item.ordered_qty:
- add_indented_qty = mr_item.qty
- elif se_detail.docstatus == 1 and \
- mr_item.ordered_qty + se_detail.transfer_qty > mr_item.qty:
- add_indented_qty = mr_item.qty - mr_item.ordered_qty
- else:
- add_indented_qty = se_detail.transfer_qty
+ if se_detail.docstatus == 2 and mr_item.ordered_qty > mr_item.qty \
+ and se_detail.transfer_qty == mr_item.ordered_qty:
+ add_indented_qty = mr_item.qty
+ elif se_detail.docstatus == 1 and \
+ mr_item.ordered_qty + se_detail.transfer_qty > mr_item.qty:
+ add_indented_qty = mr_item.qty - mr_item.ordered_qty
+ else:
+ add_indented_qty = se_detail.transfer_qty
- update_bin({
- "item_code": se_detail.item_code,
- "warehouse": se_detail.t_warehouse,
- "indented_qty": (se_detail.docstatus==2 and 1 or -1) * add_indented_qty,
- "posting_date": bean.posting_date,
- })
+ update_bin({
+ "item_code": se_detail.item_code,
+ "warehouse": se_detail.t_warehouse,
+ "indented_qty": (se_detail.docstatus==2 and 1 or -1) * add_indented_qty,
+ "posting_date": bean.posting_date,
+ })
def set_missing_values(source, target_doc):
po = frappe.get_doc(target_doc)
diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py
index 7f4c438..cab1424 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.py
+++ b/erpnext/stock/doctype/serial_no/serial_no.py
@@ -299,7 +299,7 @@
if not stock_ledger_entries: return
- for d in controller.doclist.get({"parentfield": parentfield}):
+ for d in controller.get(parentfield):
serial_no = None
for sle in stock_ledger_entries:
if sle.voucher_detail_no==d.name:
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 1bcceaf..8841b96 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -241,23 +241,23 @@
def validate_return_reference_doc(self):
"""validate item with reference doc"""
- ref = get_return_doclist_and_details(self.fields)
+ ref = get_return_doc_and_details(self)
- if ref.doclist:
+ if ref.doc:
# validate docstatus
- if ref.doclist[0].docstatus != 1:
- frappe.msgprint(_(ref.doclist[0].doctype) + ' "' + ref.doclist[0].name + '": '
+ if ref.doc.docstatus != 1:
+ frappe.msgprint(_(ref.doc.doctype) + ' "' + ref.doc.name + '": '
+ _("Status should be Submitted"), raise_exception=frappe.InvalidStatusError)
# update stock check
- if ref.doclist[0].doctype == "Sales Invoice" and cint(ref.doclist[0].update_stock) != 1:
- frappe.msgprint(_(ref.doclist[0].doctype) + ' "' + ref.doclist[0].name + '": '
+ if ref.doc.doctype == "Sales Invoice" and cint(ref.doc.update_stock) != 1:
+ frappe.msgprint(_(ref.doc.doctype) + ' "' + ref.doc.name + '": '
+ _("Update Stock should be checked."),
raise_exception=NotUpdateStockError)
# posting date check
- ref_posting_datetime = "%s %s" % (cstr(ref.doclist[0].posting_date),
- cstr(ref.doclist[0].posting_time) or "00:00:00")
+ ref_posting_datetime = "%s %s" % (cstr(ref.doc.posting_date),
+ cstr(ref.doc.posting_time) or "00:00:00")
this_posting_datetime = "%s %s" % (cstr(self.posting_date),
cstr(self.posting_time))
if this_posting_datetime < ref_posting_datetime:
@@ -266,18 +266,18 @@
+ ": " + datetime_in_user_format(ref_posting_datetime),
raise_exception=True)
- stock_items = get_stock_items_for_return(ref.doclist, ref.parentfields)
+ stock_items = get_stock_items_for_return(ref.doc, ref.parentfields)
already_returned_item_qty = self.get_already_returned_item_qty(ref.fieldname)
for item in self.get("mtn_details"):
- # validate if item exists in the ref doclist and that it is a stock item
+ # validate if item exists in the ref doc and that it is a stock item
if item.item_code not in stock_items:
msgprint(_("Item") + ': "' + item.item_code + _("\" does not exist in ") +
- ref.doclist[0].doctype + ": " + ref.doclist[0].name,
+ ref.doc.doctype + ": " + ref.doc.name,
raise_exception=frappe.DoesNotExistError)
# validate quantity <= ref item's qty - qty already returned
- ref_item = ref.doclist.getone({"item_code": item.item_code})
+ ref_item = ref.getone({"item_code": item.item_code})
returnable_qty = ref_item.qty - flt(already_returned_item_qty.get(item.item_code))
if not returnable_qty:
frappe.throw("{item}: {item_code} {returned}".format(
@@ -638,13 +638,13 @@
def query_return_item(doctype, txt, searchfield, start, page_len, filters):
txt = txt.replace("%", "")
- ref = get_return_doclist_and_details(filters)
+ ref = get_return_doc_and_details(filters)
- stock_items = get_stock_items_for_return(ref.doclist, ref.parentfields)
+ stock_items = get_stock_items_for_return(ref.doc, ref.parentfields)
result = []
- for item in ref.doclist.get({"parentfield": ["in", ref.parentfields]}):
- if item.item_code in stock_items:
+ for item in ref.doc.get_all_children():
+ if getattr(item, "item_code", None) in stock_items:
item.item_name = cstr(item.item_name)
item.description = cstr(item.description)
if (txt in item.item_code) or (txt in item.item_name) or (txt in item.description):
@@ -704,28 +704,28 @@
limit %(start)s, %(page_len)s
""" % args)
-def get_stock_items_for_return(ref_doclist, parentfields):
- """return item codes filtered from doclist, which are stock items"""
+def get_stock_items_for_return(ref_doc, parentfields):
+ """return item codes filtered from doc, which are stock items"""
if isinstance(parentfields, basestring):
parentfields = [parentfields]
all_items = list(set([d.item_code for d in
- ref_doclist.get({"parentfield": ["in", parentfields]})]))
+ ref_doc.get_all_children() if d.item_code]))
stock_items = frappe.db.sql_list("""select name from `tabItem`
where is_stock_item='Yes' and name in (%s)""" % (", ".join(["%s"] * len(all_items))),
tuple(all_items))
return stock_items
-def get_return_doclist_and_details(args):
+def get_return_doc_and_details(args):
ref = frappe._dict()
- # get ref_doclist
+ # get ref_doc
if args["purpose"] in return_map:
for fieldname, val in return_map[args["purpose"]].items():
if args.get(fieldname):
ref.fieldname = fieldname
- ref.doclist = frappe.get_doclist(val[0], args[fieldname])
+ ref.doc = frappe.get_doc(val[0], args[fieldname])
ref.parentfields = val[1]
break
@@ -748,16 +748,16 @@
if not se.purpose in ["Sales Return", "Purchase Return"]:
return
- ref = get_return_doclist_and_details(se.fields)
+ ref = get_return_doc_and_details(se.fields)
- if ref.doclist[0].doctype == "Delivery Note":
+ if ref.doc.doctype == "Delivery Note":
result = make_return_jv_from_delivery_note(se, ref)
- elif ref.doclist[0].doctype == "Sales Invoice":
+ elif ref.doc.doctype == "Sales Invoice":
result = make_return_jv_from_sales_invoice(se, ref)
- elif ref.doclist[0].doctype == "Purchase Receipt":
+ elif ref.doc.doctype == "Purchase Receipt":
result = make_return_jv_from_purchase_receipt(se, ref)
- # create jv doclist and fetch balance for each unique row item
+ # create jv doc and fetch balance for each unique row item
jv_list = [{
"__islocal": 1,
"doctype": "Journal Voucher",
@@ -785,28 +785,28 @@
def make_return_jv_from_sales_invoice(se, ref):
# customer account entry
parent = {
- "account": ref.doclist[0].debit_to,
- "against_invoice": ref.doclist[0].name,
+ "account": ref.doc.debit_to,
+ "against_invoice": ref.doc.name,
}
# income account entries
children = []
for se_item in se.get("mtn_details"):
- # find item in ref.doclist
- ref_item = ref.doclist.getone({"item_code": se_item.item_code})
+ # find item in ref.doc
+ ref_item = ref.doc.get({"item_code": se_item.item_code})[0]
- account = get_sales_account_from_item(ref.doclist, ref_item)
+ account = get_sales_account_from_item(ref.doc, ref_item)
if account not in children:
children.append(account)
return [parent] + [{"account": account} for account in children]
-def get_sales_account_from_item(doclist, ref_item):
+def get_sales_account_from_item(doc, ref_item):
account = None
if not ref_item.income_account:
if ref_item.parent_item:
- parent_item = doclist.getone({"item_code": ref_item.parent_item})
+ parent_item = doc.get({"item_code": ref_item.parent_item})[0]
account = parent_item.income_account
else:
account = ref_item.income_account
@@ -815,10 +815,10 @@
def make_return_jv_from_delivery_note(se, ref):
invoices_against_delivery = get_invoice_list("Sales Invoice Item", "delivery_note",
- ref.doclist[0].name)
+ ref.doc.name)
if not invoices_against_delivery:
- sales_orders_against_delivery = [d.against_sales_order for d in ref.doclist if d.against_sales_order]
+ sales_orders_against_delivery = [d.against_sales_order for d in ref.doc.get_all_children() if d.against_sales_order]
if sales_orders_against_delivery:
invoices_against_delivery = get_invoice_list("Sales Invoice Item", "sales_order",
@@ -827,8 +827,7 @@
if not invoices_against_delivery:
return []
- packing_item_parent_map = dict([[d.item_code, d.parent_item] for d in ref.doclist.get(
- {"parentfield": ref.parentfields[1]})])
+ packing_item_parent_map = dict([[d.item_code, d.parent_item] for d in ref.doc.get(ref.parentfields[1])])
parent = {}
children = []
@@ -838,16 +837,16 @@
si = frappe.get_doc("Sales Invoice", sales_invoice)
if se_item.item_code in packing_item_parent_map:
- ref_item = si.doclist.get({"item_code": packing_item_parent_map[se_item.item_code]})
+ ref_item = si.get({"item_code": packing_item_parent_map[se_item.item_code]})
else:
- ref_item = si.doclist.get({"item_code": se_item.item_code})
+ ref_item = si.get({"item_code": se_item.item_code})
if not ref_item:
continue
ref_item = ref_item[0]
- account = get_sales_account_from_item(si.doclist, ref_item)
+ account = get_sales_account_from_item(si, ref_item)
if account not in children:
children.append(account)
@@ -874,11 +873,11 @@
def make_return_jv_from_purchase_receipt(se, ref):
invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_receipt",
- ref.doclist[0].name)
+ ref.doc.name)
if not invoice_against_receipt:
purchase_orders_against_receipt = [d.prevdoc_docname for d in
- ref.doclist.get({"prevdoc_doctype": "Purchase Order"}) if d.prevdoc_docname]
+ ref.get({"prevdoc_doctype": "Purchase Order"}) if d.prevdoc_docname]
if purchase_orders_against_receipt:
invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_order",
@@ -893,7 +892,7 @@
for se_item in se.get("mtn_details"):
for purchase_invoice in invoice_against_receipt:
pi = frappe.get_doc("Purchase Invoice", purchase_invoice)
- ref_item = pi.doclist.get({"item_code": se_item.item_code})
+ ref_item = pi.get({"item_code": se_item.item_code})
if not ref_item:
continue
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 57b2c2e..ed23cf7 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -209,12 +209,10 @@
def get_party_item_code(args, item_bean, out):
if args.transaction_type == "selling":
- customer_item_code = item_bean.doclist.get({"parentfield": "item_customer_details",
- "customer_name": args.customer})
+ customer_item_code = item_bean.get("item_customer_details", {"customer_name": args.customer})
out.customer_item_code = customer_item_code[0].ref_code if customer_item_code else None
else:
- item_supplier = item_bean.doclist.get({"parentfield": "item_supplier_details",
- "supplier": args.supplier})
+ item_supplier = item_bean.get({"item_supplier_details", {"supplier": args.supplier})
out.supplier_part_no = item_supplier[0].supplier_part_no if item_supplier else None