Merge branch 'model-cleanup' of github.com:frappe/erpnext into model-cleanup
diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py
index 5cecab4..3774629 100644
--- a/erpnext/accounts/doctype/account/test_account.py
+++ b/erpnext/accounts/doctype/account/test_account.py
@@ -9,29 +9,29 @@
accounts = [
# [account_name, parent_account, group_or_ledger]
- ["_Test Account Bank Account", "Bank Accounts", "Ledger"],
+ ["_Test Account Bank Account", "Bank Accounts", "Ledger", "Bank"],
- ["_Test Account Stock Expenses", "Direct Expenses", "Group"],
- ["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger"],
- ["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger"],
+ ["_Test Account Stock Expenses", "Direct Expenses", "Group", None],
+ ["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger", "Chargeable"],
+ ["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger", "Tax"],
- ["_Test Account Tax Assets", "Current Assets", "Group"],
- ["_Test Account VAT", "_Test Account Tax Assets", "Ledger"],
- ["_Test Account Service Tax", "_Test Account Tax Assets", "Ledger"],
+ ["_Test Account Tax Assets", "Current Assets", "Group", None],
+ ["_Test Account VAT", "_Test Account Tax Assets", "Ledger", "Tax"],
+ ["_Test Account Service Tax", "_Test Account Tax Assets", "Ledger", "Tax"],
- ["_Test Account Reserves and Surplus", "Current Liabilities", "Ledger"],
+ ["_Test Account Reserves and Surplus", "Current Liabilities", "Ledger", None],
- ["_Test Account Cost for Goods Sold", "Expenses", "Ledger"],
- ["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger"],
- ["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger"],
- ["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger"],
- ["_Test Account CST", "Direct Expenses", "Ledger"],
- ["_Test Account Discount", "Direct Expenses", "Ledger"],
+ ["_Test Account Cost for Goods Sold", "Expenses", "Ledger", None],
+ ["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger", "Tax"],
+ ["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"],
+ ["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"],
+ ["_Test Account CST", "Direct Expenses", "Ledger", "Tax"],
+ ["_Test Account Discount", "Direct Expenses", "Ledger", None],
# related to Account Inventory Integration
- ["_Test Account Stock In Hand", "Current Assets", "Ledger"],
- ["_Test Account Fixed Assets", "Current Assets", "Ledger"],
+ ["_Test Account Stock In Hand", "Current Assets", "Ledger", None],
+ ["_Test Account Fixed Assets", "Current Assets", "Ledger", None],
]
for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]:
@@ -40,7 +40,8 @@
"account_name": account_name,
"parent_account": parent_account + " - " + abbr,
"company": company,
- "group_or_ledger": group_or_ledger
- } for account_name, parent_account, group_or_ledger in accounts])
+ "group_or_ledger": group_or_ledger,
+ "account_type": account_type
+ } for account_name, parent_account, group_or_ledger, account_type in accounts])
return test_objects
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
index 9e88f22..3cef992 100644
--- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
+++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
@@ -26,14 +26,14 @@
def validate_from_to_values(self):
zero_to_values = []
- for d in self.shipping_rule_conditions:
+ for d in self.get("shipping_rule_conditions"):
self.round_floats_in(d)
# values cannot be negative
self.validate_value("from_value", ">=", 0.0, d)
self.validate_value("to_value", ">=", 0.0, d)
- if d.to_value == 0:
+ if not d.to_value:
zero_to_values.append(d)
elif d.from_value >= d.to_value:
msgprint(_("Error") + ": " + _("Row") + " # %d: " % d.idx +
diff --git a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py
index 0f41a56..9fee555 100644
--- a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py
+++ b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py
@@ -5,6 +5,8 @@
import unittest
from erpnext.accounts.doctype.shipping_rule.shipping_rule import FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError
+test_records = frappe.get_test_records('Shipping Rule')
+
class TestShippingRule(unittest.TestCase):
def test_from_greater_than_to(self):
shipping_rule = frappe.copy_doc(test_records[0])
@@ -29,6 +31,4 @@
shipping_rule.doclist[1].to_value = range_a[1]
shipping_rule.doclist[2].from_value = range_b[0]
shipping_rule.doclist[2].to_value = range_b[1]
- self.assertRaises(OverlappingConditionError, shipping_rule.insert)
-
-test_records = frappe.get_test_records('Shipping Rule')
\ No newline at end of file
+ self.assertRaises(OverlappingConditionError, shipping_rule.insert)
\ No newline at end of file
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index a159a73..601fcd1 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -25,13 +25,12 @@
if not ignore_permissions and not frappe.has_permission(party_type, "read", party):
frappe.throw("Not Permitted", frappe.PermissionError)
- party_doc = frappe.get_doc(party_type, party)
- party = party_doc
+ party = frappe.get_doc(party_type, party)
set_address_details(out, party, party_type)
set_contact_details(out, party, party_type)
set_other_values(out, party, party_type)
- set_price_list(out, party, price_list)
+ set_price_list(out, party, party_type, price_list)
if not out.get("currency"):
out["currency"] = currency
@@ -41,7 +40,7 @@
out["sales_team"] = [{
"sales_person": d.sales_person,
"sales_designation": d.sales_designation
- } for d in party_doc.get("sales_team")]
+ } for d in party.get("sales_team")]
return out
@@ -81,7 +80,7 @@
if party.get("default_" + f):
out[f] = party.get("default_" + f)
-def set_price_list(out, party, given_price_list):
+def set_price_list(out, party, party_type, given_price_list):
# price list
price_list = get_restrictions().get("Price List")
if isinstance(price_list, list):
@@ -90,7 +89,7 @@
if not price_list:
price_list = party.default_price_list
- if not price_list and party.party_type=="Customer":
+ if not price_list and party_type=="Customer":
price_list = frappe.db.get_value("Customer Group",
party.customer_group, "default_price_list")
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py
index 80af450..ffbbb45 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.py
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.py
@@ -81,7 +81,7 @@
if d.doctype == 'Purchase Receipt Item':
f_lst.pop('received_qty')
for x in f_lst :
- if d.meta.has_field(x):
+ if d.meta.get_field(x):
d.set(x, f_lst[x])
item = frappe.db.sql("""select is_stock_item, is_purchase_item,
@@ -101,13 +101,13 @@
frappe.throw("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code))
# list criteria that should not repeat if item is stock item
- e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom,
- d.meta.has_field('prevdoc_docname') and d.prevdoc_docname or d.meta.has_field('sales_order_no') and d.sales_order_no or '',
- d.meta.has_field('prevdoc_detail_docname') and d.prevdoc_detail_docname or '',
- d.meta.has_field('batch_no') and d.batch_no or '']
+ e = [getattr(d, "schedule_date", None), d.item_code, d.description, d.warehouse, d.uom,
+ d.meta.get_field('prevdoc_docname') and d.prevdoc_docname or d.meta.get_field('sales_order_no') and d.sales_order_no or '',
+ d.meta.get_field('prevdoc_detail_docname') and d.prevdoc_detail_docname or '',
+ d.meta.get_field('batch_no') and d.batch_no or '']
# if is not stock item
- f = [d.schedule_date, d.item_code, d.description]
+ f = [getattr(d, "schedule_date", None), d.item_code, d.description]
ch = frappe.db.sql("""select is_stock_item from `tabItem` where name = %s""", d.item_code)
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index afa9748..e7bb7c9 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -73,7 +73,7 @@
def check_for_stopped_status(self, pc_obj):
check_list =[]
for d in self.get('po_details'):
- if d.meta.has_field('prevdoc_docname') and d.prevdoc_docname and d.prevdoc_docname not in check_list:
+ if d.meta.get_field('prevdoc_docname') and d.prevdoc_docname and d.prevdoc_docname not in check_list:
check_list.append(d.prevdoc_docname)
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 1b050d7..0b1c001 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -93,7 +93,7 @@
args.update(self.as_dict())
ret = get_item_details(args)
for fieldname, value in ret.items():
- if self.meta.get_field(fieldname, parentfield=self.fname) and \
+ if item.meta.get_field(fieldname) and \
item.get(fieldname) is None and value is not None:
item.set(fieldname, value)
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 24dce4b..6e03d47 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -17,7 +17,7 @@
def validate(self):
super(BuyingController, self).validate()
- if self.supplier and not self.supplier_name:
+ if getattr(self, "supplier", None) and not self.supplier_name:
self.supplier_name = frappe.db.get_value("Supplier",
self.supplier, "supplier_name")
self.is_item_table_empty()
@@ -31,7 +31,7 @@
self.set_price_list_currency("Buying")
# set contact and address details for supplier, if they are not mentioned
- if self.supplier:
+ if getattr(self, "supplier", None):
self.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))
self.set_missing_item_details()
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index bcc46bb..da37adb 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -35,7 +35,7 @@
if getattr(self, "customer", None):
from erpnext.accounts.party import _get_party_details
self.update_if_missing(_get_party_details(self.customer,
- ignore_permissions=self.ignore_permissions))
+ ignore_permissions=getattr(self, "ignore_permissions", None)))
elif getattr(self, "lead", None):
from erpnext.selling.doctype.lead.lead import get_lead_details
@@ -377,6 +377,6 @@
d.item_code, as_dict=True)[0]
if item.is_sales_item == 'No' and item.is_service_item == 'No':
frappe.throw(_("Item is neither Sales nor Service Item") + ": " + d.item_code)
- if d.income_account and not item.income_account:
+ if getattr(d, "income_account", None) and not item.income_account:
frappe.db.set_value("Item", d.item_code, "income_account",
d.income_account)
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index e00449d..62262ee 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -223,11 +223,11 @@
make_gl_entries(gl_entries)
def check_expense_account(self, item):
- if item.meta.has_field("expense_account") and not item.expense_account:
+ if item.meta.get_field("expense_account") and not item.expense_account:
msgprint(_("""Expense/Difference account is mandatory for item: """) + item.item_code,
raise_exception=1)
- if item.meta.has_field("expense_account") and not item.cost_center:
+ if item.meta.get_field("expense_account") and not item.cost_center:
msgprint(_("""Cost Center is mandatory for item: """) + item.item_code,
raise_exception=1)
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index b507226..7dcc96e 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -384,7 +384,7 @@
ch.amount = flt(ch.qty) * flt(ch.rate)
ch.qty_consumed_per_unit = flt(ch.qty) / flt(self.quantity)
ch.docstatus = self.docstatus
- ch.save(1)
+ ch.db_update()
def validate_bom_links(self):
if not self.is_active:
diff --git a/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.py b/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.py
index bd1b1af..48ea3c0 100644
--- a/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.py
+++ b/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.py
@@ -6,5 +6,5 @@
from frappe.model.document import Document
-class BomExplosionItem(Document):
+class BOMExplosionItem(Document):
pass
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_bom_item/sales_bom_item.py b/erpnext/selling/doctype/sales_bom_item/sales_bom_item.py
index e1124d9..9a98c39 100644
--- a/erpnext/selling/doctype/sales_bom_item/sales_bom_item.py
+++ b/erpnext/selling/doctype/sales_bom_item/sales_bom_item.py
@@ -6,5 +6,5 @@
from frappe.model.document import Document
-class SalesBomItem(Document):
+class SalesBOMItem(Document):
pass
\ No newline at end of file
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
index 73ac394..be538a7 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
@@ -6,5 +6,5 @@
from frappe.model.document import Document
-class TermsAndConditions(Document):
+class TermsandConditions(Document):
pass
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 8dcdde1..b990063 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -80,7 +80,7 @@
items = self.get("delivery_note_details")
for fn in (("Sales Order", "against_sales_order"), ("Sales Invoice", "against_sales_invoice")):
- if filter(None, [(d[fn[1]] or None) for d in self.get(self.fname)]):
+ if filter(None, [getattr(d, fn[1], None) for d in items]):
super(DeliveryNote, self).validate_with_previous_doc(self.tname, {
fn[0]: {
"ref_dn_field": fn[1],
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 1cabce7..5a5bb03 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -68,7 +68,7 @@
self.validate_value("material_request_type", "in", ["Purchase", "Transfer"])
- pc_obj = frappe.get_doc(dt='Purchase Common')
+ pc_obj = frappe.get_doc('Purchase Common')
pc_obj.validate_for_items(self)
# self.validate_qty_against_so()
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 59b9c98..1ac5826 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -216,7 +216,7 @@
def check_for_stopped_status(self, pc_obj):
check_list =[]
for d in self.get('purchase_receipt_details'):
- if d.meta.has_field('prevdoc_docname') and d.prevdoc_docname and d.prevdoc_docname not in check_list:
+ if d.meta.get_field('prevdoc_docname') and d.prevdoc_docname and d.prevdoc_docname not in check_list:
check_list.append(d.prevdoc_docname)
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)