Fix in Sales Register for multiple mode of payments
This commit is contained in:
parent
d12990ff57
commit
aac32d644d
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt
|
||||
from erpnext.accounts.report.sales_register.sales_register import get_mode_of_payments
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
@ -21,6 +22,7 @@ def execute(filters=None):
|
||||
"width": 80
|
||||
})
|
||||
company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
|
||||
mode_of_payments = get_mode_of_payments(set([d.parent for d in item_list]))
|
||||
|
||||
data = []
|
||||
for d in item_list:
|
||||
@ -32,7 +34,8 @@ def execute(filters=None):
|
||||
from `tabDelivery Note Item` where docstatus=1 and so_detail=%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.mode_of_payment, d.territory, d.project, d.company, d.sales_order,
|
||||
d.customer_group, d.debit_to, ", ".join(mode_of_payments.get(d.parent, [])),
|
||||
d.territory, d.project, d.company, d.sales_order,
|
||||
delivery_note, d.income_account, d.cost_center, d.qty, d.base_net_rate, d.base_net_amount]
|
||||
|
||||
for tax in tax_accounts:
|
||||
@ -52,7 +55,7 @@ def get_columns():
|
||||
_("Posting Date") + ":Date:80", _("Customer") + ":Link/Customer:120",
|
||||
_("Customer Name") + "::120", _("Customer Group") + ":Link/Customer Group:120",
|
||||
_("Receivable Account") + ":Link/Account:120",
|
||||
_("Mode of Payment") + ":Link/Mode of Payment:80", _("Territory") + ":Link/Territory:80",
|
||||
_("Mode of Payment") + "::120", _("Territory") + ":Link/Territory:80",
|
||||
_("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", _("Cost Center") + ":Link/Cost Center:140",
|
||||
@ -68,10 +71,14 @@ def get_conditions(filters):
|
||||
("customer", " and si.customer = %(customer)s"),
|
||||
("item_code", " and si_item.item_code = %(item_code)s"),
|
||||
("from_date", " and si.posting_date>=%(from_date)s"),
|
||||
("to_date", " and si.posting_date<=%(to_date)s"),
|
||||
("mode_of_payment", " and ifnull(mode_of_payment, '') = %(mode_of_payment)s")):
|
||||
("to_date", " and si.posting_date<=%(to_date)s")):
|
||||
if filters.get(opts[0]):
|
||||
conditions += opts[1]
|
||||
|
||||
if filters.get("mode_of_payment"):
|
||||
conditions += """ and exists(select name from `tabSales Invoice Payment`
|
||||
where parent=si.name
|
||||
and ifnull(`tabSales Invoice Payment`.mode_of_payment, '') = %(mode_of_payment)s)"""
|
||||
|
||||
return conditions
|
||||
|
||||
@ -84,7 +91,7 @@ def get_items(filters):
|
||||
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.cost_center, si_item.qty,
|
||||
si_item.base_net_rate, si_item.base_net_amount, si.customer_name,
|
||||
si.customer_group, si_item.so_detail, si.mode_of_payment
|
||||
si.customer_group, si_item.so_detail
|
||||
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
|
||||
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)
|
||||
|
@ -23,6 +23,7 @@ def execute(filters=None):
|
||||
invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
|
||||
customer_map = get_customer_deatils(invoice_list)
|
||||
company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
|
||||
mode_of_payments = get_mode_of_payments([inv.name for inv in invoice_list])
|
||||
|
||||
data = []
|
||||
for inv in invoice_list:
|
||||
@ -33,7 +34,7 @@ def execute(filters=None):
|
||||
row = [inv.name, inv.posting_date, inv.customer, inv.customer_name,
|
||||
customer_map.get(inv.customer, {}).get("customer_group"),
|
||||
customer_map.get(inv.customer, {}).get("territory"),
|
||||
inv.debit_to, inv.mode_of_payment, inv.project, inv.remarks,
|
||||
inv.debit_to, ", ".join(mode_of_payments.get(inv.name, [])), inv.project, inv.remarks,
|
||||
", ".join(sales_order), ", ".join(delivery_note), company_currency]
|
||||
|
||||
# map income values
|
||||
@ -68,7 +69,7 @@ def get_columns(invoice_list):
|
||||
_("Invoice") + ":Link/Sales Invoice:120", _("Posting Date") + ":Date:80",
|
||||
_("Customer Id") + "::120", _("Customer Name") + "::120",
|
||||
_("Customer Group") + ":Link/Customer Group:120", _("Territory") + ":Link/Territory:80",
|
||||
_("Receivable Account") + ":Link/Account:120", _("Mode of Payment") + ":Link/Mode of Payment:80",
|
||||
_("Receivable Account") + ":Link/Account:120", _("Mode of Payment") + "::120",
|
||||
_("Project") +":Link/Project:80", _("Remarks") + "::150",
|
||||
_("Sales Order") + ":Link/Sales Order:100", _("Delivery Note") + ":Link/Delivery Note:100",
|
||||
{
|
||||
@ -113,8 +114,11 @@ def get_conditions(filters):
|
||||
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("mode_of_payment"): conditions += " and ifnull(mode_of_payment, '') = %(mode_of_payment)s"
|
||||
|
||||
if filters.get("mode_of_payment"):
|
||||
conditions += """ and exists(select name from `tabSales Invoice Payment`
|
||||
where parent=`tabSales Invoice`.name
|
||||
and ifnull(`tabSales Invoice Payment`.mode_of_payment, '') = %(mode_of_payment)s)"""
|
||||
|
||||
return conditions
|
||||
|
||||
def get_invoices(filters):
|
||||
@ -188,3 +192,15 @@ def get_customer_deatils(invoice_list):
|
||||
customer_map.setdefault(cust.name, cust)
|
||||
|
||||
return customer_map
|
||||
|
||||
|
||||
def get_mode_of_payments(invoice_list):
|
||||
mode_of_payments = {}
|
||||
inv_mop = frappe.db.sql("""select parent, mode_of_payment
|
||||
from `tabSales Invoice Payment` where parent in (%s) group by parent, mode_of_payment""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple(invoice_list), as_dict=1)
|
||||
|
||||
for d in inv_mop:
|
||||
mode_of_payments.setdefault(d.parent, []).append(d.mode_of_payment)
|
||||
|
||||
return mode_of_payments
|
Loading…
Reference in New Issue
Block a user