From e88bc8b12afd4a78667bc9210e99263c16d0af08 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 27 Mar 2014 17:51:41 +0530 Subject: [PATCH] frappe/frappe#478 --- .../journal_voucher/journal_voucher.py | 15 +++-------- .../purchase_invoice/test_purchase_invoice.py | 4 +-- .../doctype/sales_invoice/sales_invoice.py | 8 +----- .../sales_invoice/test_sales_invoice.py | 25 ++++++++----------- erpnext/accounts/utils.py | 2 +- erpnext/buying/doctype/supplier/supplier.py | 2 +- erpnext/controllers/accounts_controller.py | 17 ++++--------- erpnext/controllers/buying_controller.py | 3 +-- erpnext/controllers/selling_controller.py | 3 +-- erpnext/home/__init__.py | 5 ++-- erpnext/hr/doctype/employee/employee.py | 2 +- .../hr/doctype/holiday_list/holiday_list.py | 2 +- .../test_leave_application.py | 3 +-- .../leave_control_panel.py | 16 +++++------- erpnext/hr/doctype/salary_slip/salary_slip.py | 2 +- .../salary_structure/salary_structure.py | 2 +- .../upload_attendance/upload_attendance.py | 4 +-- .../production_planning_tool.py | 14 +++++------ erpnext/patches/4_0/update_user_properties.py | 2 +- .../doctype/time_log/test_time_log.py | 2 +- erpnext/selling/doctype/customer/customer.py | 7 +++--- .../doctype/sales_order/test_sales_order.py | 6 ++--- .../page/sales_browser/sales_browser.py | 3 +-- erpnext/setup/doctype/company/company.py | 6 ++--- .../doctype/naming_series/naming_series.py | 11 ++++---- erpnext/stock/doctype/item/item.py | 4 +-- .../material_request/material_request.py | 2 +- .../stock/doctype/price_list/price_list.py | 3 +-- erpnext/stock/doctype/serial_no/serial_no.py | 2 +- .../doctype/stock_ledger/stock_ledger.py | 1 - erpnext/stock/get_item_details.py | 2 +- erpnext/stock/stock_ledger.py | 2 +- .../support_email_settings.py | 7 +++--- erpnext/utilities/doctype/address/address.py | 2 +- .../doctype/sms_control/sms_control.py | 5 ++-- erpnext/utilities/transaction_base.py | 9 +++---- 36 files changed, 81 insertions(+), 124 deletions(-) diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py index 9884b57da34..5727ed48554 100644 --- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py +++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py @@ -389,19 +389,12 @@ def get_payment_entry(doc): jv.doc.company = doc.company jv.doc.fiscal_year = doc.fiscal_year - jv.doclist.append({ - "doctype": "Journal Voucher Detail", - "parentfield": "entries" - }) + d1 = jv.append("entries") + d2 = jv.append("entries") - jv.doclist.append({ - "doctype": "Journal Voucher Detail", - "parentfield": "entries" - }) - if bank_account: - jv.doclist[2].account = bank_account["account"] - jv.doclist[2].balance = bank_account["balance"] + d2.account = bank_account["account"] + d2.balance = bank_account["balance"] return jv diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 28bd2d183db..c648c37f155 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -174,9 +174,7 @@ class TestPurchaseInvoice(unittest.TestCase): jv.submit() pi = frappe.bean(copy=test_records[0]) - pi.doclist.append({ - "doctype": "Purchase Invoice Advance", - "parentfield": "advance_allocation_details", + pi.append("advance_allocation_details", { "journal_voucher": jv.doc.name, "jv_detail_no": jv.doclist[1].name, "advance_amount": 400, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 068d82ce850..c61df0e9753 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -9,7 +9,7 @@ from frappe.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, get_first_day, get_last_day from frappe.utils import comma_and, get_url -from frappe.model.doc import make_autoname +from frappe.model.naming import make_autoname from frappe.model.bean import getlist from frappe.model.code import get_obj from frappe import _, msgprint @@ -587,12 +587,6 @@ class SalesInvoice(SellingController): invoice_date = %s, territory = %s, net_total = %s, grand_total = %s where invoice_no = %s and parent = %s""", (self.doc.name, self.doc.amended_from, self.doc.c_form_no)) - - @property - def meta(self): - if not hasattr(self, "_meta"): - self._meta = frappe.get_doctype(self.doc.doctype) - return self._meta def validate_recurring_invoice(self): if self.doc.convert_into_recurring_invoice: diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index a4a1f7ba795..1c67e711a32 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -139,16 +139,14 @@ class TestSalesInvoice(unittest.TestCase): def test_sales_invoice_discount_amount(self): si = frappe.bean(copy=test_records[3]) si.doc.discount_amount = 104.95 - si.doclist.append({ + si.append("other_charges", { "doctype": "Sales Taxes and Charges", - "parentfield": "other_charges", "charge_type": "On Previous Row Amount", "account_head": "_Test Account Service Tax - _TC", "cost_center": "_Test Cost Center - _TC", "description": "Service Tax", "rate": 10, "row_id": 8, - "idx": 9 }) si.insert() @@ -196,16 +194,14 @@ class TestSalesInvoice(unittest.TestCase): def test_discount_amount_gl_entry(self): si = frappe.bean(copy=test_records[3]) si.doc.discount_amount = 104.95 - si.doclist.append({ + si.append("other_charges", { "doctype": "Sales Taxes and Charges", - "parentfield": "other_charges", "charge_type": "On Previous Row Amount", "account_head": "_Test Account Service Tax - _TC", "cost_center": "_Test Cost Center - _TC", "description": "Service Tax", "rate": 10, - "row_id": 8, - "idx": 9 + "row_id": 8 }) si.insert() si.submit() @@ -369,7 +365,7 @@ class TestSalesInvoice(unittest.TestCase): from erpnext.accounts.doctype.journal_voucher.test_journal_voucher \ import test_records as jv_test_records - jv = frappe.bean(frappe.copy_doclist(jv_test_records[0])) + jv = frappe.bean(frappe.copy_doc(jv_test_records[0])) jv.doclist[1].against_invoice = w.doc.name jv.insert() jv.submit() @@ -385,7 +381,7 @@ class TestSalesInvoice(unittest.TestCase): tlb = frappe.bean("Time Log Batch", "_T-Time Log Batch-00001") tlb.submit() - si = frappe.bean(frappe.copy_doclist(test_records[0])) + si = frappe.bean(frappe.copy_doc(test_records[0])) si.doclist[1].time_log_batch = "_T-Time Log Batch-00001" si.insert() si.submit() @@ -444,7 +440,7 @@ class TestSalesInvoice(unittest.TestCase): self._insert_purchase_receipt() self._insert_pos_settings() - pos = frappe.copy_doclist(test_records[1]) + pos = frappe.copy_doc(test_records[1]) pos[0]["is_pos"] = 1 pos[0]["update_stock"] = 1 pos[0]["posting_time"] = "12:05" @@ -510,7 +506,7 @@ class TestSalesInvoice(unittest.TestCase): pr.insert() pr.submit() - si_doclist = frappe.copy_doclist(test_records[1]) + si_doclist = frappe.copy_doc(test_records[1]) si_doclist[0]["update_stock"] = 1 si_doclist[0]["posting_time"] = "12:05" si_doclist[1]["warehouse"] = "_Test Warehouse No Account - _TC" @@ -555,7 +551,7 @@ class TestSalesInvoice(unittest.TestCase): self.clear_stock_account_balance() set_perpetual_inventory() - si_copy = frappe.copy_doclist(test_records[1]) + si_copy = frappe.copy_doc(test_records[1]) si_copy[1]["item_code"] = None si = frappe.bean(si_copy) si.insert() @@ -582,7 +578,7 @@ class TestSalesInvoice(unittest.TestCase): def test_sales_invoice_gl_entry_with_aii_non_stock_item(self): self.clear_stock_account_balance() set_perpetual_inventory() - si_copy = frappe.copy_doclist(test_records[1]) + si_copy = frappe.copy_doc(test_records[1]) si_copy[1]["item_code"] = "_Test Non Stock Item" si = frappe.bean(si_copy) si.insert() @@ -640,9 +636,8 @@ class TestSalesInvoice(unittest.TestCase): jv.submit() si = frappe.bean(copy=test_records[0]) - si.doclist.append({ + si.append("advance_adjustment_details", { "doctype": "Sales Invoice Advance", - "parentfield": "advance_adjustment_details", "journal_voucher": jv.doc.name, "jv_detail_no": jv.doclist[1].name, "advance_amount": 400, diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 3805ec34684..260344c2415 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -242,7 +242,7 @@ def get_company_default(company, fieldname): if not value: throw(_("Please mention default value for '") + - _(frappe.get_doctype("company").get_label(fieldname) + + _(frappe.get_meta("Company").get_label(fieldname) + _("' in Company: ") + company)) return value diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 44dcd5fd286..0102edca649 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -7,7 +7,7 @@ import frappe.defaults from frappe.utils import cint from frappe import msgprint, _ -from frappe.model.doc import make_autoname +from frappe.model.naming import make_autoname from erpnext.accounts.party import create_party_account from erpnext.utilities.transaction_base import TransactionBase diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 35234ce5684..3eac80f4409 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -121,17 +121,11 @@ class AccountsController(TransactionBase): from frappe.model import default_fields tax_master = frappe.bean(tax_master_doctype, self.doc.fields.get(tax_master_field)) - for i, tax in enumerate(tax_master.doclist.get({"parentfield": tax_parentfield})): + for i, tax in enumerate(tax_master.get(tax_parentfield)): for fieldname in default_fields: - tax.fields[fieldname] = None - - tax.fields.update({ - "doctype": tax_doctype, - "parentfield": tax_parentfield, - "idx": i+1 - }) - - self.doclist.append(tax) + tax.set(fieldname, None) + + self.append(tax_parentfield, tax) def get_other_charges(self): self.set("other_charges", []) @@ -410,9 +404,8 @@ class AccountsController(TransactionBase): self.set(parentfield, []) for d in res: - self.doclist.append({ + self.append(parentfield, { "doctype": child_doctype, - "parentfield": parentfield, "journal_voucher": d.jv_no, "jv_detail_no": d.jv_detail_no, "remarks": d.remark, diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 655b101a128..6392e58cd4e 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -230,7 +230,6 @@ class BuyingController(StockController): for item in bom_items: required_qty = flt(item.qty_consumed_per_unit) * flt(d.qty) * flt(d.conversion_factor) rm_doclist = { - "parentfield": raw_material_table, "doctype": self.doc.doctype + " Item Supplied", "reference_name": d.name, "bom_detail_no": item.name, @@ -248,7 +247,7 @@ class BuyingController(StockController): "description": item.description, }) - self.doclist.append(rm_doclist) + self.append(raw_material_table, rm_doclist) raw_materials_cost += required_qty * flt(item.rate) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 5e0ea659f59..a3d140bd1ea 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -59,9 +59,8 @@ class SellingController(StockController): shipping_amount = condition.shipping_amount break - self.doclist.append({ + self.append("other_charges", { "doctype": "Sales Taxes and Charges", - "parentfield": "other_charges", "charge_type": "Actual", "account_head": shipping_rule.doc.account, "cost_center": shipping_rule.doc.cost_center, diff --git a/erpnext/home/__init__.py b/erpnext/home/__init__.py index 2aae0b0b0c0..75fab1c9ea1 100644 --- a/erpnext/home/__init__.py +++ b/erpnext/home/__init__.py @@ -59,8 +59,7 @@ feed_dict = { def make_feed(feedtype, doctype, name, owner, subject, color): "makes a new Feed record" #msgprint(subject) - from frappe.model.doc import Document - from frappe.utils import get_fullname + from frappe.utils import get_fullname if feedtype in ('Login', 'Comment', 'Assignment'): # delete old login, comment feed @@ -72,7 +71,7 @@ def make_feed(feedtype, doctype, name, owner, subject, color): where doc_type=%s and doc_name=%s and ifnull(feed_type,'') != 'Comment'""", (doctype, name)) - f = Document('Feed') + f = frappe.get_doc('Feed') f.owner = owner f.feed_type = feedtype f.doc_type = doctype diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index aacb2aa44bf..d6f1241a212 100644 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.utils import getdate, validate_email_add, cstr, cint -from frappe.model.doc import make_autoname +from frappe.model.naming import make_autoname from frappe import msgprint, throw, _ import frappe.permissions from frappe.defaults import get_restrictions diff --git a/erpnext/hr/doctype/holiday_list/holiday_list.py b/erpnext/hr/doctype/holiday_list/holiday_list.py index c0f1b1b83ea..80c14130fa4 100644 --- a/erpnext/hr/doctype/holiday_list/holiday_list.py +++ b/erpnext/hr/doctype/holiday_list/holiday_list.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.utils import add_days, add_years, cint, getdate -from frappe.model.doc import make_autoname +from frappe.model.naming import make_autoname from frappe import msgprint, throw, _ import datetime diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 30f0cb7db9e..cb8f77ef1a1 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -24,9 +24,8 @@ class TestLeaveApplication(unittest.TestCase): temp_session_user = frappe.session.user frappe.set_user("Administrator") employee = frappe.bean("Employee", employee) - employee.doclist.append({ + employee.append("employee_leave_approvers", { "doctype": "Employee Leave Approver", - "parentfield": "employee_leave_approvers", "leave_approver": leave_approver }) employee.save() diff --git a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py index f3aace2e5c1..bf912655bae 100644 --- a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py +++ b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe.utils import cint, cstr, flt, nowdate -from frappe.model.doc import Document from frappe.model.code import get_obj from frappe import msgprint, _ @@ -38,10 +37,9 @@ class LeaveControlPanel(Document): return e def validate_values(self): - meta = frappe.get_doctype(self.doc.doctype) for f in ["fiscal_year", "leave_type", "no_of_days"]: - if not self.doc.fields[f]: - frappe.throw(_(meta.get_label(f)) + _(" is mandatory")) + if not self.get(f): + frappe.throw(_(self.meta.get_label(f)) + _(" is mandatory")) def allocate_leave(self): self.validate_values() @@ -52,7 +50,8 @@ class LeaveControlPanel(Document): for d in self.get_employees(): try: - la = Document('Leave Allocation') + la = frappe.get_doc('Leave Allocation') + la.set("__islocal", 1) la.employee = cstr(d[0]) la.employee_name = frappe.db.get_value('Employee',cstr(d[0]),'employee_name') la.leave_type = self.doc.leave_type @@ -60,11 +59,8 @@ class LeaveControlPanel(Document): la.posting_date = nowdate() la.carry_forward = cint(self.doc.carry_forward) la.new_leaves_allocated = flt(self.doc.no_of_days) - la_obj = get_obj(doc=la) - la_obj.doc.docstatus = 1 - la_obj.validate() - la_obj.on_update() - la_obj.doc.save(1) + la.docstatus = 1 + la.save() leave_allocated_for.append(d[0]) except: pass diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py index a7c4f8df166..e167835ad58 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.utils import add_days, cint, cstr, flt, getdate, nowdate, _round -from frappe.model.doc import make_autoname +from frappe.model.naming import make_autoname from frappe.model.bean import getlist from frappe.model.code import get_obj from frappe import msgprint, _ diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.py b/erpnext/hr/doctype/salary_structure/salary_structure.py index ae103945fca..ab73a095104 100644 --- a/erpnext/hr/doctype/salary_structure/salary_structure.py +++ b/erpnext/hr/doctype/salary_structure/salary_structure.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.utils import cstr, flt -from frappe.model.doc import make_autoname +from frappe.model.naming import make_autoname from frappe import msgprint, _ diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.py b/erpnext/hr/doctype/upload_attendance/upload_attendance.py index 844806ecb73..8a544158324 100644 --- a/erpnext/hr/doctype/upload_attendance/upload_attendance.py +++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.py @@ -120,7 +120,7 @@ def upload(): error = False from frappe.utils.datautils import check_record, import_doc - doctype_dl = frappe.get_doctype("Attendance") + doctype_dl = frappe.get_meta("Attendance") for i, row in enumerate(rows[5:]): if not row: continue @@ -131,7 +131,7 @@ def upload(): d["docstatus"] = frappe.db.get_value("Attendance", d.name, "docstatus") try: - check_record(d, doctype_dl=doctype_dl) + check_record(d) ret.append(import_doc(d, "Attendance", 1, row_idx, submit=True)) except Exception, e: error = True diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 89fafbcab7d..9f14b2cc4ea 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -366,7 +366,7 @@ class ProductionPlanningTool(Document): if items_to_be_requested: for item in items_to_be_requested: item_wrapper = frappe.bean("Item", item) - pr_doclist = [{ + pr_doc = frappe.get_doc({ "doctype": "Material Request", "__islocal": 1, "naming_series": "IDT", @@ -376,12 +376,11 @@ class ProductionPlanningTool(Document): "fiscal_year": fiscal_year, "requested_by": frappe.session.user, "material_request_type": "Purchase" - }] + }) for sales_order, requested_qty in items_to_be_requested[item].items(): - pr_doclist.append({ + pr_doc.append("indent_details", { "doctype": "Material Request Item", "__islocal": 1, - "parentfield": "indent_details", "item_code": item, "item_name": item_wrapper.doc.item_name, "description": item_wrapper.doc.description, @@ -394,10 +393,9 @@ class ProductionPlanningTool(Document): "sales_order_no": sales_order if sales_order!="No Sales Order" else None }) - pr_wrapper = frappe.bean(pr_doclist) - pr_wrapper.ignore_permissions = 1 - pr_wrapper.submit() - purchase_request_list.append(pr_wrapper.doc.name) + pr_doc.ignore_permissions = 1 + pr_doc.submit() + purchase_request_list.append(pr_doc.name) if purchase_request_list: pur_req = ["""%s""" % \ diff --git a/erpnext/patches/4_0/update_user_properties.py b/erpnext/patches/4_0/update_user_properties.py index 6dac125c1cb..262f7b8230e 100644 --- a/erpnext/patches/4_0/update_user_properties.py +++ b/erpnext/patches/4_0/update_user_properties.py @@ -39,7 +39,7 @@ def update_user_match(): doctype_matches.setdefault(doctype, []).append(match) for doctype, user_matches in doctype_matches.items(): - meta = frappe.get_doctype(doctype) + meta = frappe.get_meta(doctype) # for each user with roles of this doctype, check if match condition applies for user in frappe.db.sql_list("""select name from `tabUser` diff --git a/erpnext/projects/doctype/time_log/test_time_log.py b/erpnext/projects/doctype/time_log/test_time_log.py index b6e27417237..973e89ba599 100644 --- a/erpnext/projects/doctype/time_log/test_time_log.py +++ b/erpnext/projects/doctype/time_log/test_time_log.py @@ -8,7 +8,7 @@ from erpnext.projects.doctype.time_log.time_log import OverlapError class TestTimeLog(unittest.TestCase): def test_duplication(self): - ts = frappe.bean(frappe.copy_doclist(test_records[0])) + ts = frappe.bean(frappe.copy_doc(test_records[0])) self.assertRaises(OverlapError, ts.insert) test_records = [[{ diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 1fc2613d1fb..1ab827d0e21 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import frappe -from frappe.model.doc import Document, make_autoname +from frappe.model.naming import make_autoname from frappe import msgprint, _ import frappe.defaults @@ -56,7 +56,8 @@ class Customer(TransactionBase): (self.doc.name, self.doc.customer_name, self.doc.lead_name)) lead = frappe.db.get_value("Lead", self.doc.lead_name, ["lead_name", "email_id", "phone", "mobile_no"], as_dict=True) - c = Document('Contact') + c = frappe.get_doc('Contact') + c.set("__islocal", 1) c.first_name = lead.lead_name c.email_id = lead.email_id c.phone = lead.phone @@ -65,7 +66,7 @@ class Customer(TransactionBase): c.customer_name = self.doc.customer_name c.is_primary_contact = 1 try: - c.save(1) + c.save() except NameError, e: pass diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index e325aeb1eaa..869350cd5c0 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -80,7 +80,7 @@ class TestSalesOrder(unittest.TestCase): _insert_purchase_receipt(so.doclist[1].item_code) - dn = frappe.bean(frappe.copy_doclist(dn_test_records[0])) + dn = frappe.bean(frappe.copy_doc(dn_test_records[0])) dn.doclist[1].item_code = so.doclist[1].item_code dn.doclist[1].against_sales_order = so.doc.name dn.doclist[1].prevdoc_detail_docname = so.doclist[1].name @@ -199,7 +199,7 @@ class TestSalesOrder(unittest.TestCase): # change item in test so record - test_record = frappe.copy_doclist(test_records[0]) + test_record = frappe.copy_doc(test_records[0]) test_record[1]["item_code"] = "_Test Sales BOM Item" # reset bin @@ -248,7 +248,7 @@ class TestSalesOrder(unittest.TestCase): from erpnext.selling.doctype.sales_bom.test_sales_bom import test_records as sbom_test_records # change item in test so record - test_record = frappe.copy_doclist(test_records[0]) + test_record = frappe.copy_doc(test_records[0]) test_record[1]["item_code"] = "_Test Sales BOM Item" # reset bin diff --git a/erpnext/selling/page/sales_browser/sales_browser.py b/erpnext/selling/page/sales_browser/sales_browser.py index e53515c22ec..42839f3e4e7 100644 --- a/erpnext/selling/page/sales_browser/sales_browser.py +++ b/erpnext/selling/page/sales_browser/sales_browser.py @@ -21,8 +21,7 @@ def get_children(): @frappe.whitelist() def add_node(): - # from frappe.model.doc import Document - ctype = frappe.form_dict.get('ctype') + # ctype = frappe.form_dict.get('ctype') parent_field = 'parent_' + ctype.lower().replace(' ', '_') name_field = ctype.lower().replace(' ', '_') + '_name' diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 9c980684e8e..a7e884eb580 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -86,15 +86,13 @@ class Company(Document): website_settings.doc.home_page = webpage.doc.name website_settings.doc.brand_html = self.doc.name website_settings.doc.copyright = self.doc.name - website_settings.doclist.append({ + website_settings.append("top_bar_items", { "doctype": "Top Bar Item", - "parentfield": "top_bar_items", "label":"Contact", "url": "contact" }) - website_settings.doclist.append({ + website_settings.append("top_bar_items", { "doctype": "Top Bar Item", - "parentfield": "top_bar_items", "label":"Blog", "url": "blog" }) diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py index 454b38a3499..d1608fc5814 100644 --- a/erpnext/setup/doctype/naming_series/naming_series.py +++ b/erpnext/setup/doctype/naming_series/naming_series.py @@ -56,26 +56,27 @@ class NamingSeries(Document): default = options[0] # update in property setter - from frappe.model.doc import Document - prop_dict = {'options': "\n".join(options), 'default': default} + prop_dict = {'options': "\n".join(options), 'default': default} for prop in prop_dict: ps_exists = frappe.db.sql("""SELECT name FROM `tabProperty Setter` WHERE doc_type = %s AND field_name = 'naming_series' AND property = %s""", (doctype, prop)) if ps_exists: - ps = Document('Property Setter', ps_exists[0][0]) + ps = frappe.get_doc('Property Setter', ps_exists[0][0]) ps.value = prop_dict[prop] ps.save() else: - ps = Document('Property Setter', fielddata = { + ps = frappe.get_doc({ + 'doctype': 'Property Setter', 'doctype_or_field': 'DocField', 'doc_type': doctype, 'field_name': 'naming_series', 'property': prop, 'value': prop_dict[prop], 'property_type': 'Select', + '__islocal': 1 }) - ps.save(1) + ps.save() self.doc.set_options = "\n".join(options) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 3a20d8cdf5f..2074925e8c2 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -18,7 +18,7 @@ class Item(DocListController): def autoname(self): if frappe.db.get_default("item_naming_by")=="Naming Series": - from frappe.model.doc import make_autoname + from frappe.model.naming import make_autoname self.doc.item_code = make_autoname(self.doc.naming_series+'.#####') elif not self.doc.item_code: msgprint(_("Item Code (item_code) is mandatory because Item naming is not sequential."), raise_exception=1) @@ -272,7 +272,7 @@ def validate_end_of_life(item_code, end_of_life=None, verbose=1): "in Item master") % { "item_code": item_code, "date": formatdate(end_of_life), - "end_of_life_label": frappe.get_doctype("Item").get_label("end_of_life") + "end_of_life_label": frappe.get_meta("Item").get_label("end_of_life") } _msgprint(msg, verbose) diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index c05a8d87b22..fda6849e213 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -177,7 +177,7 @@ def update_completed_qty(bean, method): for mr_name, mr_items in material_request_map.items(): mr_obj = frappe.get_obj("Material Request", mr_name, with_children=1) - mr_doctype = frappe.get_doctype("Material Request") + mr_doctype = frappe.get_meta("Material Request") if mr_obj.doc.status in ["Stopped", "Cancelled"]: frappe.throw(_("Material Request") + ": %s, " % mr_obj.doc.name diff --git a/erpnext/stock/doctype/price_list/price_list.py b/erpnext/stock/doctype/price_list/price_list.py index 420c6c5ffc7..bf49a519940 100644 --- a/erpnext/stock/doctype/price_list/price_list.py +++ b/erpnext/stock/doctype/price_list/price_list.py @@ -16,9 +16,8 @@ class PriceList(DocListController): if not self.get("valid_for_territories"): # if no territory, set default territory if frappe.defaults.get_user_default("territory"): - self.doclist.append({ + self.append("valid_for_territories", { "doctype": "Applicable Territory", - "parentfield": "valid_for_territories", "territory": frappe.defaults.get_user_default("territory") }) else: diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index d8bdb77142d..50b1d00406c 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -254,7 +254,7 @@ def validate_serial_no(sle, item_det): def update_serial_nos(sle, item_det): if sle.is_cancelled == "No" and not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series: - from frappe.model.doc import make_autoname + from frappe.model.naming import make_autoname serial_nos = [] for i in xrange(cint(sle.actual_qty)): serial_nos.append(make_autoname(item_det.serial_no_series)) diff --git a/erpnext/stock/doctype/stock_ledger/stock_ledger.py b/erpnext/stock/doctype/stock_ledger/stock_ledger.py index 452ad358799..966e7ab656b 100644 --- a/erpnext/stock/doctype/stock_ledger/stock_ledger.py +++ b/erpnext/stock/doctype/stock_ledger/stock_ledger.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe.utils import add_days, cstr, flt, nowdate, cint, now -from frappe.model.doc import Document from frappe.model.bean import getlist from frappe.model.code import get_obj from frappe import session, msgprint diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 8bfc0836298..3cd49d94b38 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -158,7 +158,7 @@ def get_basic_details(args, item_bean): return out def get_price_list_rate(args, item_bean, out): - meta = frappe.get_doctype(args.doctype) + meta = frappe.get_meta(args.doctype) if meta.get_field("currency"): validate_price_list(args) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 822c8f288d4..4628b5b221f 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -116,7 +116,7 @@ def update_entries_after(args, verbose=1): # rounding as per precision from frappe.model.meta import get_field_precision - meta = frappe.get_doctype("Stock Ledger Entry") + meta = frappe.get_meta("Stock Ledger Entry") stock_value = flt(stock_value, get_field_precision(meta.get_field("stock_value"), frappe._dict({"fields": sle}))) diff --git a/erpnext/support/doctype/support_email_settings/support_email_settings.py b/erpnext/support/doctype/support_email_settings/support_email_settings.py index 65edf23940e..011a94368c0 100644 --- a/erpnext/support/doctype/support_email_settings/support_email_settings.py +++ b/erpnext/support/doctype/support_email_settings/support_email_settings.py @@ -16,11 +16,10 @@ class SupportEmailSettings(Document): """ if self.doc.sync_support_mails and self.doc.mail_server: from frappe.utils.email_lib.receive import POP3Mailbox - from frappe.model.doc import Document - import _socket, poplib + import _socket, poplib - inc_email = Document('Incoming Email Settings') - inc_email.encode() + inc_email = frappe.get_doc('Incoming Email Settings') + # inc_email.encode() inc_email.host = self.doc.mail_server inc_email.use_ssl = self.doc.use_ssl try: diff --git a/erpnext/utilities/doctype/address/address.py b/erpnext/utilities/doctype/address/address.py index b698658eace..778451b0736 100644 --- a/erpnext/utilities/doctype/address/address.py +++ b/erpnext/utilities/doctype/address/address.py @@ -56,7 +56,7 @@ def get_address_display(address_dict): if not isinstance(address_dict, dict): address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {} - meta = frappe.get_doctype("Address") + meta = frappe.get_meta("Address") sequence = (("", "address_line1"), ("\n", "address_line2"), ("\n", "city"), diff --git a/erpnext/utilities/doctype/sms_control/sms_control.py b/erpnext/utilities/doctype/sms_control/sms_control.py index b160ad9139e..3a23558573c 100644 --- a/erpnext/utilities/doctype/sms_control/sms_control.py +++ b/erpnext/utilities/doctype/sms_control/sms_control.py @@ -6,7 +6,6 @@ import frappe, json from frappe.utils import nowdate, cstr from frappe.model.code import get_obj -from frappe.model.doc import Document from frappe import msgprint, throw, _ from frappe.model.bean import getlist @@ -109,11 +108,11 @@ class SmsControl(Document): # Create SMS Log # ========================================================= def create_sms_log(self, arg, sent_sms): - sl = Document('SMS Log') + sl = frappe.get_doc('SMS Log') sl.sender_name = arg['sender_name'] sl.sent_on = nowdate() sl.receiver_list = cstr(arg['receiver_list']) sl.message = arg['message'] sl.no_of_requested_sms = len(arg['receiver_list']) sl.no_of_sent_sms = sent_sms - sl.save(new=1) + sl.save() diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 11dfc5252b0..ee78cede9a4 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -36,7 +36,7 @@ class TransactionBase(StatusUpdater): opts = frappe._dict(opts) if self.doc.contact_date: - event_doclist = [{ + event_doclist = frappe.get_doc({ "doctype": "Event", "owner": opts.owner or self.doc.owner, "subject": opts.subject, @@ -45,16 +45,15 @@ class TransactionBase(StatusUpdater): "event_type": "Private", "ref_type": self.doc.doctype, "ref_name": self.doc.name - }] + }) if frappe.db.exists("User", self.doc.contact_by): - event_doclist.append({ + event_doclist.append("event_individuals", { "doctype": "Event User", - "parentfield": "event_individuals", "person": self.doc.contact_by }) - frappe.bean(event_doclist).insert() + event_doclist.insert() def validate_uom_is_integer(self, uom_field, qty_fields): validate_uom_is_integer(self.doclist, uom_field, qty_fields)