Merge branch 'model-cleanup' of github.com:frappe/erpnext into model-cleanup
This commit is contained in:
commit
c10213d861
@ -9,29 +9,29 @@ def _make_test_records(verbose):
|
||||
|
||||
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 @@ def _make_test_records(verbose):
|
||||
"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
|
@ -26,14 +26,14 @@ class ShippingRule(DocListController):
|
||||
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 +
|
||||
|
@ -5,6 +5,8 @@ import frappe
|
||||
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 @@ class TestShippingRule(unittest.TestCase):
|
||||
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')
|
||||
self.assertRaises(OverlappingConditionError, shipping_rule.insert)
|
@ -25,13 +25,12 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
||||
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 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
||||
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 @@ def set_other_values(out, party, party_type):
|
||||
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 @@ def set_price_list(out, party, given_price_list):
|
||||
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")
|
||||
|
||||
|
@ -81,7 +81,7 @@ class PurchaseCommon(BuyingController):
|
||||
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 @@ class PurchaseCommon(BuyingController):
|
||||
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)
|
||||
|
||||
|
@ -73,7 +73,7 @@ class PurchaseOrder(BuyingController):
|
||||
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)
|
||||
|
||||
|
@ -93,7 +93,7 @@ class AccountsController(TransactionBase):
|
||||
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)
|
||||
|
||||
|
@ -17,7 +17,7 @@ class BuyingController(StockController):
|
||||
|
||||
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 @@ class BuyingController(StockController):
|
||||
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()
|
||||
|
@ -35,7 +35,7 @@ class SellingController(StockController):
|
||||
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 @@ def check_active_sales_items(obj):
|
||||
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)
|
||||
|
@ -223,11 +223,11 @@ class StockController(AccountsController):
|
||||
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)
|
||||
|
||||
|
@ -384,7 +384,7 @@ class BOM(Document):
|
||||
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:
|
||||
|
@ -6,5 +6,5 @@ import frappe
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class BomExplosionItem(Document):
|
||||
class BOMExplosionItem(Document):
|
||||
pass
|
@ -6,5 +6,5 @@ import frappe
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class SalesBomItem(Document):
|
||||
class SalesBOMItem(Document):
|
||||
pass
|
@ -6,5 +6,5 @@ import frappe
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class TermsAndConditions(Document):
|
||||
class TermsandConditions(Document):
|
||||
pass
|
@ -80,7 +80,7 @@ class DeliveryNote(SellingController):
|
||||
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],
|
||||
|
@ -68,7 +68,7 @@ class MaterialRequest(BuyingController):
|
||||
|
||||
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()
|
||||
|
@ -216,7 +216,7 @@ class PurchaseReceipt(BuyingController):
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user