frappe/frappe#478 fixes
This commit is contained in:
parent
99f914b782
commit
365ae27acf
@ -9,29 +9,29 @@ def _make_test_records(verbose):
|
|||||||
|
|
||||||
accounts = [
|
accounts = [
|
||||||
# [account_name, parent_account, group_or_ledger]
|
# [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 Stock Expenses", "Direct Expenses", "Group", None],
|
||||||
["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger"],
|
["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger", "Chargeable"],
|
||||||
["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger"],
|
["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger", "Tax"],
|
||||||
|
|
||||||
|
|
||||||
["_Test Account Tax Assets", "Current Assets", "Group"],
|
["_Test Account Tax Assets", "Current Assets", "Group", None],
|
||||||
["_Test Account VAT", "_Test Account Tax Assets", "Ledger"],
|
["_Test Account VAT", "_Test Account Tax Assets", "Ledger", "Tax"],
|
||||||
["_Test Account Service Tax", "_Test Account Tax Assets", "Ledger"],
|
["_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 Cost for Goods Sold", "Expenses", "Ledger", None],
|
||||||
["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger"],
|
["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger", "Tax"],
|
||||||
["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger"],
|
["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"],
|
||||||
["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger"],
|
["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"],
|
||||||
["_Test Account CST", "Direct Expenses", "Ledger"],
|
["_Test Account CST", "Direct Expenses", "Ledger", "Tax"],
|
||||||
["_Test Account Discount", "Direct Expenses", "Ledger"],
|
["_Test Account Discount", "Direct Expenses", "Ledger", None],
|
||||||
|
|
||||||
# related to Account Inventory Integration
|
# related to Account Inventory Integration
|
||||||
["_Test Account Stock In Hand", "Current Assets", "Ledger"],
|
["_Test Account Stock In Hand", "Current Assets", "Ledger", None],
|
||||||
["_Test Account Fixed Assets", "Current Assets", "Ledger"],
|
["_Test Account Fixed Assets", "Current Assets", "Ledger", None],
|
||||||
]
|
]
|
||||||
|
|
||||||
for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]:
|
for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]:
|
||||||
@ -40,7 +40,8 @@ def _make_test_records(verbose):
|
|||||||
"account_name": account_name,
|
"account_name": account_name,
|
||||||
"parent_account": parent_account + " - " + abbr,
|
"parent_account": parent_account + " - " + abbr,
|
||||||
"company": company,
|
"company": company,
|
||||||
"group_or_ledger": group_or_ledger
|
"group_or_ledger": group_or_ledger,
|
||||||
} for account_name, parent_account, group_or_ledger in accounts])
|
"account_type": account_type
|
||||||
|
} for account_name, parent_account, group_or_ledger, account_type in accounts])
|
||||||
|
|
||||||
return test_objects
|
return test_objects
|
@ -26,14 +26,14 @@ class ShippingRule(DocListController):
|
|||||||
def validate_from_to_values(self):
|
def validate_from_to_values(self):
|
||||||
zero_to_values = []
|
zero_to_values = []
|
||||||
|
|
||||||
for d in self.shipping_rule_conditions:
|
for d in self.get("shipping_rule_conditions"):
|
||||||
self.round_floats_in(d)
|
self.round_floats_in(d)
|
||||||
|
|
||||||
# values cannot be negative
|
# values cannot be negative
|
||||||
self.validate_value("from_value", ">=", 0.0, d)
|
self.validate_value("from_value", ">=", 0.0, d)
|
||||||
self.validate_value("to_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)
|
zero_to_values.append(d)
|
||||||
elif d.from_value >= d.to_value:
|
elif d.from_value >= d.to_value:
|
||||||
msgprint(_("Error") + ": " + _("Row") + " # %d: " % d.idx +
|
msgprint(_("Error") + ": " + _("Row") + " # %d: " % d.idx +
|
||||||
|
@ -5,6 +5,8 @@ import frappe
|
|||||||
import unittest
|
import unittest
|
||||||
from erpnext.accounts.doctype.shipping_rule.shipping_rule import FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError
|
from erpnext.accounts.doctype.shipping_rule.shipping_rule import FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError
|
||||||
|
|
||||||
|
test_records = frappe.get_test_records('Shipping Rule')
|
||||||
|
|
||||||
class TestShippingRule(unittest.TestCase):
|
class TestShippingRule(unittest.TestCase):
|
||||||
def test_from_greater_than_to(self):
|
def test_from_greater_than_to(self):
|
||||||
shipping_rule = frappe.copy_doc(test_records[0])
|
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[1].to_value = range_a[1]
|
||||||
shipping_rule.doclist[2].from_value = range_b[0]
|
shipping_rule.doclist[2].from_value = range_b[0]
|
||||||
shipping_rule.doclist[2].to_value = range_b[1]
|
shipping_rule.doclist[2].to_value = range_b[1]
|
||||||
self.assertRaises(OverlappingConditionError, shipping_rule.insert)
|
self.assertRaises(OverlappingConditionError, shipping_rule.insert)
|
||||||
|
|
||||||
test_records = frappe.get_test_records('Shipping Rule')
|
|
@ -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):
|
if not ignore_permissions and not frappe.has_permission(party_type, "read", party):
|
||||||
frappe.throw("Not Permitted", frappe.PermissionError)
|
frappe.throw("Not Permitted", frappe.PermissionError)
|
||||||
|
|
||||||
party_doc = frappe.get_doc(party_type, party)
|
party = frappe.get_doc(party_type, party)
|
||||||
party = party_doc
|
|
||||||
|
|
||||||
set_address_details(out, party, party_type)
|
set_address_details(out, party, party_type)
|
||||||
set_contact_details(out, party, party_type)
|
set_contact_details(out, party, party_type)
|
||||||
set_other_values(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"):
|
if not out.get("currency"):
|
||||||
out["currency"] = currency
|
out["currency"] = currency
|
||||||
@ -41,7 +40,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
|||||||
out["sales_team"] = [{
|
out["sales_team"] = [{
|
||||||
"sales_person": d.sales_person,
|
"sales_person": d.sales_person,
|
||||||
"sales_designation": d.sales_designation
|
"sales_designation": d.sales_designation
|
||||||
} for d in party_doc.get("sales_team")]
|
} for d in party.get("sales_team")]
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ def set_other_values(out, party, party_type):
|
|||||||
if party.get("default_" + f):
|
if party.get("default_" + f):
|
||||||
out[f] = 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
|
||||||
price_list = get_restrictions().get("Price List")
|
price_list = get_restrictions().get("Price List")
|
||||||
if isinstance(price_list, list):
|
if isinstance(price_list, list):
|
||||||
@ -90,7 +89,7 @@ def set_price_list(out, party, given_price_list):
|
|||||||
if not price_list:
|
if not price_list:
|
||||||
price_list = party.default_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",
|
price_list = frappe.db.get_value("Customer Group",
|
||||||
party.customer_group, "default_price_list")
|
party.customer_group, "default_price_list")
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class PurchaseCommon(BuyingController):
|
|||||||
if d.doctype == 'Purchase Receipt Item':
|
if d.doctype == 'Purchase Receipt Item':
|
||||||
f_lst.pop('received_qty')
|
f_lst.pop('received_qty')
|
||||||
for x in f_lst :
|
for x in f_lst :
|
||||||
if d.meta.has_field(x):
|
if d.meta.get_field(x):
|
||||||
d.set(x, f_lst[x])
|
d.set(x, f_lst[x])
|
||||||
|
|
||||||
item = frappe.db.sql("""select is_stock_item, is_purchase_item,
|
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))
|
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
|
# list criteria that should not repeat if item is stock item
|
||||||
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom,
|
e = [getattr(d, "schedule_date", None), 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.get_field('prevdoc_docname') and d.prevdoc_docname or d.meta.get_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.get_field('prevdoc_detail_docname') and d.prevdoc_detail_docname or '',
|
||||||
d.meta.has_field('batch_no') and d.batch_no or '']
|
d.meta.get_field('batch_no') and d.batch_no or '']
|
||||||
|
|
||||||
# if is not stock item
|
# 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)
|
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):
|
def check_for_stopped_status(self, pc_obj):
|
||||||
check_list =[]
|
check_list =[]
|
||||||
for d in self.get('po_details'):
|
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)
|
check_list.append(d.prevdoc_docname)
|
||||||
pc_obj.check_for_stopped_status( d.prevdoc_doctype, 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())
|
args.update(self.as_dict())
|
||||||
ret = get_item_details(args)
|
ret = get_item_details(args)
|
||||||
for fieldname, value in ret.items():
|
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.get(fieldname) is None and value is not None:
|
||||||
item.set(fieldname, value)
|
item.set(fieldname, value)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class BuyingController(StockController):
|
|||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(BuyingController, self).validate()
|
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_name = frappe.db.get_value("Supplier",
|
||||||
self.supplier, "supplier_name")
|
self.supplier, "supplier_name")
|
||||||
self.is_item_table_empty()
|
self.is_item_table_empty()
|
||||||
@ -31,7 +31,7 @@ class BuyingController(StockController):
|
|||||||
self.set_price_list_currency("Buying")
|
self.set_price_list_currency("Buying")
|
||||||
|
|
||||||
# set contact and address details for supplier, if they are not mentioned
|
# 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.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))
|
||||||
|
|
||||||
self.set_missing_item_details()
|
self.set_missing_item_details()
|
||||||
|
@ -35,7 +35,7 @@ class SellingController(StockController):
|
|||||||
if getattr(self, "customer", None):
|
if getattr(self, "customer", None):
|
||||||
from erpnext.accounts.party import _get_party_details
|
from erpnext.accounts.party import _get_party_details
|
||||||
self.update_if_missing(_get_party_details(self.customer,
|
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):
|
elif getattr(self, "lead", None):
|
||||||
from erpnext.selling.doctype.lead.lead import get_lead_details
|
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]
|
d.item_code, as_dict=True)[0]
|
||||||
if item.is_sales_item == 'No' and item.is_service_item == 'No':
|
if item.is_sales_item == 'No' and item.is_service_item == 'No':
|
||||||
frappe.throw(_("Item is neither Sales nor Service Item") + ": " + d.item_code)
|
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",
|
frappe.db.set_value("Item", d.item_code, "income_account",
|
||||||
d.income_account)
|
d.income_account)
|
||||||
|
@ -223,11 +223,11 @@ class StockController(AccountsController):
|
|||||||
make_gl_entries(gl_entries)
|
make_gl_entries(gl_entries)
|
||||||
|
|
||||||
def check_expense_account(self, item):
|
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,
|
msgprint(_("""Expense/Difference account is mandatory for item: """) + item.item_code,
|
||||||
raise_exception=1)
|
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,
|
msgprint(_("""Cost Center is mandatory for item: """) + item.item_code,
|
||||||
raise_exception=1)
|
raise_exception=1)
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ class BOM(Document):
|
|||||||
ch.amount = flt(ch.qty) * flt(ch.rate)
|
ch.amount = flt(ch.qty) * flt(ch.rate)
|
||||||
ch.qty_consumed_per_unit = flt(ch.qty) / flt(self.quantity)
|
ch.qty_consumed_per_unit = flt(ch.qty) / flt(self.quantity)
|
||||||
ch.docstatus = self.docstatus
|
ch.docstatus = self.docstatus
|
||||||
ch.save(1)
|
ch.db_update()
|
||||||
|
|
||||||
def validate_bom_links(self):
|
def validate_bom_links(self):
|
||||||
if not self.is_active:
|
if not self.is_active:
|
||||||
|
@ -6,5 +6,5 @@ import frappe
|
|||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class BomExplosionItem(Document):
|
class BOMExplosionItem(Document):
|
||||||
pass
|
pass
|
@ -6,5 +6,5 @@ import frappe
|
|||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class SalesBomItem(Document):
|
class SalesBOMItem(Document):
|
||||||
pass
|
pass
|
@ -6,5 +6,5 @@ import frappe
|
|||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class TermsAndConditions(Document):
|
class TermsandConditions(Document):
|
||||||
pass
|
pass
|
@ -80,7 +80,7 @@ class DeliveryNote(SellingController):
|
|||||||
items = self.get("delivery_note_details")
|
items = self.get("delivery_note_details")
|
||||||
|
|
||||||
for fn in (("Sales Order", "against_sales_order"), ("Sales Invoice", "against_sales_invoice")):
|
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, {
|
super(DeliveryNote, self).validate_with_previous_doc(self.tname, {
|
||||||
fn[0]: {
|
fn[0]: {
|
||||||
"ref_dn_field": fn[1],
|
"ref_dn_field": fn[1],
|
||||||
|
@ -68,7 +68,7 @@ class MaterialRequest(BuyingController):
|
|||||||
|
|
||||||
self.validate_value("material_request_type", "in", ["Purchase", "Transfer"])
|
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)
|
pc_obj.validate_for_items(self)
|
||||||
|
|
||||||
# self.validate_qty_against_so()
|
# self.validate_qty_against_so()
|
||||||
|
@ -216,7 +216,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
def check_for_stopped_status(self, pc_obj):
|
def check_for_stopped_status(self, pc_obj):
|
||||||
check_list =[]
|
check_list =[]
|
||||||
for d in self.get('purchase_receipt_details'):
|
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)
|
check_list.append(d.prevdoc_docname)
|
||||||
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)
|
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user