mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 04:39:11 +00:00
Sales/purchase register and item-wise sales/purchase register fixes for party
Show Delivery Note and Purchase Receipt based on SO and PO if it not defined in SI/PI #2166
This commit is contained in:
@@ -23,21 +23,10 @@ frappe.query_reports["Item-wise Purchase Register"] = {
|
|||||||
"options": "Item",
|
"options": "Item",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"account",
|
"fieldname":"supplier",
|
||||||
"label": __("Account"),
|
"label": __("Supplier"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Account",
|
"options": "Supplier"
|
||||||
"get_query": function() {
|
|
||||||
var company = frappe.query_report.filters_by_name.company.get_value();
|
|
||||||
return {
|
|
||||||
"query": "erpnext.controllers.queries.get_account_list",
|
|
||||||
"filters": {
|
|
||||||
"report_type": "Balance Sheet",
|
|
||||||
"company": company,
|
|
||||||
"master_type": "Supplier"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"company",
|
"fieldname":"company",
|
||||||
|
|||||||
@@ -18,10 +18,17 @@ def execute(filters=None):
|
|||||||
|
|
||||||
data = []
|
data = []
|
||||||
for d in item_list:
|
for d in item_list:
|
||||||
|
purchase_receipt = None
|
||||||
|
if d.purchase_receipt:
|
||||||
|
purchase_receipt = d.purchase_receipt
|
||||||
|
elif d.po_detail:
|
||||||
|
purchase_receipt = ", ".join(frappe.db.sql_list("""select distinct parent
|
||||||
|
from `tabPurchase Receipt Item` where docstatus=1 and prevdoc_detail_docname=%s""", d.po_detail))
|
||||||
|
|
||||||
expense_account = d.expense_account or aii_account_map.get(d.company)
|
expense_account = d.expense_account or aii_account_map.get(d.company)
|
||||||
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date,
|
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.supplier,
|
||||||
d.supplier_name, d.credit_to, d.project_name, d.company, d.purchase_order,
|
d.supplier_name, d.credit_to, d.project_name, d.company, d.purchase_order,
|
||||||
d.purchase_receipt, expense_account, d.qty, d.base_rate, d.base_amount]
|
purchase_receipt, expense_account, d.qty, d.base_rate, d.base_amount]
|
||||||
for tax in tax_accounts:
|
for tax in tax_accounts:
|
||||||
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
|
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
|
||||||
|
|
||||||
@@ -34,18 +41,19 @@ def execute(filters=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
return [_("Item Code") + ":Link/Item:120", _("Item Name") + "::120", _("Item Group") + ":Link/Item Group:100",
|
return [_("Item Code") + ":Link/Item:120", _("Item Name") + "::120",
|
||||||
_("Invoice") + ":Link/Purchase Invoice:120", _("Posting Date") + ":Date:80", _("Supplier") + ":Link/Customer:120",
|
_("Item Group") + ":Link/Item Group:100", _("Invoice") + ":Link/Purchase Invoice:120",
|
||||||
_("Supplier Account") + ":Link/Account:120", _("Project") + ":Link/Project:80", _("Company") + ":Link/Company:100",
|
_("Posting Date") + ":Date:80", _("Supplier") + ":Link/Supplier:120",
|
||||||
_("Purchase Order") + ":Link/Purchase Order:100", _("Purchase Receipt") + ":Link/Purchase Receipt:100",
|
"Supplier Name::120", "Payable Account:Link/Account:120", _("Project") + ":Link/Project:80",
|
||||||
_("Expense Account") + ":Link/Account:140", _("Qty") + ":Float:120", _("Rate") + ":Currency:120",
|
_("Company") + ":Link/Company:100", _("Purchase Order") + ":Link/Purchase Order:100",
|
||||||
_("Amount") + ":Currency:120"]
|
_("Purchase Receipt") + ":Link/Purchase Receipt:100", _("Expense Account") + ":Link/Account:140",
|
||||||
|
_("Qty") + ":Float:120", _("Rate") + ":Currency:120", _("Amount") + ":Currency:120"]
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_conditions(filters):
|
||||||
conditions = ""
|
conditions = ""
|
||||||
|
|
||||||
for opts in (("company", " and company=%(company)s"),
|
for opts in (("company", " and company=%(company)s"),
|
||||||
("account", " and pi.credit_to = %(account)s"),
|
("supplier", " and pi.supplier = %(supplier)s"),
|
||||||
("item_code", " and pi_item.item_code = %(item_code)s"),
|
("item_code", " and pi_item.item_code = %(item_code)s"),
|
||||||
("from_date", " and pi.posting_date>=%(from_date)s"),
|
("from_date", " and pi.posting_date>=%(from_date)s"),
|
||||||
("to_date", " and pi.posting_date<=%(to_date)s")):
|
("to_date", " and pi.posting_date<=%(to_date)s")):
|
||||||
@@ -60,7 +68,7 @@ def get_items(filters):
|
|||||||
|
|
||||||
return frappe.db.sql("""select pi_item.parent, pi.posting_date, pi.credit_to, pi.company,
|
return frappe.db.sql("""select pi_item.parent, pi.posting_date, pi.credit_to, pi.company,
|
||||||
pi.supplier, pi.remarks, pi_item.item_code, pi_item.item_name, pi_item.item_group,
|
pi.supplier, pi.remarks, pi_item.item_code, pi_item.item_name, pi_item.item_group,
|
||||||
pi_item.project_name, pi_item.purchase_order, pi_item.purchase_receipt,
|
pi_item.project_name, pi_item.purchase_order, pi_item.purchase_receipt, pi_item.po_detail,
|
||||||
pi_item.expense_account, pi_item.qty, pi_item.base_rate, pi_item.base_amount, pi.supplier_name
|
pi_item.expense_account, pi_item.qty, pi_item.base_rate, pi_item.base_amount, pi.supplier_name
|
||||||
from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` pi_item
|
from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` pi_item
|
||||||
where pi.name = pi_item.parent and pi.docstatus = 1 %s %s
|
where pi.name = pi_item.parent and pi.docstatus = 1 %s %s
|
||||||
|
|||||||
@@ -17,21 +17,10 @@ frappe.query_reports["Item-wise Sales Register"] = frappe.query_reports["Sales R
|
|||||||
"default": get_today()
|
"default": get_today()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"account",
|
"fieldname":"customer",
|
||||||
"label": __("Account"),
|
"label": __("Customer"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Account",
|
"options": "Customer"
|
||||||
"get_query": function() {
|
|
||||||
var company = frappe.query_report.filters_by_name.company.get_value();
|
|
||||||
return {
|
|
||||||
"query": "erpnext.controllers.queries.get_account_list",
|
|
||||||
"filters": {
|
|
||||||
"report_type": "Balance Sheet",
|
|
||||||
"company": company,
|
|
||||||
"master_type": "Customer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"company",
|
"fieldname":"company",
|
||||||
|
|||||||
@@ -17,9 +17,16 @@ def execute(filters=None):
|
|||||||
|
|
||||||
data = []
|
data = []
|
||||||
for d in item_list:
|
for d in item_list:
|
||||||
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date,
|
delivery_note = None
|
||||||
d.customer_name, d.debit_to, d.territory, d.project_name, d.company, d.sales_order,
|
if d.delivery_note:
|
||||||
d.delivery_note, d.income_account, d.qty, d.base_rate, d.base_amount]
|
delivery_note = d.delivery_note
|
||||||
|
elif d.so_detail:
|
||||||
|
delivery_note = ", ".join(frappe.db.sql_list("""select distinct parent
|
||||||
|
from `tabDelivery Note Item` where docstatus=1 and prevdoc_detail_docname=%s""", d.so_detail))
|
||||||
|
|
||||||
|
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.customer, d.customer_name,
|
||||||
|
d.customer_group, d.debit_to, d.territory, d.project_name, d.company, d.sales_order,
|
||||||
|
delivery_note, d.income_account, d.qty, d.base_rate, d.base_amount]
|
||||||
|
|
||||||
for tax in tax_accounts:
|
for tax in tax_accounts:
|
||||||
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
|
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
|
||||||
@@ -33,19 +40,22 @@ def execute(filters=None):
|
|||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
return [
|
return [
|
||||||
_("Item Code") + ":Link/Item:120", _("Item Name") + "::120", _("Item Group") + ":Link/Item Group:100",
|
_("Item Code") + ":Link/Item:120", _("Item Name") + "::120",
|
||||||
_("Invoice") + ":Link/Sales Invoice:120", _("Posting Date") + ":Date:80", _("Customer") + ":Link/Customer:120",
|
_("Item Group") + ":Link/Item Group:100", _("Invoice") + ":Link/Sales Invoice:120",
|
||||||
_("Customer Account") + ":Link/Account:120", _("Territory") + ":Link/Territory:80",
|
_("Posting Date") + ":Date:80", _("Customer") + ":Link/Customer:120",
|
||||||
_("Project") + ":Link/Project:80", _("Company") + ":Link/Company:100", _("Sales Order") + ":Link/Sales Order:100",
|
_("Customer Name") + "::120", _("Customer Group") + ":Link/Customer Group:120",
|
||||||
_("Delivery Note") + ":Link/Delivery Note:100", _("Income Account") + ":Link/Account:140",
|
_("Receivable Account") + ":Link/Account:120", _("Territory") + ":Link/Territory:80",
|
||||||
_("Qty") + ":Float:120", _("Rate") + ":Currency:120", _("Amount") + ":Currency:120"
|
_("Project") + ":Link/Project:80", _("Company") + ":Link/Company:100",
|
||||||
|
_("Sales Order") + ":Link/Sales Order:100", _("Delivery Note") + ":Link/Delivery Note:100",
|
||||||
|
_("Income Account") + ":Link/Account:140", _("Qty") + ":Float:120",
|
||||||
|
_("Rate") + ":Currency:120", _("Amount") + ":Currency:120"
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_conditions(filters):
|
||||||
conditions = ""
|
conditions = ""
|
||||||
|
|
||||||
for opts in (("company", " and company=%(company)s"),
|
for opts in (("company", " and company=%(company)s"),
|
||||||
("account", " and si.debit_to = %(account)s"),
|
("customer", " and si.customer = %(customer)s"),
|
||||||
("item_code", " and si_item.item_code = %(item_code)s"),
|
("item_code", " and si_item.item_code = %(item_code)s"),
|
||||||
("from_date", " and si.posting_date>=%(from_date)s"),
|
("from_date", " and si.posting_date>=%(from_date)s"),
|
||||||
("to_date", " and si.posting_date<=%(to_date)s")):
|
("to_date", " and si.posting_date<=%(to_date)s")):
|
||||||
@@ -59,7 +69,8 @@ def get_items(filters):
|
|||||||
return frappe.db.sql("""select si_item.parent, si.posting_date, si.debit_to, si.project_name,
|
return frappe.db.sql("""select si_item.parent, si.posting_date, si.debit_to, si.project_name,
|
||||||
si.customer, si.remarks, si.territory, si.company, si_item.item_code, si_item.item_name,
|
si.customer, si.remarks, si.territory, si.company, si_item.item_code, si_item.item_name,
|
||||||
si_item.item_group, si_item.sales_order, si_item.delivery_note, si_item.income_account,
|
si_item.item_group, si_item.sales_order, si_item.delivery_note, si_item.income_account,
|
||||||
si_item.qty, si_item.base_rate, si_item.base_amount, si.customer_name
|
si_item.qty, si_item.base_rate, si_item.base_amount, si.customer_name,
|
||||||
|
si.customer_group, si_item.so_detail
|
||||||
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
|
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
|
||||||
where si.name = si_item.parent and si.docstatus = 1 %s
|
where si.name = si_item.parent and si.docstatus = 1 %s
|
||||||
order by si.posting_date desc, si_item.item_code desc""" % conditions, filters, as_dict=1)
|
order by si.posting_date desc, si_item.item_code desc""" % conditions, filters, as_dict=1)
|
||||||
|
|||||||
@@ -17,21 +17,10 @@ frappe.query_reports["Purchase Register"] = {
|
|||||||
"default": get_today()
|
"default": get_today()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"account",
|
"fieldname":"supplier",
|
||||||
"label": __("Account"),
|
"label": __("Supplier"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Account",
|
"options": "Supplier"
|
||||||
"get_query": function() {
|
|
||||||
var company = frappe.query_report.filters_by_name.company.get_value();
|
|
||||||
return {
|
|
||||||
"query": "erpnext.controllers.queries.get_account_list",
|
|
||||||
"filters": {
|
|
||||||
"report_type": "Balance Sheet",
|
|
||||||
"company": company,
|
|
||||||
"master_type": "Supplier"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"company",
|
"fieldname":"company",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def execute(filters=None):
|
|||||||
invoice_expense_map, invoice_tax_map = get_invoice_tax_map(invoice_list,
|
invoice_expense_map, invoice_tax_map = get_invoice_tax_map(invoice_list,
|
||||||
invoice_expense_map, expense_accounts)
|
invoice_expense_map, expense_accounts)
|
||||||
invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
|
invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
|
||||||
account_map = get_account_details(invoice_list)
|
supplier_details = get_supplier_deatils(invoice_list)
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for inv in invoice_list:
|
for inv in invoice_list:
|
||||||
@@ -30,9 +30,9 @@ def execute(filters=None):
|
|||||||
purchase_receipt = list(set(invoice_po_pr_map.get(inv.name, {}).get("purchase_receipt", [])))
|
purchase_receipt = list(set(invoice_po_pr_map.get(inv.name, {}).get("purchase_receipt", [])))
|
||||||
project_name = list(set(invoice_po_pr_map.get(inv.name, {}).get("project_name", [])))
|
project_name = list(set(invoice_po_pr_map.get(inv.name, {}).get("project_name", [])))
|
||||||
|
|
||||||
row = [inv.name, inv.posting_date, inv.supplier, inv.supplier_name, inv.credit_to,
|
row = [inv.name, inv.posting_date, inv.supplier, inv.supplier_name, supplier_details.get(inv.supplier),
|
||||||
account_map.get(inv.credit_to), ", ".join(project_name), inv.bill_no, inv.bill_date,
|
inv.credit_to, ", ".join(project_name), inv.bill_no, inv.bill_date, inv.remarks,
|
||||||
inv.remarks, ", ".join(purchase_order), ", ".join(purchase_receipt)]
|
", ".join(purchase_order), ", ".join(purchase_receipt)]
|
||||||
|
|
||||||
# map expense values
|
# map expense values
|
||||||
net_total = 0
|
net_total = 0
|
||||||
@@ -64,9 +64,8 @@ def get_columns(invoice_list):
|
|||||||
"""return columns based on filters"""
|
"""return columns based on filters"""
|
||||||
columns = [
|
columns = [
|
||||||
_("Invoice") + ":Link/Purchase Invoice:120", _("Posting Date") + ":Date:80", _("Supplier Id") + "::120",
|
_("Invoice") + ":Link/Purchase Invoice:120", _("Posting Date") + ":Date:80", _("Supplier Id") + "::120",
|
||||||
_("Supplier Name") + "::120", _("Supplier Account") + ":Link/Account:120",
|
_("Supplier Name") + "::120", _("Supplier Type") + ":Link/Supplier Type:120", _("Payable Account") + ":Link/Account:120",
|
||||||
_("Account Group") + ":Link/Account:120", _("Project") + ":Link/Project:80", _("Bill No") + "::120",
|
_("Project") + ":Link/Project:80", _("Bill No") + "::120", _("Bill Date") + ":Date:80", _("Remarks") + "::150",
|
||||||
_("Bill Date") + ":Date:80", _("Remarks") + "::150",
|
|
||||||
_("Purchase Order") + ":Link/Purchase Order:100", _("Purchase Receipt") + ":Link/Purchase Receipt:100"
|
_("Purchase Order") + ":Link/Purchase Order:100", _("Purchase Receipt") + ":Link/Purchase Receipt:100"
|
||||||
]
|
]
|
||||||
expense_accounts = tax_accounts = expense_columns = tax_columns = []
|
expense_accounts = tax_accounts = expense_columns = tax_columns = []
|
||||||
@@ -89,10 +88,9 @@ def get_columns(invoice_list):
|
|||||||
if account not in expense_accounts:
|
if account not in expense_accounts:
|
||||||
tax_columns.append(account + ":Currency:120")
|
tax_columns.append(account + ":Currency:120")
|
||||||
|
|
||||||
columns = columns + expense_columns + \
|
columns = columns + expense_columns + [_("Net Total") + ":Currency:120"] + tax_columns + \
|
||||||
["Net Total:Currency:120"] + tax_columns + \
|
[_("Total Tax") + ":Currency:120", _("Grand Total") + ":Currency:120",
|
||||||
["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \
|
_("Rounded Total") + ":Currency:120", _("Outstanding Amount") + ":Currency:120"]
|
||||||
["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"]
|
|
||||||
|
|
||||||
return columns, expense_accounts, tax_accounts
|
return columns, expense_accounts, tax_accounts
|
||||||
|
|
||||||
@@ -100,7 +98,7 @@ def get_conditions(filters):
|
|||||||
conditions = ""
|
conditions = ""
|
||||||
|
|
||||||
if filters.get("company"): conditions += " and company=%(company)s"
|
if filters.get("company"): conditions += " and company=%(company)s"
|
||||||
if filters.get("account"): conditions += " and credit_to = %(account)s"
|
if filters.get("supplier"): conditions += " and supplier = %(supplier)s"
|
||||||
|
|
||||||
if filters.get("from_date"): conditions += " and posting_date>=%(from_date)s"
|
if filters.get("from_date"): conditions += " and posting_date>=%(from_date)s"
|
||||||
if filters.get("to_date"): conditions += " and posting_date<=%(to_date)s"
|
if filters.get("to_date"): conditions += " and posting_date<=%(to_date)s"
|
||||||
@@ -109,7 +107,7 @@ def get_conditions(filters):
|
|||||||
|
|
||||||
def get_invoices(filters):
|
def get_invoices(filters):
|
||||||
conditions = get_conditions(filters)
|
conditions = get_conditions(filters)
|
||||||
return frappe.db.sql("""select name, posting_date, credit_to, supplier, supplier_name,
|
return frappe.db.sql("""select name, posting_date, credit_to, supplier, supplier_name
|
||||||
bill_no, bill_date, remarks, net_total, grand_total, outstanding_amount
|
bill_no, bill_date, remarks, net_total, grand_total, outstanding_amount
|
||||||
from `tabPurchase Invoice` where docstatus = 1 %s
|
from `tabPurchase Invoice` where docstatus = 1 %s
|
||||||
order by posting_date desc, name desc""" % conditions, filters, as_dict=1)
|
order by posting_date desc, name desc""" % conditions, filters, as_dict=1)
|
||||||
@@ -146,7 +144,7 @@ def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
|
|||||||
return invoice_expense_map, invoice_tax_map
|
return invoice_expense_map, invoice_tax_map
|
||||||
|
|
||||||
def get_invoice_po_pr_map(invoice_list):
|
def get_invoice_po_pr_map(invoice_list):
|
||||||
pi_items = frappe.db.sql("""select parent, purchase_order, purchase_receipt,
|
pi_items = frappe.db.sql("""select parent, purchase_order, purchase_receipt, po_detail
|
||||||
project_name from `tabPurchase Invoice Item` where parent in (%s)
|
project_name from `tabPurchase Invoice Item` where parent in (%s)
|
||||||
and (ifnull(purchase_order, '') != '' or ifnull(purchase_receipt, '') != '')""" %
|
and (ifnull(purchase_order, '') != '' or ifnull(purchase_receipt, '') != '')""" %
|
||||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
|
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
|
||||||
@@ -156,9 +154,17 @@ def get_invoice_po_pr_map(invoice_list):
|
|||||||
if d.purchase_order:
|
if d.purchase_order:
|
||||||
invoice_po_pr_map.setdefault(d.parent, frappe._dict()).setdefault(
|
invoice_po_pr_map.setdefault(d.parent, frappe._dict()).setdefault(
|
||||||
"purchase_order", []).append(d.purchase_order)
|
"purchase_order", []).append(d.purchase_order)
|
||||||
|
|
||||||
|
pr_list = None
|
||||||
if d.purchase_receipt:
|
if d.purchase_receipt:
|
||||||
invoice_po_pr_map.setdefault(d.parent, frappe._dict()).setdefault(
|
pr_list = [d.purchase_receipt]
|
||||||
"purchase_receipt", []).append(d.purchase_receipt)
|
elif d.po_detail:
|
||||||
|
pr_list = frappe.db.sql_list("""select distinct parent from `tabPurchase Receipt Item`
|
||||||
|
where docstatus=1 and prevdoc_detail_docname=%s""", d.pr_detail)
|
||||||
|
|
||||||
|
if pr_list:
|
||||||
|
invoice_po_pr_map.setdefault(d.parent, frappe._dict()).setdefault("purchase_receipt", pr_list)
|
||||||
|
|
||||||
if d.project_name:
|
if d.project_name:
|
||||||
invoice_po_pr_map.setdefault(d.parent, frappe._dict()).setdefault(
|
invoice_po_pr_map.setdefault(d.parent, frappe._dict()).setdefault(
|
||||||
"project_name", []).append(d.project_name)
|
"project_name", []).append(d.project_name)
|
||||||
@@ -173,3 +179,12 @@ def get_account_details(invoice_list):
|
|||||||
account_map[acc.name] = acc.parent_account
|
account_map[acc.name] = acc.parent_account
|
||||||
|
|
||||||
return account_map
|
return account_map
|
||||||
|
|
||||||
|
def get_supplier_deatils(invoice_list):
|
||||||
|
supplier_details = {}
|
||||||
|
suppliers = list(set([inv.supplier for inv in invoice_list]))
|
||||||
|
for supp in frappe.db.sql("""select name, supplier_type from `tabSupplier`
|
||||||
|
where name in (%s)""" % ", ".join(["%s"]*len(suppliers)), tuple(suppliers), as_dict=1):
|
||||||
|
supplier_details.setdefault(supp.name, supp.supplier_type)
|
||||||
|
|
||||||
|
return supplier_details
|
||||||
|
|||||||
@@ -17,21 +17,10 @@ frappe.query_reports["Sales Register"] = {
|
|||||||
"default": get_today()
|
"default": get_today()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"account",
|
"fieldname":"customer",
|
||||||
"label": __("Account"),
|
"label": __("Customer"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Account",
|
"options": "Customer"
|
||||||
"get_query": function() {
|
|
||||||
var company = frappe.query_report.filters_by_name.company.get_value();
|
|
||||||
return {
|
|
||||||
"query": "erpnext.controllers.queries.get_account_list",
|
|
||||||
"filters": {
|
|
||||||
"report_type": "Balance Sheet",
|
|
||||||
"company": company,
|
|
||||||
"master_type": "Customer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"company",
|
"fieldname":"company",
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ def execute(filters=None):
|
|||||||
|
|
||||||
invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
|
invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
|
||||||
customer_map = get_customer_deatils(invoice_list)
|
customer_map = get_customer_deatils(invoice_list)
|
||||||
account_map = get_account_details(invoice_list)
|
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for inv in invoice_list:
|
for inv in invoice_list:
|
||||||
@@ -30,9 +29,9 @@ def execute(filters=None):
|
|||||||
sales_order = list(set(invoice_so_dn_map.get(inv.name, {}).get("sales_order", [])))
|
sales_order = list(set(invoice_so_dn_map.get(inv.name, {}).get("sales_order", [])))
|
||||||
delivery_note = list(set(invoice_so_dn_map.get(inv.name, {}).get("delivery_note", [])))
|
delivery_note = list(set(invoice_so_dn_map.get(inv.name, {}).get("delivery_note", [])))
|
||||||
|
|
||||||
row = [inv.name, inv.posting_date, inv.customer, inv.customer_name, inv.debit_to,
|
row = [inv.name, inv.posting_date, inv.customer, inv.customer_name,
|
||||||
account_map.get(inv.debit_to), customer_map.get(inv.customer), inv.project_name,
|
customer_map.get(inv.customer)["customer_group"], customer_map.get(inv.customer)["territory"],
|
||||||
inv.remarks, ", ".join(sales_order), ", ".join(delivery_note)]
|
inv.debit_to, inv.project_name, inv.remarks, ", ".join(sales_order), ", ".join(delivery_note)]
|
||||||
|
|
||||||
# map income values
|
# map income values
|
||||||
net_total = 0
|
net_total = 0
|
||||||
@@ -64,8 +63,8 @@ def get_columns(invoice_list):
|
|||||||
"""return columns based on filters"""
|
"""return columns based on filters"""
|
||||||
columns = [
|
columns = [
|
||||||
_("Invoice") + ":Link/Sales Invoice:120", _("Posting Date") + ":Date:80", _("Customer Id") + "::120",
|
_("Invoice") + ":Link/Sales Invoice:120", _("Posting Date") + ":Date:80", _("Customer Id") + "::120",
|
||||||
_("Customer Name") + "::120", _("Customer Account") + ":Link/Account:120", _("Account Group") + ":Link/Account:120",
|
_("Customer Name") + "::120", _("Customer Group") + ":Link/Customer Group:120", _("Territory") + ":Link/Territory:80",
|
||||||
_("Territory") + ":Link/Territory:80", _("Project") + ":Link/Project:80", _("Remarks") + "::150",
|
_("Receivable Account") + ":Link/Account:120", _("Project") +":Link/Project:80", _("Remarks") + "::150",
|
||||||
_("Sales Order") + ":Link/Sales Order:100", _("Delivery Note") + ":Link/Delivery Note:100"
|
_("Sales Order") + ":Link/Sales Order:100", _("Delivery Note") + ":Link/Delivery Note:100"
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -88,9 +87,9 @@ def get_columns(invoice_list):
|
|||||||
if account not in income_accounts:
|
if account not in income_accounts:
|
||||||
tax_columns.append(account + ":Currency:120")
|
tax_columns.append(account + ":Currency:120")
|
||||||
|
|
||||||
columns = columns + income_columns + ["Net Total:Currency:120"] + tax_columns + \
|
columns = columns + income_columns + [_("Net Total") + ":Currency:120"] + tax_columns + \
|
||||||
["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \
|
[_("Total Tax") + ":Currency:120", _("Grand Total") + ":Currency:120",
|
||||||
["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"]
|
_("Rounded Total") + ":Currency:120", _("Outstanding Amount") + ":Currency:120"]
|
||||||
|
|
||||||
return columns, income_accounts, tax_accounts
|
return columns, income_accounts, tax_accounts
|
||||||
|
|
||||||
@@ -98,7 +97,7 @@ def get_conditions(filters):
|
|||||||
conditions = ""
|
conditions = ""
|
||||||
|
|
||||||
if filters.get("company"): conditions += " and company=%(company)s"
|
if filters.get("company"): conditions += " and company=%(company)s"
|
||||||
if filters.get("account"): conditions += " and debit_to = %(account)s"
|
if filters.get("customer"): conditions += " and customer = %(customer)s"
|
||||||
|
|
||||||
if filters.get("from_date"): conditions += " and posting_date >= %(from_date)s"
|
if filters.get("from_date"): conditions += " and posting_date >= %(from_date)s"
|
||||||
if filters.get("to_date"): conditions += " and posting_date <= %(to_date)s"
|
if filters.get("to_date"): conditions += " and posting_date <= %(to_date)s"
|
||||||
@@ -145,7 +144,7 @@ def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
|
|||||||
return invoice_income_map, invoice_tax_map
|
return invoice_income_map, invoice_tax_map
|
||||||
|
|
||||||
def get_invoice_so_dn_map(invoice_list):
|
def get_invoice_so_dn_map(invoice_list):
|
||||||
si_items = frappe.db.sql("""select parent, sales_order, delivery_note
|
si_items = frappe.db.sql("""select parent, sales_order, delivery_note, so_detail
|
||||||
from `tabSales Invoice Item` where parent in (%s)
|
from `tabSales Invoice Item` where parent in (%s)
|
||||||
and (ifnull(sales_order, '') != '' or ifnull(delivery_note, '') != '')""" %
|
and (ifnull(sales_order, '') != '' or ifnull(delivery_note, '') != '')""" %
|
||||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
|
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
|
||||||
@@ -155,26 +154,24 @@ def get_invoice_so_dn_map(invoice_list):
|
|||||||
if d.sales_order:
|
if d.sales_order:
|
||||||
invoice_so_dn_map.setdefault(d.parent, frappe._dict()).setdefault(
|
invoice_so_dn_map.setdefault(d.parent, frappe._dict()).setdefault(
|
||||||
"sales_order", []).append(d.sales_order)
|
"sales_order", []).append(d.sales_order)
|
||||||
|
|
||||||
|
delivery_note_list = None
|
||||||
if d.delivery_note:
|
if d.delivery_note:
|
||||||
invoice_so_dn_map.setdefault(d.parent, frappe._dict()).setdefault(
|
delivery_note_list = [d.delivery_note]
|
||||||
"delivery_note", []).append(d.delivery_note)
|
elif d.sales_order:
|
||||||
|
delivery_note_list = frappe.db.sql_list("""select distinct parent from `tabDelivery Note Item`
|
||||||
|
where docstatus=1 and prevdoc_detail_docname=%s""", d.so_detail)
|
||||||
|
|
||||||
|
if delivery_note_list:
|
||||||
|
invoice_so_dn_map.setdefault(d.parent, frappe._dict()).setdefault("delivery_note", delivery_note_list)
|
||||||
|
|
||||||
return invoice_so_dn_map
|
return invoice_so_dn_map
|
||||||
|
|
||||||
def get_customer_deatils(invoice_list):
|
def get_customer_deatils(invoice_list):
|
||||||
customer_map = {}
|
customer_map = {}
|
||||||
customers = list(set([inv.customer for inv in invoice_list]))
|
customers = list(set([inv.customer for inv in invoice_list]))
|
||||||
for cust in frappe.db.sql("""select name, territory from `tabCustomer`
|
for cust in frappe.db.sql("""select name, territory, customer_group from `tabCustomer`
|
||||||
where name in (%s)""" % ", ".join(["%s"]*len(customers)), tuple(customers), as_dict=1):
|
where name in (%s)""" % ", ".join(["%s"]*len(customers)), tuple(customers), as_dict=1):
|
||||||
customer_map[cust.name] = cust.territory
|
customer_map.setdefault(cust.name, cust)
|
||||||
|
|
||||||
return customer_map
|
return customer_map
|
||||||
|
|
||||||
def get_account_details(invoice_list):
|
|
||||||
account_map = {}
|
|
||||||
accounts = list(set([inv.debit_to for inv in invoice_list]))
|
|
||||||
for acc in frappe.db.sql("""select name, parent_account from tabAccount
|
|
||||||
where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
|
|
||||||
account_map[acc.name] = acc.parent_account
|
|
||||||
|
|
||||||
return account_map
|
|
||||||
Reference in New Issue
Block a user