Credit Limit and credit days fixes #2031

This commit is contained in:
Nabin Hait
2014-08-27 16:46:33 +05:30
parent be8ec39678
commit e9daefe07f
15 changed files with 138 additions and 243 deletions

View File

@@ -22,6 +22,7 @@ class AccountsController(TransactionBase):
self.set_total_in_words()
self.validate_for_freezed_account()
self.validate_due_date()
if self.meta.get_field("is_recurring"):
validate_recurring_document(self)
@@ -61,6 +62,13 @@ class AccountsController(TransactionBase):
validate_fiscal_year(self.get(date_field), self.fiscal_year,
label=self.meta.get_label(date_field))
def validate_due_date(self):
from erpnext.accounts.party import validate_due_date
if self.doctype == "Sales Invoice":
validate_due_date(self.posting_date, self.due_date, "Customer", self.customer, self.company)
elif self.doctype == "Purchase Invoice":
validate_due_date(self.posting_date, self.due_date, "Supplier", self.supplier, self.company)
def validate_for_freezed_account(self):
for fieldname in ["customer", "supplier"]:
if self.meta.get_field(fieldname) and self.get(fieldname):
@@ -515,15 +523,6 @@ class AccountsController(TransactionBase):
return self._abbr
def check_credit_limit(self, account):
total_outstanding = frappe.db.sql("""
select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry` where account = %s""", account)
total_outstanding = total_outstanding[0][0] if total_outstanding else 0
if total_outstanding:
frappe.get_doc('Account', account).check_credit_limit(total_outstanding)
@frappe.whitelist()
def get_tax_rate(account_head):
return frappe.db.get_value("Account", account_head, "tax_rate")

View File

@@ -33,6 +33,10 @@ class SellingController(StockController):
self.validate_max_discount()
check_active_sales_items(self)
def check_credit_limit(self):
from erpnext.selling.doctype.customer.customer import check_credit_limit
check_credit_limit(self.customer, self.company)
def set_missing_values(self, for_validate=False):
super(SellingController, self).set_missing_values(for_validate)
@@ -301,28 +305,6 @@ class SellingController(StockController):
elif self.order_type not in valid_types:
throw(_("Order Type must be one of {0}").format(comma_or(valid_types)))
def check_credit(self, grand_total):
customer_account = frappe.db.get_value("Account", {"company": self.company,
"master_name": self.customer}, "name")
if customer_account:
invoice_outstanding = frappe.db.sql("""select
sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry` where account = %s""", customer_account)
invoice_outstanding = flt(invoice_outstanding[0][0]) if invoice_outstanding else 0
ordered_amount_to_be_billed = frappe.db.sql("""
select sum(grand_total*(100 - ifnull(per_billed, 0))/100)
from `tabSales Order`
where customer=%s and docstatus = 1
and ifnull(per_billed, 0) < 100 and status != 'Stopped'""", self.customer)
ordered_amount_to_be_billed = flt(ordered_amount_to_be_billed[0][0]) \
if ordered_amount_to_be_billed else 0.0
total_outstanding = invoice_outstanding + ordered_amount_to_be_billed
frappe.get_doc('Account', customer_account).check_credit_limit(total_outstanding)
def validate_max_discount(self):
for d in self.get(self.fname):
discount = flt(frappe.db.get_value("Item", d.item_code, "max_discount"))