Fixed conflict while merging with master
This commit is contained in:
commit
139aa71666
@ -364,7 +364,6 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
|
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
|
||||||
order by account asc, debit asc""", si.doc.name, as_dict=1)
|
order by account asc, debit asc""", si.doc.name, as_dict=1)
|
||||||
self.assertTrue(gl_entries)
|
self.assertTrue(gl_entries)
|
||||||
# print gl_entries
|
|
||||||
|
|
||||||
stock_in_hand = webnotes.conn.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
|
stock_in_hand = webnotes.conn.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ def execute(filters=None):
|
|||||||
for gle in get_gl_entries(filters, before_report_date=False)]
|
for gle in get_gl_entries(filters, before_report_date=False)]
|
||||||
|
|
||||||
account_supplier_type_map = get_account_supplier_type_map()
|
account_supplier_type_map = get_account_supplier_type_map()
|
||||||
pi_map = get_pi_map()
|
voucher_detail_map = get_voucher_details()
|
||||||
|
|
||||||
# Age of the invoice on this date
|
# Age of the invoice on this date
|
||||||
age_on = getdate(filters.get("report_date")) > getdate(nowdate()) \
|
age_on = getdate(filters.get("report_date")) > getdate(nowdate()) \
|
||||||
@ -29,13 +29,7 @@ def execute(filters=None):
|
|||||||
for gle in entries:
|
for gle in entries:
|
||||||
if cstr(gle.against_voucher) == gle.voucher_no or not gle.against_voucher \
|
if cstr(gle.against_voucher) == gle.voucher_no or not gle.against_voucher \
|
||||||
or [gle.against_voucher_type, gle.against_voucher] in entries_after_report_date:
|
or [gle.against_voucher_type, gle.against_voucher] in entries_after_report_date:
|
||||||
if gle.voucher_type == "Purchase Invoice":
|
voucher_details = voucher_detail_map.get(gle.voucher_type, {}).get(gle.voucher_no, {})
|
||||||
pi_info = pi_map.get(gle.voucher_no)
|
|
||||||
due_date = pi_info.get("due_date")
|
|
||||||
bill_no = pi_info.get("bill_no")
|
|
||||||
bill_date = pi_info.get("bill_date")
|
|
||||||
else:
|
|
||||||
due_date = bill_no = bill_date = ""
|
|
||||||
|
|
||||||
invoiced_amount = gle.credit > 0 and gle.credit or 0
|
invoiced_amount = gle.credit > 0 and gle.credit or 0
|
||||||
outstanding_amount = get_outstanding_amount(gle,
|
outstanding_amount = get_outstanding_amount(gle,
|
||||||
@ -44,13 +38,15 @@ def execute(filters=None):
|
|||||||
if abs(flt(outstanding_amount)) > 0.01:
|
if abs(flt(outstanding_amount)) > 0.01:
|
||||||
paid_amount = invoiced_amount - outstanding_amount
|
paid_amount = invoiced_amount - outstanding_amount
|
||||||
row = [gle.posting_date, gle.account, account_supplier.get(gle.account, ""),
|
row = [gle.posting_date, gle.account, account_supplier.get(gle.account, ""),
|
||||||
gle.voucher_type, gle.voucher_no,
|
gle.voucher_type, gle.voucher_no, gle.remarks,
|
||||||
gle.remarks, account_supplier_type_map.get(gle.account), due_date, bill_no,
|
account_supplier_type_map.get(gle.account),
|
||||||
bill_date, invoiced_amount, paid_amount, outstanding_amount]
|
voucher_details.get("due_date", ""), voucher_details.get("bill_no", ""),
|
||||||
|
voucher_details.get("bill_date", ""), invoiced_amount,
|
||||||
|
paid_amount, outstanding_amount]
|
||||||
|
|
||||||
# Ageing
|
# Ageing
|
||||||
if filters.get("ageing_based_on") == "Due Date":
|
if filters.get("ageing_based_on") == "Due Date":
|
||||||
ageing_based_on_date = due_date
|
ageing_based_on_date = voucher_details.get("due_date", "")
|
||||||
else:
|
else:
|
||||||
ageing_based_on_date = gle.posting_date
|
ageing_based_on_date = gle.posting_date
|
||||||
|
|
||||||
@ -111,14 +107,15 @@ def get_account_supplier_type_map():
|
|||||||
|
|
||||||
return account_supplier_type_map
|
return account_supplier_type_map
|
||||||
|
|
||||||
def get_pi_map():
|
def get_voucher_details():
|
||||||
""" get due_date from sales invoice """
|
voucher_details = {}
|
||||||
pi_map = {}
|
for dt in ["Purchase Invoice", "Journal Voucher"]:
|
||||||
for t in webnotes.conn.sql("""select name, due_date, bill_no, bill_date
|
voucher_details.setdefault(dt, webnotes._dict())
|
||||||
from `tabPurchase Invoice`""", as_dict=1):
|
for t in webnotes.conn.sql("""select name, due_date, bill_no, bill_date
|
||||||
pi_map[t.name] = t
|
from `tab%s`""" % dt, as_dict=1):
|
||||||
|
voucher_details[dt].setdefault(t.name, t)
|
||||||
|
|
||||||
return pi_map
|
return voucher_details
|
||||||
|
|
||||||
def get_outstanding_amount(gle, report_date):
|
def get_outstanding_amount(gle, report_date):
|
||||||
payment_amount = webnotes.conn.sql("""
|
payment_amount = webnotes.conn.sql("""
|
||||||
|
@ -11,26 +11,6 @@ wn.query_reports["General Ledger"] = {
|
|||||||
"default": wn.defaults.get_user_default("company"),
|
"default": wn.defaults.get_user_default("company"),
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname":"account",
|
|
||||||
"label": wn._("Account"),
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"options": "Account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname":"voucher_no",
|
|
||||||
"label": wn._("Voucher No"),
|
|
||||||
"fieldtype": "Data",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname":"group_by",
|
|
||||||
"label": wn._("Group by"),
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"options": "\nGroup by Account\nGroup by Voucher"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldtype": "Break",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname":"from_date",
|
"fieldname":"from_date",
|
||||||
"label": wn._("From Date"),
|
"label": wn._("From Date"),
|
||||||
@ -46,6 +26,40 @@ wn.query_reports["General Ledger"] = {
|
|||||||
"default": wn.datetime.get_today(),
|
"default": wn.datetime.get_today(),
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"width": "60px"
|
"width": "60px"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldtype": "Break",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"account",
|
||||||
|
"label": wn._("Account"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Account",
|
||||||
|
"get_query": function() {
|
||||||
|
var company = wn.query_report.filters_by_name.company.get_value();
|
||||||
|
return {
|
||||||
|
"doctype": "Account",
|
||||||
|
"filters": {
|
||||||
|
"company": company,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"voucher_no",
|
||||||
|
"label": wn._("Voucher No"),
|
||||||
|
"fieldtype": "Data",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"group_by_voucher",
|
||||||
|
"label": wn._("Group by Voucher"),
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"default": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"group_by_account",
|
||||||
|
"label": wn._("Group by Account"),
|
||||||
|
"fieldtype": "Check",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -3,71 +3,61 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import flt, add_days
|
from webnotes.utils import cstr, flt
|
||||||
from webnotes import _
|
from webnotes import _
|
||||||
from erpnext.accounts.utils import get_balance_on
|
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
account_details = webnotes.conn.get_value("Account", filters["account"],
|
account_details = {}
|
||||||
["debit_or_credit", "group_or_ledger"], as_dict=True) if filters.get("account") else None
|
for acc in webnotes.conn.sql("""select name, debit_or_credit, group_or_ledger
|
||||||
|
from tabAccount""", as_dict=1):
|
||||||
|
account_details.setdefault(acc.name, acc)
|
||||||
|
|
||||||
validate_filters(filters, account_details)
|
validate_filters(filters, account_details)
|
||||||
|
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
data = []
|
|
||||||
if filters.get("group_by"):
|
|
||||||
data += get_grouped_gle(filters)
|
|
||||||
else:
|
|
||||||
data += get_gl_entries(filters)
|
|
||||||
if data:
|
|
||||||
data.append(get_total_row(data))
|
|
||||||
|
|
||||||
if account_details:
|
res = get_result(filters, account_details)
|
||||||
data = [get_opening_balance_row(filters, account_details.debit_or_credit)] + data + \
|
|
||||||
[get_closing_balance_row(filters, account_details.debit_or_credit)]
|
|
||||||
|
|
||||||
return columns, data
|
return columns, res
|
||||||
|
|
||||||
def validate_filters(filters, account_details):
|
def validate_filters(filters, account_details):
|
||||||
if account_details and account_details.group_or_ledger == "Ledger" \
|
if filters.get("account") and filters.get("group_by_account") \
|
||||||
and filters.get("group_by") == "Group by Account":
|
and account_details[filters.account].group_or_ledger == "Ledger":
|
||||||
webnotes.throw(_("Can not filter based on Account, if grouped by Account"))
|
webnotes.throw(_("Can not filter based on Account, if grouped by Account"))
|
||||||
|
|
||||||
if filters.get("voucher_no") and filters.get("group_by") == "Group by Voucher":
|
if filters.get("voucher_no") and filters.get("group_by_voucher"):
|
||||||
webnotes.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
|
webnotes.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
|
||||||
|
|
||||||
|
if filters.from_date > filters.to_date:
|
||||||
|
webnotes.throw(_("From Date must be before To Date"))
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Float:100",
|
return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Float:100",
|
||||||
"Credit:Float:100", "Voucher Type::120", "Voucher No::160", "Link::20",
|
"Credit:Float:100", "Voucher Type::120", "Voucher No::160", "Link::20",
|
||||||
"Cost Center:Link/Cost Center:100", "Remarks::200"]
|
"Against Account::120", "Cost Center:Link/Cost Center:100", "Remarks::200"]
|
||||||
|
|
||||||
def get_opening_balance_row(filters, debit_or_credit):
|
def get_result(filters, account_details):
|
||||||
opening_balance = get_balance_on(filters["account"], add_days(filters["from_date"], -1))
|
gl_entries = get_gl_entries(filters)
|
||||||
return get_balance_row(opening_balance, debit_or_credit, "Opening Balance")
|
|
||||||
|
|
||||||
def get_closing_balance_row(filters, debit_or_credit):
|
data = get_data_with_opening_closing(filters, account_details, gl_entries)
|
||||||
closing_balance = get_balance_on(filters["account"], filters["to_date"])
|
|
||||||
return get_balance_row(closing_balance, debit_or_credit, "Closing Balance")
|
|
||||||
|
|
||||||
def get_balance_row(balance, debit_or_credit, balance_label):
|
result = get_result_as_list(data)
|
||||||
if debit_or_credit == "Debit":
|
|
||||||
return ["", balance_label, balance, 0.0, "", "", ""]
|
return result
|
||||||
else:
|
|
||||||
return ["", balance_label, 0.0, balance, "", "", ""]
|
|
||||||
|
|
||||||
def get_gl_entries(filters):
|
def get_gl_entries(filters):
|
||||||
gl_entries = webnotes.conn.sql("""select
|
group_by_condition = "group by voucher_type, voucher_no, account" \
|
||||||
posting_date, account, debit, credit, voucher_type, voucher_no, cost_center, remarks
|
if filters.get("group_by_voucher") else "group by name"
|
||||||
from `tabGL Entry`
|
|
||||||
where company=%(company)s
|
|
||||||
and posting_date between %(from_date)s and %(to_date)s
|
|
||||||
{conditions}
|
|
||||||
order by posting_date, account"""\
|
|
||||||
.format(conditions=get_conditions(filters)), filters, as_list=1)
|
|
||||||
|
|
||||||
for d in gl_entries:
|
gl_entries = webnotes.conn.sql("""select posting_date, account,
|
||||||
icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
|
sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit,
|
||||||
% ("/".join(["#Form", d[4], d[5]]),)
|
voucher_type, voucher_no, cost_center, remarks, is_advance, against
|
||||||
d.insert(6, icon)
|
from `tabGL Entry`
|
||||||
|
where company=%(company)s {conditions}
|
||||||
|
{group_by_condition}
|
||||||
|
order by posting_date, account"""\
|
||||||
|
.format(conditions=get_conditions(filters), group_by_condition=group_by_condition),
|
||||||
|
filters, as_dict=1)
|
||||||
|
|
||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
@ -77,35 +67,106 @@ def get_conditions(filters):
|
|||||||
lft, rgt = webnotes.conn.get_value("Account", filters["account"], ["lft", "rgt"])
|
lft, rgt = webnotes.conn.get_value("Account", filters["account"], ["lft", "rgt"])
|
||||||
conditions.append("""account in (select name from tabAccount
|
conditions.append("""account in (select name from tabAccount
|
||||||
where lft>=%s and rgt<=%s and docstatus<2)""" % (lft, rgt))
|
where lft>=%s and rgt<=%s and docstatus<2)""" % (lft, rgt))
|
||||||
|
else:
|
||||||
|
conditions.append("posting_date between %(from_date)s and %(to_date)s")
|
||||||
|
|
||||||
if filters.get("voucher_no"):
|
if filters.get("voucher_no"):
|
||||||
conditions.append("voucher_no=%(voucher_no)s")
|
conditions.append("voucher_no=%(voucher_no)s")
|
||||||
|
|
||||||
return "and {}".format(" and ".join(conditions)) if conditions else ""
|
return "and {}".format(" and ".join(conditions)) if conditions else ""
|
||||||
|
|
||||||
def get_grouped_gle(filters):
|
def get_data_with_opening_closing(filters, account_details, gl_entries):
|
||||||
gle_map = {}
|
|
||||||
gle = get_gl_entries(filters)
|
|
||||||
for d in gle:
|
|
||||||
gle_map.setdefault(d[1 if filters["group_by"]=="Group by Account" else 5], []).append(d)
|
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for entries in gle_map.values():
|
gle_map = initialize_gle_map(gl_entries)
|
||||||
subtotal_debit = subtotal_credit = 0.0
|
|
||||||
for entry in entries:
|
|
||||||
data.append(entry)
|
|
||||||
subtotal_debit += flt(entry[2])
|
|
||||||
subtotal_credit += flt(entry[3])
|
|
||||||
|
|
||||||
data.append(["", "Total", subtotal_debit, subtotal_credit, "", "", ""])
|
opening, total_debit, total_credit, gle_map = get_accountwise_gle(filters, gl_entries, gle_map)
|
||||||
|
|
||||||
|
# Opening for filtered account
|
||||||
|
if filters.get("account"):
|
||||||
|
data += [get_balance_row("Opening", account_details[filters.account].debit_or_credit,
|
||||||
|
opening), {}]
|
||||||
|
|
||||||
|
for acc, acc_dict in gle_map.items():
|
||||||
|
if acc_dict.entries:
|
||||||
|
# Opening for individual ledger, if grouped by account
|
||||||
|
if filters.get("group_by_account"):
|
||||||
|
data.append(get_balance_row("Opening", account_details[acc].debit_or_credit,
|
||||||
|
acc_dict.opening))
|
||||||
|
|
||||||
|
data += acc_dict.entries
|
||||||
|
|
||||||
|
# Totals and closing for individual ledger, if grouped by account
|
||||||
|
if filters.get("group_by_account"):
|
||||||
|
data += [{"account": "Totals", "debit": acc_dict.total_debit,
|
||||||
|
"credit": acc_dict.total_credit},
|
||||||
|
get_balance_row("Closing (Opening + Totals)",
|
||||||
|
account_details[acc].debit_or_credit, (acc_dict.opening
|
||||||
|
+ acc_dict.total_debit - acc_dict.total_credit)), {}]
|
||||||
|
|
||||||
|
# Total debit and credit between from and to date
|
||||||
|
if total_debit or total_credit:
|
||||||
|
data.append({"account": "Totals", "debit": total_debit, "credit": total_credit})
|
||||||
|
|
||||||
|
# Closing for filtered account
|
||||||
|
if filters.get("account"):
|
||||||
|
data.append(get_balance_row("Closing (Opening + Totals)",
|
||||||
|
account_details[filters.account].debit_or_credit,
|
||||||
|
(opening + total_debit - total_credit)))
|
||||||
|
|
||||||
if data:
|
|
||||||
data.append(get_total_row(gle))
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_total_row(gle):
|
def initialize_gle_map(gl_entries):
|
||||||
total_debit = total_credit = 0.0
|
gle_map = webnotes._dict()
|
||||||
for d in gle:
|
for gle in gl_entries:
|
||||||
total_debit += flt(d[2])
|
gle_map.setdefault(gle.account, webnotes._dict({
|
||||||
total_credit += flt(d[3])
|
"opening": 0,
|
||||||
|
"entries": [],
|
||||||
|
"total_debit": 0,
|
||||||
|
"total_credit": 0,
|
||||||
|
"closing": 0
|
||||||
|
}))
|
||||||
|
return gle_map
|
||||||
|
|
||||||
return ["", "Total Debit/Credit", total_debit, total_credit, "", "", ""]
|
def get_accountwise_gle(filters, gl_entries, gle_map):
|
||||||
|
opening, total_debit, total_credit = 0, 0, 0
|
||||||
|
|
||||||
|
for gle in gl_entries:
|
||||||
|
amount = flt(gle.debit) - flt(gle.credit)
|
||||||
|
if filters.get("account") and (gle.posting_date < filters.from_date
|
||||||
|
or cstr(gle.is_advance) == "Yes"):
|
||||||
|
gle_map[gle.account].opening += amount
|
||||||
|
opening += amount
|
||||||
|
elif gle.posting_date < filters.to_date:
|
||||||
|
gle_map[gle.account].entries.append(gle)
|
||||||
|
gle_map[gle.account].total_debit += flt(gle.debit)
|
||||||
|
gle_map[gle.account].total_credit += flt(gle.credit)
|
||||||
|
|
||||||
|
total_debit += flt(gle.debit)
|
||||||
|
total_credit += flt(gle.credit)
|
||||||
|
|
||||||
|
return opening, total_debit, total_credit, gle_map
|
||||||
|
|
||||||
|
def get_balance_row(label, debit_or_credit, balance):
|
||||||
|
return {
|
||||||
|
"account": label,
|
||||||
|
"debit": balance if debit_or_credit=="Debit" else 0,
|
||||||
|
"credit": -1*balance if debit_or_credit=="Credit" else 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_result_as_list(data):
|
||||||
|
result = []
|
||||||
|
for d in data:
|
||||||
|
result.append([d.get("posting_date"), d.get("account"), d.get("debit"),
|
||||||
|
d.get("credit"), d.get("voucher_type"), d.get("voucher_no"),
|
||||||
|
get_voucher_link(d.get("voucher_type"), d.get("voucher_no")),
|
||||||
|
d.get("against"), d.get("cost_center"), d.get("remarks")])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_voucher_link(voucher_type, voucher_no):
|
||||||
|
icon = ""
|
||||||
|
if voucher_type and voucher_no:
|
||||||
|
icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;">
|
||||||
|
</i></a>""" % ("/".join(["#Form", voucher_type, voucher_no]))
|
||||||
|
|
||||||
|
return icon
|
||||||
|
@ -28,7 +28,7 @@ class DocType:
|
|||||||
})
|
})
|
||||||
|
|
||||||
def validate_time_log_is_submitted(self, tl):
|
def validate_time_log_is_submitted(self, tl):
|
||||||
if tl.status != "Submitted":
|
if tl.status != "Submitted" and self.doc.docstatus == 0:
|
||||||
webnotes.msgprint(_("Time Log must have status 'Submitted'") + \
|
webnotes.msgprint(_("Time Log must have status 'Submitted'") + \
|
||||||
" :" + tl.name + " (" + _(tl.status) + ")", raise_exception=True)
|
" :" + tl.name + " (" + _(tl.status) + ")", raise_exception=True)
|
||||||
|
|
||||||
@ -58,6 +58,3 @@ class DocType:
|
|||||||
tl.doc.time_log_batch = time_log_batch
|
tl.doc.time_log_batch = time_log_batch
|
||||||
tl.doc.sales_invoice = self.doc.sales_invoice
|
tl.doc.sales_invoice = self.doc.sales_invoice
|
||||||
tl.update_after_submit()
|
tl.update_after_submit()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -288,11 +288,12 @@ class DocType(StockController):
|
|||||||
if not returnable_qty:
|
if not returnable_qty:
|
||||||
webnotes.throw("{item}: {item_code} {returned}".format(
|
webnotes.throw("{item}: {item_code} {returned}".format(
|
||||||
item=_("Item"), item_code=item.item_code,
|
item=_("Item"), item_code=item.item_code,
|
||||||
returned=_("already returned though some other documents")), StockOverReturnError)
|
returned=_("already returned though some other documents")),
|
||||||
|
StockOverReturnError)
|
||||||
elif item.transfer_qty > returnable_qty:
|
elif item.transfer_qty > returnable_qty:
|
||||||
webnotes.throw("{item}: {item_code}, {returned}: {qty}".format(
|
webnotes.throw("{item}: {item_code}, {returned}: {qty}".format(
|
||||||
item=_("Item"), item_code=item.item_code,
|
item=_("Item"), item_code=item.item_code,
|
||||||
returned=_("Max Returnable Qty"), qty=returnable_qty))
|
returned=_("Max Returnable Qty"), qty=returnable_qty), StockOverReturnError)
|
||||||
|
|
||||||
def get_already_returned_item_qty(self, ref_fieldname):
|
def get_already_returned_item_qty(self, ref_fieldname):
|
||||||
return dict(webnotes.conn.sql("""select item_code, sum(transfer_qty) as qty
|
return dict(webnotes.conn.sql("""select item_code, sum(transfer_qty) as qty
|
||||||
|
Loading…
x
Reference in New Issue
Block a user