def execute(filters=None): if not filters: filters = {} #Check if customer id is according to naming series or customer name customer_naming_type = frappe.db.get_value("Selling Settings", None, "cust_master_name") columns = get_columns(customer_naming_type) data = [] customer_list = get_details(filters) for d in customer_list: row = [] outstanding_amt = get_customer_outstanding(d.name, filters.get("company")) credit_limit = get_credit_limit(d.name, filters.get("company")) bal = flt(credit_limit) - flt(outstanding_amt) if customer_naming_type == "Naming Series": row = [d.name, d.customer_name, credit_limit, outstanding_amt, bal] else: row = [d.name, credit_limit, outstanding_amt, bal] if credit_limit: data.append(row) return columns, data
def execute(filters=None): if not filters: filters = {} #Check if customer id is according to naming series or customer name customer_naming_type = frappe.db.get_value("Selling Settings", None, "cust_master_name") columns = get_columns(customer_naming_type) data = [] customer_list = get_details(filters) for d in customer_list: row = [] outstanding_amt = get_customer_outstanding(d.name, filters.get("company"), ignore_outstanding_sales_order=d.bypass_credit_limit_check_at_sales_order, cost_center=filters.get("cost_center")) credit_limit = get_credit_limit(d.name, filters.get("company")) bal = flt(credit_limit) - flt(outstanding_amt) if customer_naming_type == "Naming Series": row = [d.name, d.customer_name, credit_limit, outstanding_amt, bal, d.bypass_credit_limit_check_at_sales_order, d.is_frozen, d.disabled] else: row = [d.name, credit_limit, outstanding_amt, bal, d.bypass_credit_limit_check_at_sales_order, d.is_frozen, d.disabled] if credit_limit: data.append(row) return columns, data
def execute(filters=None): if not filters: filters = {} #Check if customer id is according to naming series or customer name customer_naming_type = frappe.db.get_value("Selling Settings", None, "cust_master_name") columns = get_columns(customer_naming_type) data = [] customer_list = get_details(filters) frappe.msgprint(str(customer_list)) for d in customer_list: row = [] outstanding_amt = get_customer_outstanding(d.name, filters.get("company")) credit_limit = get_credit_limit(d.name, filters.get("company")) bal = flt(credit_limit) - flt(outstanding_amt) if customer_naming_type == "Naming Series": row = [d.name, d.customer_name, credit_limit, outstanding_amt, bal] else: row = [d.name, credit_limit, outstanding_amt, bal] if credit_limit: data.append(row) frappe.msgprint(str(data)) return columns, data
def on_update(self): if self.workflow_state == "Sales Approved": if get_credit_limit(self.customer, self.company) != 0: check_credit_limit(self.customer, self.company) self.workflow_state = "Account Approved" self.save() self.submit()
def test_customer_credit_limit_on_change(self): from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order outstanding_amt = self.get_customer_outstanding_amount() credit_limit = get_credit_limit('_Test Customer', '_Test Company') customer = frappe.get_doc("Customer", '_Test Customer') customer.credit_limit = flt(outstanding_amt - 100) self.assertRaises(frappe.ValidationError, customer.save)
def _get_party_details(party=None, account=None, party_type="Customer", letter_of_credit=None, company=None, posting_date=None, bill_date=None, price_list=None, currency=None, doctype=None, ignore_permissions=False, fetch_payment_terms_template=True, transaction_type=None, cost_center=None, tax_id=None, tax_cnic=None, tax_strn=None, has_stin=None, party_address=None, shipping_address=None, pos_profile=None): out = frappe._dict(set_due_date(party, party_type, company, posting_date, bill_date, doctype)) party = out[scrub(party_type)] if not ignore_permissions and not frappe.has_permission(party_type, "read", party): frappe.throw(_("Not permitted for {0}").format(party), frappe.PermissionError) if party or letter_of_credit: account = get_party_account("Letter of Credit" if letter_of_credit else party_type, letter_of_credit if letter_of_credit else party, company) account_fieldname = "debit_to" if party_type=="Customer" else "credit_to" out[account_fieldname] = account party = frappe.get_doc(party_type, party) currency = party.default_currency if party.get("default_currency") else get_company_currency(company) party_address, shipping_address = set_address_details(out, party, party_type, doctype, company, party_address, shipping_address) set_contact_details(out, party, party_type) set_other_values(out, party, party_type) set_price_list(out, party, party_type, price_list, pos_profile) out["tax_category"] = get_address_tax_category(party.get("tax_category"), party_address, shipping_address if party_type != "Supplier" else party_address) out["taxes_and_charges"] = set_taxes(party.name, party_type, posting_date, company, customer_group=out.customer_group, supplier_group=out.supplier_group, tax_category=out.tax_category, transaction_type=transaction_type, cost_center=cost_center, tax_id=tax_id, tax_cnic=tax_cnic, tax_strn=tax_strn, has_stin=has_stin, billing_address=party_address, shipping_address=shipping_address) if fetch_payment_terms_template: out["payment_terms_template"] = get_pyt_term_template(party.name, party_type, company) if not out.get("currency"): out["currency"] = currency # sales team if party_type=="Customer": out["sales_team"] = [{ "sales_person": d.sales_person, "allocated_percentage": d.allocated_percentage or None } for d in party.get("sales_team")] if doctype == "Sales Order": from erpnext.selling.doctype.customer.customer import get_credit_limit, get_customer_outstanding out["customer_credit_limit"] = get_credit_limit(party.name, company) out["customer_outstanding_amount"] = get_customer_outstanding(party.name, company) out["customer_credit_balance"] = out["customer_credit_limit"] - out["customer_outstanding_amount"] # supplier tax withholding category if party_type == "Supplier" and party: out["supplier_tds"] = frappe.get_value(party_type, party.name, "tax_withholding_category") return out
def get_credit_details(customer, company): outstanding = get_customer_outstanding(customer, company) credit_limit = get_credit_limit(customer, company) bal = credit_limit - outstanding if bal < 0: bal = 0 return { "outstanding": outstanding, "credit_limit": credit_limit, "bal": bal }
def test_customer_credit_limit(self): from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice outstanding_amt = self.get_customer_outstanding_amount() credit_limit = get_credit_limit('_Test Customer', '_Test Company') if outstanding_amt <= 0.0: item_qty = int((abs(outstanding_amt) + 200) / 100) make_sales_order(qty=item_qty) if credit_limit == 0.0: frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', outstanding_amt - 50.0) # Sales Order so = make_sales_order(do_not_submit=True) self.assertRaises(frappe.ValidationError, so.submit) # Delivery Note dn = create_delivery_note(do_not_submit=True) self.assertRaises(frappe.ValidationError, dn.submit) # Sales Invoice si = create_sales_invoice(do_not_submit=True) self.assertRaises(frappe.ValidationError, si.submit) if credit_limit > outstanding_amt: frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', credit_limit) # Makes Sales invoice from Sales Order so.save(ignore_permissions=True) si = make_sales_invoice(so.name) si.save(ignore_permissions=True) self.assertRaises(frappe.ValidationError, make_sales_order)
def test_customer_credit_limit(self): from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice outstanding_amt = self.get_customer_outstanding_amount() credit_limit = get_credit_limit('_Test Customer', '_Test Company') if outstanding_amt <= 0.0: item_qty = int((abs(outstanding_amt) + 200)/100) make_sales_order(qty=item_qty) if credit_limit == 0.0: frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', outstanding_amt - 50.0) # Sales Order so = make_sales_order(do_not_submit=True) self.assertRaises(frappe.ValidationError, so.submit) # Delivery Note dn = create_delivery_note(do_not_submit=True) self.assertRaises(frappe.ValidationError, dn.submit) # Sales Invoice si = create_sales_invoice(do_not_submit=True) self.assertRaises(frappe.ValidationError, si.submit) if credit_limit > outstanding_amt: frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', credit_limit) # Makes Sales invoice from Sales Order so.save(ignore_permissions=True) si = make_sales_invoice(so.name) si.save(ignore_permissions=True) self.assertRaises(frappe.ValidationError, make_sales_order)