Merge branch 'shreyasp-disable_cust_supp' into develop

This commit is contained in:
Anand Doshi 2016-01-26 16:41:11 +05:30
commit 5b1b2fb858
9 changed files with 760 additions and 671 deletions

View File

@ -6,10 +6,10 @@ import frappe
from frappe import _
from frappe.utils import flt, fmt_money, getdate, formatdate
from frappe.model.document import Document
from erpnext.accounts.party import validate_party_gle_currency
from erpnext.accounts.party import validate_party_gle_currency, validate_party_frozen_disabled
from erpnext.accounts.utils import get_account_currency
from erpnext.setup.doctype.company.company import get_company_currency
from erpnext.exceptions import InvalidAccountCurrency, CustomerFrozen
from erpnext.exceptions import InvalidAccountCurrency
exclude_from_linked_with = True
@ -96,11 +96,7 @@ class GLEntry(Document):
frappe.throw(_("Cost Center {0} does not belong to Company {1}").format(self.cost_center, self.company))
def validate_party(self):
if self.party_type and self.party:
frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
if not frozen_accounts_modifier in frappe.get_roles():
if frappe.db.get_value(self.party_type, self.party, "is_frozen"):
frappe.throw("{0} {1} is frozen".format(self.party_type, self.party), CustomerFrozen)
validate_party_frozen_disabled(self.party_type, self.party)
def validate_currency(self):
company_currency = get_company_currency(self.company)

View File

@ -10,7 +10,7 @@ from frappe.defaults import get_user_permissions
from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff
from erpnext.utilities.doctype.address.address import get_address_display
from erpnext.utilities.doctype.contact.contact import get_contact_details
from erpnext.exceptions import InvalidAccountCurrency
from erpnext.exceptions import PartyFrozen, InvalidCurrency, PartyDisabled, InvalidAccountCurrency
class DuplicatePartyAccountError(frappe.ValidationError): pass
@ -308,3 +308,13 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup
args.update({"use_for_shopping_cart": use_for_shopping_cart})
return get_tax_template(posting_date, args)
def validate_party_frozen_disabled(party_type, party_name):
if party_type and party_name:
party = frappe.db.get_value(party_type, party_name, ["is_frozen", "disabled"], as_dict=True)
if party.disabled:
frappe.throw("{0} {1} is disabled".format(party_type, party_name), PartyDisabled)
elif party.is_frozen:
frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
if not frozen_accounts_modifier in frappe.get_roles():
frappe.throw("{0} {1} is frozen".format(party_type, party_name), PartyFrozen)

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,11 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import unittest
import frappe, unittest
from erpnext.accounts.party import get_due_date
from erpnext.exceptions import PartyFrozen, PartyDisabled
from frappe.test_runner import make_test_records
test_records = frappe.get_test_records('Supplier')
@ -52,3 +54,19 @@ class TestSupplier(unittest.TestCase):
# Non Leap year
due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier", "_Test Company")
self.assertEqual(due_date, "2017-02-28")
def test_supplier_disabled(self):
make_test_records("Item")
frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 1)
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
po = create_purchase_order(do_not_save=True)
self.assertRaises(PartyDisabled, po.save)
frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 0)
po.save()

View File

@ -10,8 +10,8 @@ from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year, get_ac
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.controllers.recurring_document import convert_to_recurring, validate_recurring_document
from erpnext.controllers.sales_and_purchase_return import validate_return
from erpnext.accounts.party import get_party_account_currency
from erpnext.exceptions import CustomerFrozen, InvalidCurrency
from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled
from erpnext.exceptions import InvalidCurrency
force_item_fields = ("item_group", "barcode", "brand", "stock_uom")
@ -416,24 +416,23 @@ class AccountsController(TransactionBase):
return self._abbr
def validate_party(self):
frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
if frozen_accounts_modifier in frappe.get_roles():
return
party_type, party = self.get_party()
if party_type:
if frappe.db.get_value(party_type, party, "is_frozen"):
frappe.throw("{0} {1} is frozen".format(party_type, party), CustomerFrozen)
validate_party_frozen_disabled(party_type, party)
def get_party(self):
party_type = None
if self.meta.get_field("customer"):
if self.doctype in ("Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"):
party_type = 'Customer'
elif self.meta.get_field("supplier"):
elif self.doctype in ("Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"):
party_type = 'Supplier'
elif self.meta.get_field("customer"):
party_type = "Customer"
elif self.meta.get_field("supplier"):
party_type = "Supplier"
party = self.get(party_type.lower()) if party_type else None
return party_type, party
@ -451,7 +450,9 @@ class AccountsController(TransactionBase):
frappe.throw(_("Accounting Entry for {0}: {1} can only be made in currency: {2}")
.format(party_type, party, party_account_currency), InvalidCurrency)
# Note: not validating with gle account because we don't have the account at quotation / sales order level and we shouldn't stop someone from creating a sales invoice if sales order is already created
# Note: not validating with gle account because we don't have the account
# at quotation / sales order level and we shouldn't stop someone
# from creating a sales invoice if sales order is already created
@frappe.whitelist()
def get_tax_rate(account_head):

View File

@ -89,7 +89,7 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""select {fields} from `tabCustomer`
where docstatus < 2
and ({key} like %(txt)s
or customer_name like %(txt)s)
or customer_name like %(txt)s) and disabled=0
{mcond}
order by
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
@ -118,7 +118,7 @@ def supplier_query(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""select {field} from `tabSupplier`
where docstatus < 2
and ({key} like %(txt)s
or supplier_name like %(txt)s)
or supplier_name like %(txt)s) and disabled=0
{mcond}
order by
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
@ -216,12 +216,8 @@ def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len,
return frappe.db.sql("""select `tabDelivery Note`.name, `tabDelivery Note`.customer_name
from `tabDelivery Note`
where `tabDelivery Note`.`%(key)s` like %(txt)s and
`tabDelivery Note`.docstatus = 1 and status not in ("Stopped", "Closed") %(fcond)s and
(ifnull((select sum(qty) from `tabDelivery Note Item` where
`tabDelivery Note Item`.parent=`tabDelivery Note`.name), 0) >
ifnull((select sum(qty) from `tabSales Invoice Item` where
`tabSales Invoice Item`.docstatus = 1 and
`tabSales Invoice Item`.delivery_note=`tabDelivery Note`.name), 0))
`tabDelivery Note`.docstatus = 1 and status not in ("Stopped", "Closed") %(fcond)s
and (`tabDelivery Note`.per_billed < 100 or `tabDelivery Note`.grand_total = 0)
%(mcond)s order by `tabDelivery Note`.`%(key)s` asc
limit %(start)s, %(page_len)s""" % {
"key": searchfield,

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
import frappe
# accounts
class CustomerFrozen(frappe.ValidationError): pass
class PartyFrozen(frappe.ValidationError): pass
class InvalidAccountCurrency(frappe.ValidationError): pass
class InvalidCurrency(frappe.ValidationError): pass
class PartyDisabled(frappe.ValidationError):pass

View File

@ -241,13 +241,14 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "is_frozen",
"default": "0",
"fieldname": "disabled",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Is Frozen",
"label": "Disabled",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -591,7 +592,7 @@
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Customer Details",
"label": "More Information",
"length": 0,
"no_copy": 0,
"oldfieldtype": "Section Break",
@ -655,6 +656,30 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "is_frozen",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Is Frozen",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -794,7 +819,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-01-06 02:36:04.820353",
"modified": "2016-01-25 06:56:05.103168",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",
@ -984,5 +1009,6 @@
"read_only": 0,
"read_only_onload": 0,
"search_fields": "customer_name,customer_group,territory",
"sort_order": "ASC",
"title_field": "customer_name"
}

View File

@ -7,7 +7,7 @@ import frappe
import unittest
from frappe.test_runner import make_test_records
from erpnext.exceptions import CustomerFrozen
from erpnext.exceptions import PartyFrozen, PartyDisabled
test_ignore = ["Price List"]
@ -68,22 +68,38 @@ class TestCustomer(unittest.TestCase):
frappe.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1")
def test_freezed_customer(self):
make_test_records("Customer")
make_test_records("Item")
frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 1)
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
so = make_sales_order(do_not_save= True)
self.assertRaises(CustomerFrozen, so.save)
self.assertRaises(PartyFrozen, so.save)
frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 0)
so.save()
def test_disabled_customer(self):
make_test_records("Item")
frappe.db.set_value("Customer", "_Test Customer", "disabled", 1)
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
so = make_sales_order(do_not_save=True)
self.assertRaises(PartyDisabled, so.save)
frappe.db.set_value("Customer", "_Test Customer", "disabled", 0)
so.save()
def test_duplicate_customer(self):
frappe.db.sql("delete from `tabCustomer` where customer_name='_Test Customer 1'")
if not frappe.db.get_value("Customer", "_Test Customer 1"):
test_customer_1 = frappe.get_doc({
"customer_group": "_Test Customer Group",
@ -105,4 +121,4 @@ class TestCustomer(unittest.TestCase):
self.assertEquals("_Test Customer 1", test_customer_1.name)
self.assertEquals("_Test Customer 1 - 1", duplicate_customer.name)
self.assertEquals(test_customer_1.customer_name, duplicate_customer.customer_name)
self.assertEquals(test_customer_1.customer_name, duplicate_customer.customer_name)