Merge pull request #2473 from nabinhait/fix1

minor fix
This commit is contained in:
Nabin Hait 2014-12-09 16:31:03 +05:30
commit f18d285eab
2 changed files with 32 additions and 40 deletions

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import flt, cstr, cint, getdate, add_days, formatdate from frappe.utils import flt, cstr, cint, getdate
from frappe import msgprint, throw, _ from frappe import msgprint, throw, _
from frappe.model.document import Document from frappe.model.document import Document
@ -176,15 +176,7 @@ class Account(Document):
frappe.throw(_("Due Date cannot be before Posting Date")) frappe.throw(_("Due Date cannot be before Posting Date"))
elif credit_days is not None and diff > credit_days: elif credit_days is not None and diff > credit_days:
is_credit_controller = frappe.db.get_value("Accounts Settings", None, msgprint(_("Note: Due Date exceeds the allowed credit days by {0} day(s)").format(diff - credit_days))
"credit_controller") in frappe.user.get_roles()
if is_credit_controller:
msgprint(_("Note: Due Date exceeds the allowed credit days by {0} day(s)").format(
diff - credit_days))
else:
max_due_date = formatdate(add_days(posting_date, credit_days))
frappe.throw(_("Due Date cannot be after {0}").format(max_due_date))
def validate_trash(self): def validate_trash(self):
"""checks gl entries and if child exists""" """checks gl entries and if child exists"""

View File

@ -13,17 +13,17 @@ class AccountsReceivableReport(object):
self.age_as_on = getdate(nowdate()) \ self.age_as_on = getdate(nowdate()) \
if self.filters.report_date > getdate(nowdate()) \ if self.filters.report_date > getdate(nowdate()) \
else self.filters.report_date else self.filters.report_date
def run(self): def run(self):
customer_naming_by = frappe.db.get_value("Selling Settings", None, "cust_master_name") customer_naming_by = frappe.db.get_value("Selling Settings", None, "cust_master_name")
return self.get_columns(customer_naming_by), self.get_data(customer_naming_by) return self.get_columns(customer_naming_by), self.get_data(customer_naming_by)
def get_columns(self, customer_naming_by): def get_columns(self, customer_naming_by):
columns = [ columns = [
_("Posting Date") + ":Date:80", _("Account") + ":Link/Account:150", _("Posting Date") + ":Date:80", _("Account") + ":Link/Account:150",
_("Voucher Type") + "::110", _("Voucher No") + ":Dynamic Link/Voucher Type:120", _("Voucher Type") + "::110", _("Voucher No") + ":Dynamic Link/Voucher Type:120",
_("Due Date") + ":Date:80", _("Due Date") + ":Date:80",
_("Invoiced Amount") + ":Currency:100", _("Payment Received") + ":Currency:100", _("Invoiced Amount") + ":Currency:100", _("Payment Received") + ":Currency:100",
_("Outstanding Amount") + ":Currency:100", _("Age") + ":Int:50", "0-30:Currency:100", _("Outstanding Amount") + ":Currency:100", _("Age") + ":Int:50", "0-30:Currency:100",
"30-60:Currency:100", "60-90:Currency:100", _("90-Above") + ":Currency:100", "30-60:Currency:100", "60-90:Currency:100", _("90-Above") + ":Currency:100",
_("Customer") + ":Link/Customer:200" _("Customer") + ":Link/Customer:200"
@ -69,27 +69,27 @@ class AccountsReceivableReport(object):
# returns a distinct list # returns a distinct list
return list(set([(e.voucher_type, e.voucher_no) for e in self.get_gl_entries() return list(set([(e.voucher_type, e.voucher_no) for e in self.get_gl_entries()
if getdate(e.posting_date) > report_date])) if getdate(e.posting_date) > report_date]))
def get_entries_till(self, report_date): def get_entries_till(self, report_date):
# returns a generator # returns a generator
return (e for e in self.get_gl_entries() return (e for e in self.get_gl_entries()
if getdate(e.posting_date) <= report_date) if getdate(e.posting_date) <= report_date)
def is_receivable(self, gle, future_vouchers): def is_receivable(self, gle, future_vouchers):
return ( return (
# advance # advance
(not gle.against_voucher) or (not gle.against_voucher) or
# against sales order # against sales order
(gle.against_voucher_type == "Sales Order") or (gle.against_voucher_type == "Sales Order") or
# sales invoice # sales invoice
(gle.against_voucher==gle.voucher_no and gle.debit > 0) or (gle.against_voucher==gle.voucher_no and gle.debit > 0) or
# entries adjusted with future vouchers # entries adjusted with future vouchers
((gle.against_voucher_type, gle.against_voucher) in future_vouchers) ((gle.against_voucher_type, gle.against_voucher) in future_vouchers)
) )
def get_outstanding_amount(self, gle, report_date): def get_outstanding_amount(self, gle, report_date):
payment_received = 0.0 payment_received = 0.0
for e in self.get_gl_entries_for(gle.account, gle.voucher_type, gle.voucher_no): for e in self.get_gl_entries_for(gle.account, gle.voucher_type, gle.voucher_no):
@ -97,7 +97,7 @@ class AccountsReceivableReport(object):
payment_received += (flt(e.credit) - flt(e.debit)) payment_received += (flt(e.credit) - flt(e.debit))
return flt(gle.debit) - flt(gle.credit) - payment_received return flt(gle.debit) - flt(gle.credit) - payment_received
def get_customer(self, account): def get_customer(self, account):
return self.get_account_map().get(account, {}).get("customer") or "" return self.get_account_map().get(account, {}).get("customer") or ""
@ -106,25 +106,25 @@ class AccountsReceivableReport(object):
def get_territory(self, account): def get_territory(self, account):
return self.get_account_map().get(account, {}).get("territory") or "" return self.get_account_map().get(account, {}).get("territory") or ""
def get_account_map(self): def get_account_map(self):
if not hasattr(self, "account_map"): if not hasattr(self, "account_map"):
self.account_map = dict(((r.name, r) for r in frappe.db.sql("""select self.account_map = dict(((r.name, r) for r in frappe.db.sql("""select
acc.name, cust.name as customer, cust.customer_name, cust.territory acc.name, cust.name as customer, cust.customer_name, cust.territory
from `tabAccount` acc left join `tabCustomer` cust from `tabAccount` acc left join `tabCustomer` cust
on cust.name=acc.master_name where acc.master_type="Customer" """, as_dict=True))) on cust.name=acc.master_name where acc.master_type="Customer" """, as_dict=True)))
return self.account_map return self.account_map
def get_due_date(self, gle): def get_due_date(self, gle):
if not hasattr(self, "invoice_due_date_map"): if not hasattr(self, "invoice_due_date_map"):
# TODO can be restricted to posting date # TODO can be restricted to posting date
self.invoice_due_date_map = dict(frappe.db.sql("""select name, due_date self.invoice_due_date_map = dict(frappe.db.sql("""select name, due_date
from `tabSales Invoice` where docstatus=1""")) from `tabSales Invoice` where docstatus=1"""))
return gle.voucher_type == "Sales Invoice" \ return gle.voucher_type == "Sales Invoice" \
and self.invoice_due_date_map.get(gle.voucher_no) or "" and self.invoice_due_date_map.get(gle.voucher_no) or ""
def get_gl_entries(self): def get_gl_entries(self):
if not hasattr(self, "gl_entries"): if not hasattr(self, "gl_entries"):
conditions, values = self.prepare_conditions() conditions, values = self.prepare_conditions()
@ -132,15 +132,15 @@ class AccountsReceivableReport(object):
where docstatus < 2 {0} order by posting_date, account""".format(conditions), where docstatus < 2 {0} order by posting_date, account""".format(conditions),
values, as_dict=True) values, as_dict=True)
return self.gl_entries return self.gl_entries
def prepare_conditions(self): def prepare_conditions(self):
conditions = [""] conditions = [""]
values = {} values = {}
if self.filters.company: if self.filters.company:
conditions.append("company=%(company)s") conditions.append("company=%(company)s")
values["company"] = self.filters.company values["company"] = self.filters.company
if self.filters.account: if self.filters.account:
conditions.append("account=%(account)s") conditions.append("account=%(account)s")
values["account"] = self.filters.account values["account"] = self.filters.account
@ -149,11 +149,11 @@ class AccountsReceivableReport(object):
if not account_map: if not account_map:
frappe.throw(_("No Customer Accounts found.")) frappe.throw(_("No Customer Accounts found."))
else: else:
accounts_list = ['"{0}"'.format(ac) for ac in account_map] accounts_list = ['"{0}"'.format(ac.replace('"', '\"')) for ac in account_map]
conditions.append("account in ({0})".format(", ".join(accounts_list))) conditions.append("account in ({0})".format(", ".join(accounts_list)))
return " and ".join(conditions), values return " and ".join(conditions), values
def get_gl_entries_for(self, account, against_voucher_type, against_voucher): def get_gl_entries_for(self, account, against_voucher_type, against_voucher):
if not hasattr(self, "gl_entries_map"): if not hasattr(self, "gl_entries_map"):
self.gl_entries_map = {} self.gl_entries_map = {}
@ -163,7 +163,7 @@ class AccountsReceivableReport(object):
.setdefault(gle.against_voucher_type, {})\ .setdefault(gle.against_voucher_type, {})\
.setdefault(gle.against_voucher, [])\ .setdefault(gle.against_voucher, [])\
.append(gle) .append(gle)
return self.gl_entries_map.get(account, {})\ return self.gl_entries_map.get(account, {})\
.get(against_voucher_type, {})\ .get(against_voucher_type, {})\
.get(against_voucher, []) .get(against_voucher, [])
@ -176,15 +176,15 @@ def get_ageing_data(age_as_on, entry_date, outstanding_amount):
outstanding_range = [0.0, 0.0, 0.0, 0.0] outstanding_range = [0.0, 0.0, 0.0, 0.0]
if not (age_as_on and entry_date): if not (age_as_on and entry_date):
return [0] + outstanding_range return [0] + outstanding_range
age = (getdate(age_as_on) - getdate(entry_date)).days or 0 age = (getdate(age_as_on) - getdate(entry_date)).days or 0
index = None index = None
for i, days in enumerate([30, 60, 90]): for i, days in enumerate([30, 60, 90]):
if age <= days: if age <= days:
index = i index = i
break break
if index is None: index = 3 if index is None: index = 3
outstanding_range[index] = outstanding_amount outstanding_range[index] = outstanding_amount
return [age] + outstanding_range return [age] + outstanding_range