Credit days and credit limit option in customer group / supplier type #1354
This commit is contained in:
parent
e9daefe07f
commit
3a40435f8c
@ -38,10 +38,10 @@ class JournalVoucher(AccountsController):
|
||||
self.set_print_format_fields()
|
||||
self.validate_against_sales_order()
|
||||
self.validate_against_purchase_order()
|
||||
self.check_credit_limit()
|
||||
self.check_credit_days()
|
||||
|
||||
def on_submit(self):
|
||||
self.check_credit_limit()
|
||||
self.make_gl_entries()
|
||||
self.update_advance_paid()
|
||||
|
||||
@ -73,8 +73,8 @@ class JournalVoucher(AccountsController):
|
||||
check_credit_limit(customer, self.company)
|
||||
|
||||
def check_credit_days(self):
|
||||
from erpnext.accounts.party import get_credit_days
|
||||
posting_date = self.posting_date
|
||||
company_credit_days = frappe.db.get_value("Company", self.company, "credit_days")
|
||||
if self.cheque_date:
|
||||
for d in self.get("entries"):
|
||||
if d.party_type and d.party and d.get("credit" if d.party_type=="Customer" else "debit") > 0:
|
||||
@ -83,11 +83,12 @@ class JournalVoucher(AccountsController):
|
||||
elif d.against_voucher:
|
||||
posting_date = frappe.db.get_value("Purchase Invoice", d.against_voucher, "posting_date")
|
||||
|
||||
credit_days = frappe.db.get_value(d.party_type, d.party, "credit_days") or company_credit_days
|
||||
credit_days = get_credit_days(d.party_type, d.party, self.company)
|
||||
if credit_days:
|
||||
if (getdate(self.cheque_date) - getdate(posting_date)).days > flt(credit_days):
|
||||
msgprint(_("Note: Reference Date is after allowed credit days {0} for {1} {2}")
|
||||
.format(credit_days, d.party_type, d.party))
|
||||
date_diff = (getdate(self.cheque_date) - getdate(posting_date)).days
|
||||
if date_diff > flt(credit_days):
|
||||
msgprint(_("Note: Reference Date exceeds allowed credit days by {0} days for {1} {2}")
|
||||
.format(date_diff, d.party_type, d.party))
|
||||
|
||||
def validate_cheque_info(self):
|
||||
if self.voucher_type in ['Bank Voucher']:
|
||||
|
@ -147,9 +147,15 @@ def get_due_date(posting_date, party_type, party, company):
|
||||
|
||||
return due_date
|
||||
|
||||
def get_credit_days(self, party_type, party, company):
|
||||
return frappe.db.get_value(party_type, party, "credit_days") or \
|
||||
frappe.db.get_value("Company", company, "credit_days") if company else 0
|
||||
def get_credit_days(party_type, party, company):
|
||||
party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type"
|
||||
credit_days, party_group = frappe.db.get_value(party_type, party, ["credit_days", frappe.scrub(party_group_doctype)])
|
||||
|
||||
if not credit_days:
|
||||
credit_days = frappe.db.get_value(party_group_doctype, party_group, "credit_days") or \
|
||||
frappe.db.get_value("Company", company, "credit_days")
|
||||
|
||||
return credit_days
|
||||
|
||||
def validate_due_date(posting_date, due_date, party_type, party, company):
|
||||
credit_days = get_credit_days(party_type, party, company)
|
||||
@ -164,8 +170,8 @@ def validate_due_date(posting_date, due_date, party_type, party, company):
|
||||
"credit_controller") in frappe.user.get_roles()
|
||||
|
||||
if is_credit_controller:
|
||||
msgprint(_("Note: Due / Reference Date exceeds the allowed credit days by {0} day(s)").format(
|
||||
diff - flt(credit_days)))
|
||||
msgprint(_("Note: Due / Reference Date exceeds allowed customer credit days by {0} day(s)")
|
||||
.format(diff - flt(credit_days)))
|
||||
else:
|
||||
max_due_date = formatdate(add_days(posting_date, credit_days))
|
||||
frappe.throw(_("Due / Reference Date cannot be after {0}").format(max_due_date))
|
||||
|
@ -152,9 +152,7 @@ def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
|
||||
def check_credit_limit(customer, company):
|
||||
customer_outstanding = get_customer_outstanding(customer, company)
|
||||
|
||||
credit_limit = frappe.db.get_value("Customer", customer, "credit_limit") or \
|
||||
frappe.db.get_value('Company', company, 'credit_limit')
|
||||
|
||||
credit_limit = get_credit_limit(customer, company)
|
||||
if credit_limit > 0 and flt(customer_outstanding) > credit_limit:
|
||||
msgprint(_("Credit limit has been crossed for customer {0} {1}/{2}")
|
||||
.format(customer, customer_outstanding, credit_limit))
|
||||
@ -186,9 +184,9 @@ def get_customer_outstanding(customer, company):
|
||||
select
|
||||
sum(
|
||||
(
|
||||
(ifnull(dn_item.amount) - (select sum(ifnull(amount, 0))
|
||||
(ifnull(dn_item.amount, 0) - ifnull((select sum(ifnull(amount, 0))
|
||||
from `tabSales Invoice Item`
|
||||
where ifnull(dn_detail, '') = dn_item.name and docstatus = 1)
|
||||
where ifnull(dn_detail, '') = dn_item.name and docstatus = 1), 0)
|
||||
)/dn.net_total
|
||||
)*dn.grand_total
|
||||
)
|
||||
@ -198,10 +196,19 @@ def get_customer_outstanding(customer, company):
|
||||
and dn.docstatus = 1 and dn.status != 'Stopped'
|
||||
and ifnull(dn_item.against_sales_order, '') = ''
|
||||
and ifnull(dn_item.against_sales_invoice, '') = ''
|
||||
and ifnull(dn_item.amount) > (select sum(ifnull(amount, 0))
|
||||
and ifnull(dn_item.amount, 0) > ifnull((select sum(ifnull(amount, 0))
|
||||
from `tabSales Invoice Item`
|
||||
where ifnull(dn_detail, '') = dn_item.name and docstatus = 1)""", (customer, company))
|
||||
where ifnull(dn_detail, '') = dn_item.name and docstatus = 1), 0)""", (customer, company))
|
||||
|
||||
outstanding_based_on_dn = flt(outstanding_based_on_dn[0][0]) if outstanding_based_on_dn else 0.0
|
||||
|
||||
return outstanding_based_on_gle + outstanding_based_on_so + outstanding_based_on_dn
|
||||
|
||||
|
||||
def get_credit_limit(customer, company):
|
||||
credit_limit, customer_group = frappe.db.get_value("Customer", customer, ["credit_limit", "customer_group"])
|
||||
if not credit_limit:
|
||||
credit_limit = frappe.db.get_value("Customer Group", customer_group, "credit_limit") or \
|
||||
frappe.db.get_value("Company", company, "credit_limit")
|
||||
|
||||
return credit_limit
|
||||
|
@ -56,6 +56,18 @@
|
||||
"options": "Price List",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "credit_days",
|
||||
"fieldtype": "Int",
|
||||
"label": "Credit Days",
|
||||
"permlevel": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "credit_limit",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Credit Limit",
|
||||
"permlevel": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "lft",
|
||||
"fieldtype": "Int",
|
||||
@ -101,7 +113,7 @@
|
||||
"icon": "icon-sitemap",
|
||||
"idx": 1,
|
||||
"in_create": 1,
|
||||
"modified": "2014-05-27 03:49:09.397308",
|
||||
"modified": "2014-08-27 17:41:35.154380",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Customer Group",
|
||||
@ -146,6 +158,23 @@
|
||||
"role": "Sales Master Manager",
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"permlevel": 1,
|
||||
"read": 1,
|
||||
"role": "Sales Master Manager",
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"permlevel": 1,
|
||||
"read": 1,
|
||||
"role": "Sales User"
|
||||
},
|
||||
{
|
||||
"permlevel": 1,
|
||||
"read": 1,
|
||||
"role": "Sales Manager",
|
||||
"write": 0
|
||||
}
|
||||
],
|
||||
"read_only": 1,
|
||||
|
@ -16,11 +16,17 @@
|
||||
"oldfieldtype": "Data",
|
||||
"permlevel": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "credit_days",
|
||||
"fieldtype": "Int",
|
||||
"label": "Credit Days",
|
||||
"permlevel": 1
|
||||
}
|
||||
],
|
||||
"icon": "icon-flag",
|
||||
"idx": 1,
|
||||
"modified": "2014-05-27 03:49:20.505739",
|
||||
"modified": "2014-08-27 17:43:31.479133",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Supplier Type",
|
||||
@ -65,6 +71,22 @@
|
||||
"role": "Purchase Master Manager",
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"permlevel": 1,
|
||||
"read": 1,
|
||||
"role": "Purchase Master Manager",
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"permlevel": 1,
|
||||
"read": 1,
|
||||
"role": "Purchase Manager"
|
||||
},
|
||||
{
|
||||
"permlevel": 1,
|
||||
"read": 1,
|
||||
"role": "Purchase User"
|
||||
}
|
||||
]
|
||||
}
|
@ -9,7 +9,6 @@ from frappe import throw, msgprint, _
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Warehouse(Document):
|
||||
|
||||
def autoname(self):
|
||||
suffix = " - " + frappe.db.get_value("Company", self.company, "abbr")
|
||||
if not self.warehouse_name.endswith(suffix):
|
||||
@ -22,7 +21,6 @@ class Warehouse(Document):
|
||||
self.update_parent_account()
|
||||
|
||||
def update_parent_account(self):
|
||||
|
||||
if not getattr(self, "__islocal", None) \
|
||||
and (self.create_account_under != frappe.db.get_value("Warehouse", self.name, "create_account_under")):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user