[report] Item-wise Sales Register [issue] webnotes/erpnext#372

This commit is contained in:
Anand Doshi 2013-07-26 13:09:23 +05:30
parent 5491332772
commit ac90542414
2 changed files with 63 additions and 21 deletions

View File

@ -1,10 +1,10 @@
wn.query_reports["Item-wise Sales Register"] = {
wn.query_reports["Item-wise Sales Register"] = wn.query_reports["Sales Register"] = {
"filters": [
{
"fieldname":"from_date",
"label": "From Date",
"fieldtype": "Date",
"default": wn.defaults.get_user_default("year_start_date"),
"default": wn.defaults.get_default("year_start_date"),
"width": "80"
},
{
@ -13,27 +13,30 @@ wn.query_reports["Item-wise Sales Register"] = {
"fieldtype": "Date",
"default": get_today()
},
{
"fieldname": "item_code",
"label": "Item",
"fieldtype": "Link",
"options": "Item",
},
{
"fieldname":"account",
"label": "Account",
"fieldtype": "Link",
"options": "Account",
"get_query": function() {
var company = wn.query_report.filters_by_name.company.get_value();
return {
"query": "accounts.utils.get_account_list",
"filters": {
"is_pl_account": "No",
"debit_or_credit": "Debit",
"company": company,
"master_type": "Customer"
}
}
}
},
{
"fieldname":"company",
"label": "Company",
"fieldtype": "Link",
"options": "Company",
"default": wn.defaults.get_default("company")
}
]
}

View File

@ -16,22 +16,30 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt
def execute(filters=None):
if not filters: filters = {}
columns = get_columns()
last_col = len(columns) - 1
item_list = get_items(filters)
item_tax, tax_accounts = get_tax_accounts(item_list, columns)
data = []
for d in item_list:
data.append([d.item_code, d.item_name, d.item_group, d.name, d.posting_date,
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date,
d.customer_name, d.debit_to, d.territory, d.project_name, d.company, d.sales_order,
d.delivery_note, d.income_account, d.qty, d.basic_rate, d.amount])
d.delivery_note, d.income_account, d.qty, d.basic_rate, d.amount]
for tax in tax_accounts:
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
row.append(sum(row[last_col:]))
data.append(row)
return columns, data
def get_columns():
return [
"Item Code:Link/Item:120", "Item Name::120", "Item Group:Link/Item Group:100",
@ -46,21 +54,52 @@ def get_columns():
def get_conditions(filters):
conditions = ""
if filters.get("account"): conditions += " and si.debit_to = %(account)s"
if filters.get("item_code"): conditions += " and si_item.item_code = %(item_code)s"
if filters.get("from_date"): conditions += " and si.posting_date>=%(from_date)s"
if filters.get("to_date"): conditions += " and si.posting_date<=%(to_date)s"
for opts in (("company", " and company=%(company)s"),
("account", " and si.debit_to = %(account)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")):
if filters.get(opts[0]):
conditions += opts[1]
return conditions
def get_items(filters):
conditions = get_conditions(filters)
return webnotes.conn.sql("""select si.name, si.posting_date, si.debit_to, si.project_name,
return webnotes.conn.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_item.item_group, si_item.sales_order, si_item.delivery_note, si_item.income_account,
si_item.qty, si_item.basic_rate, si_item.amount, si.customer_name
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)
order by si.posting_date desc, si_item.item_code desc""" % conditions, filters, as_dict=1)
def get_tax_accounts(item_list, columns):
import json
item_tax = {}
tax_accounts = []
tax_details = webnotes.conn.sql("""select parent, account_head, item_wise_tax_detail
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
and docstatus = 1 and ifnull(account_head, '') != ''
and parent in (%s)""" % ', '.join(['%s']*len(item_list)), tuple([item.parent for item in item_list]))
for parent, account_head, item_wise_tax_detail in tax_details:
if account_head not in tax_accounts:
tax_accounts.append(account_head)
invoice = item_tax.setdefault(parent, {})
if item_wise_tax_detail:
try:
item_wise_tax_detail = json.loads(item_wise_tax_detail)
for item, tax_amount in item_wise_tax_detail.items():
invoice.setdefault(item, {})[account_head] = flt(tax_amount)
except ValueError:
continue
tax_accounts.sort()
columns += [account_head + ":Currency:80" for account_head in tax_accounts]
columns.append("Total:Currency:80")
return item_tax, tax_accounts