mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
merge
This commit is contained in:
@@ -66,6 +66,6 @@ class DocType:
|
||||
vouchers.append(d.voucher_id)
|
||||
|
||||
if vouchers:
|
||||
msgprint("Clearance Date updated in %s" % vouchers)
|
||||
msgprint("Clearance Date updated in %s" % ", ".join(vouchers))
|
||||
else:
|
||||
msgprint("Clearance Date not mentioned")
|
||||
@@ -43,6 +43,8 @@ class DocType(AccountsController):
|
||||
if not self.doc.is_opening:
|
||||
self.doc.is_opening='No'
|
||||
|
||||
self.doc.clearance_date = None
|
||||
|
||||
self.validate_debit_credit()
|
||||
self.validate_cheque_info()
|
||||
self.validate_entries_for_advance()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-03-26 11:03:07",
|
||||
"creation": "2013-04-30 12:58:25",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-03-26 12:48:18",
|
||||
"modified": "2013-05-03 14:36:24",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -40,6 +40,7 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "user",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "User",
|
||||
"oldfieldname": "user",
|
||||
"oldfieldtype": "Link",
|
||||
@@ -99,6 +100,7 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Company",
|
||||
"oldfieldname": "company",
|
||||
"oldfieldtype": "Link",
|
||||
@@ -210,12 +212,6 @@
|
||||
"oldfieldtype": "Select",
|
||||
"options": "link:Print Heading"
|
||||
},
|
||||
{
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
"role": "System Manager",
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-03-26 06:51:12",
|
||||
"creation": "2013-04-19 11:00:06",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-04-17 14:05:19",
|
||||
"modified": "2013-05-07 11:23:56",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -35,6 +35,7 @@
|
||||
"oldfieldname": "category",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Valuation and Total\nValuation\nTotal",
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -45,6 +46,7 @@
|
||||
"oldfieldname": "charge_type",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "\nActual\nOn Net Total\nOn Previous Row Amount\nOn Previous Row Total",
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -55,6 +57,7 @@
|
||||
"oldfieldname": "account_head",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Account",
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -65,7 +68,8 @@
|
||||
"label": "Cost Center",
|
||||
"oldfieldname": "cost_center",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Cost Center"
|
||||
"options": "Cost Center",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@@ -75,17 +79,18 @@
|
||||
"oldfieldname": "description",
|
||||
"oldfieldtype": "Small Text",
|
||||
"print_width": "300px",
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"width": "300px"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "rate",
|
||||
"fieldtype": "Currency",
|
||||
"fieldtype": "Float",
|
||||
"label": "Rate",
|
||||
"oldfieldname": "rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 0,
|
||||
"reqd": 0
|
||||
},
|
||||
{
|
||||
@@ -96,6 +101,7 @@
|
||||
"oldfieldname": "tax_amount",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 0,
|
||||
"reqd": 0
|
||||
},
|
||||
{
|
||||
@@ -115,7 +121,8 @@
|
||||
"hidden": 0,
|
||||
"label": "Enter Row",
|
||||
"oldfieldname": "row_id",
|
||||
"oldfieldtype": "Data"
|
||||
"oldfieldtype": "Data",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"default": "Add",
|
||||
@@ -126,6 +133,7 @@
|
||||
"oldfieldname": "add_deduct_tax",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Add\nDeduct",
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -149,6 +157,7 @@
|
||||
"oldfieldname": "parenttype",
|
||||
"oldfieldtype": "Data",
|
||||
"print_hide": 1,
|
||||
"read_only": 0,
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
@@ -163,6 +172,7 @@
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 0,
|
||||
"report_hide": 1
|
||||
},
|
||||
{
|
||||
@@ -177,6 +187,7 @@
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 0,
|
||||
"report_hide": 1
|
||||
}
|
||||
]
|
||||
@@ -45,7 +45,7 @@ class DocType(SellingController):
|
||||
|
||||
def validate(self):
|
||||
super(DocType, self).validate()
|
||||
|
||||
self.fetch_missing_values()
|
||||
self.validate_posting_time()
|
||||
self.so_dn_required()
|
||||
self.validate_proj_cust()
|
||||
@@ -137,7 +137,27 @@ class DocType(SellingController):
|
||||
def on_update_after_submit(self):
|
||||
self.validate_recurring_invoice()
|
||||
self.convert_to_recurring()
|
||||
|
||||
|
||||
def fetch_missing_values(self):
|
||||
# fetch contact and address details for customer, if they are not mentioned
|
||||
if not (self.doc.contact_person and self.doc.customer_address):
|
||||
for fieldname, val in self.get_default_address_and_contact("customer").items():
|
||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
||||
self.doc.fields[fieldname] = val
|
||||
|
||||
# fetch missing item values
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
if item.fields.get("item_code"):
|
||||
ret = get_obj('Sales Common').get_item_details(item.fields, self)
|
||||
for fieldname, value in ret.items():
|
||||
if self.meta.get_field(fieldname, parentfield="entries") and \
|
||||
not item.fields.get(fieldname):
|
||||
item.fields[fieldname] = value
|
||||
|
||||
# fetch pos details, if they are not fetched
|
||||
if cint(self.doc.is_pos):
|
||||
self.set_pos_fields(for_validate=True)
|
||||
|
||||
def update_time_log_batch(self, sales_invoice):
|
||||
for d in self.doclist.get({"doctype":"Sales Invoice Item"}):
|
||||
if d.time_log_batch:
|
||||
@@ -153,60 +173,42 @@ class DocType(SellingController):
|
||||
webnotes.msgprint(_("Time Log Batch status must be 'Submitted'") + ":" + d.time_log_batch,
|
||||
raise_exception=True)
|
||||
|
||||
def set_pos_fields(self):
|
||||
def set_pos_fields(self, for_validate=False):
|
||||
"""Set retail related fields from pos settings"""
|
||||
pos = self.pos_details
|
||||
|
||||
if pos:
|
||||
val = webnotes.conn.sql("""select name from `tabAccount`
|
||||
where name = %s and docstatus != 2""",
|
||||
(cstr(self.doc.customer) + " - " + self.get_company_abbr()))
|
||||
|
||||
val = val and val[0][0] or ''
|
||||
if not val: val = pos[0]['customer_account'] or ''
|
||||
if cint(self.doc.is_pos) != 1:
|
||||
return
|
||||
|
||||
if self.pos_settings:
|
||||
pos = self.pos_settings[0]
|
||||
|
||||
self.doc.conversion_rate = flt(pos.conversion_rate)
|
||||
|
||||
if not self.doc.debit_to:
|
||||
webnotes.conn.set(self.doc,'debit_to',val)
|
||||
|
||||
lst = ['territory', 'naming_series', 'currency', 'charge', 'letter_head', 'tc_name',
|
||||
'price_list_name', 'company', 'select_print_heading', 'cash_bank_account']
|
||||
self.doc.debit_to = self.doc.customer and webnotes.conn.get_value("Account", {
|
||||
"name": self.doc.customer + " - " + self.get_company_abbr(),
|
||||
"docstatus": ["!=", 2]
|
||||
}) or pos.customer_account
|
||||
|
||||
for i in lst:
|
||||
self.doc.fields[i] = pos[0][i] or ''
|
||||
for fieldname in ('territory', 'naming_series', 'currency', 'charge', 'letter_head', 'tc_name',
|
||||
'price_list_name', 'company', 'select_print_heading', 'cash_bank_account'):
|
||||
if (not for_validate) or (for_validate and not self.doc.fields.get(fieldname)):
|
||||
self.doc.fields[fieldname] = pos.get(fieldname)
|
||||
|
||||
self.set_pos_item_values()
|
||||
|
||||
self.doc.conversion_rate = flt(pos[0]['conversion_rate']) or 0
|
||||
# set pos values in items
|
||||
for doc in self.doclist.get({"parentfield": "entries"}):
|
||||
if doc.fields.get('item_code'):
|
||||
for fieldname, val in self.apply_pos_settings(doc.fields).items():
|
||||
if (not for_validate) or (for_validate and not self.doc.fields.get(fieldname)):
|
||||
doc.fields[fieldname] = val
|
||||
|
||||
#fetch terms
|
||||
if self.doc.tc_name:
|
||||
# fetch terms
|
||||
if self.doc.tc_name and not self.doc.terms:
|
||||
self.get_tc_details()
|
||||
|
||||
#fetch charges
|
||||
if self.doc.charge:
|
||||
# fetch charges
|
||||
if self.doc.charge and not len(self.doclist.get({"parentfield": "other_charges"})):
|
||||
self.get_other_charges()
|
||||
|
||||
|
||||
def set_pos_item_values(self):
|
||||
"""Set default values related to pos for previously created sales invoice."""
|
||||
if cint(self.doc.is_pos) == 1:
|
||||
dtl = self.pos_details
|
||||
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
# overwrite if mentioned in item
|
||||
item = webnotes.conn.sql("""select default_income_account,
|
||||
default_sales_cost_center, default_warehouse, purchase_account
|
||||
from tabItem where name = %s""", (d.item_code,), as_dict=1)
|
||||
|
||||
d.income_account = (item and item[0]['default_income_account']) \
|
||||
or (dtl and dtl[0]['income_account']) or d.income_account
|
||||
d.cost_center = (item and item[0]['default_sales_cost_center']) \
|
||||
or (dtl and dtl[0]['cost_center']) or d.cost_center
|
||||
d.warehouse = (item and item[0]['default_warehouse']) \
|
||||
or (dtl and dtl[0]['warehouse']) or d.warehouse
|
||||
d.expense_account = (item and item[0].purchase_account) \
|
||||
or (dtl and dtl[0].expense_account) or d.expense_account
|
||||
|
||||
def get_customer_account(self):
|
||||
"""Get Account Head to which amount needs to be Debited based on Customer"""
|
||||
if not self.doc.company:
|
||||
@@ -299,60 +301,59 @@ class DocType(SellingController):
|
||||
args = args and json.loads(args) or {}
|
||||
if args.get('item_code'):
|
||||
ret = get_obj('Sales Common').get_item_details(args, self)
|
||||
return self.get_pos_details(args, ret)
|
||||
else:
|
||||
for doc in self.doclist:
|
||||
|
||||
if cint(self.doc.is_pos) == 1 and self.pos_settings:
|
||||
ret = self.apply_pos_settings(args, ret)
|
||||
|
||||
return ret
|
||||
|
||||
elif cint(self.doc.is_pos) == 1 and self.pos_settings:
|
||||
for doc in self.doclist.get({"parentfield": "entries"}):
|
||||
if doc.fields.get('item_code'):
|
||||
arg = {
|
||||
'item_code':doc.fields.get('item_code'),
|
||||
'income_account':doc.fields.get('income_account'),
|
||||
'cost_center': doc.fields.get('cost_center'),
|
||||
'warehouse': doc.fields.get('warehouse'),
|
||||
'expense_account': doc.fields.get('expense_account'),
|
||||
}
|
||||
|
||||
ret = self.get_pos_details(arg)
|
||||
ret = self.apply_pos_settings(doc.fields)
|
||||
for r in ret:
|
||||
if not doc.fields.get(r):
|
||||
doc.fields[r] = ret[r]
|
||||
|
||||
@property
|
||||
def pos_details(self):
|
||||
if not hasattr(self, "_pos_details"):
|
||||
def pos_settings(self):
|
||||
if not hasattr(self, "_pos_settings"):
|
||||
dtl = webnotes.conn.sql("""select * from `tabPOS Setting` where user = %s
|
||||
and company = %s""", (webnotes.session['user'], self.doc.company), as_dict=1)
|
||||
if not dtl:
|
||||
dtl = webnotes.conn.sql("""select * from `tabPOS Setting`
|
||||
where ifnull(user,'') = '' and company = %s""", self.doc.company, as_dict=1)
|
||||
self._pos_details = dtl
|
||||
self._pos_settings = dtl
|
||||
|
||||
return self._pos_details
|
||||
return self._pos_settings
|
||||
|
||||
def get_pos_details(self, args, ret = {}):
|
||||
if args['item_code'] and cint(self.doc.is_pos) == 1:
|
||||
dtl = self.pos_details
|
||||
|
||||
item = webnotes.conn.sql("""select default_income_account, default_sales_cost_center,
|
||||
default_warehouse, purchase_account from tabItem where name = %s""",
|
||||
args['item_code'], as_dict=1)
|
||||
|
||||
ret['income_account'] = item and item[0].get('default_income_account') \
|
||||
or (dtl and dtl[0].get('income_account') or args.get('income_account'))
|
||||
|
||||
ret['cost_center'] = item and item[0].get('default_sales_cost_center') \
|
||||
or (dtl and dtl[0].get('cost_center') or args.get('cost_center'))
|
||||
def apply_pos_settings(self, args, ret=None):
|
||||
if not ret: ret = {}
|
||||
|
||||
pos = self.pos_settings[0]
|
||||
|
||||
item = webnotes.conn.sql("""select default_income_account, default_sales_cost_center,
|
||||
default_warehouse, purchase_account from tabItem where name = %s""",
|
||||
args.get('item_code'), as_dict=1)
|
||||
|
||||
if item:
|
||||
item = item[0]
|
||||
|
||||
ret['warehouse'] = item and item[0].get('default_warehouse') \
|
||||
or (dtl and dtl[0].get('warehouse') or args.get('warehouse'))
|
||||
ret.update({
|
||||
"income_account": item.get("default_income_account") \
|
||||
or pos.get("income_account") or args.get("income_account"),
|
||||
"cost_center": item.get("default_sales_cost_center") \
|
||||
or pos.get("cost_center") or args.get("cost_center"),
|
||||
"warehouse": item.get("default_warehouse") \
|
||||
or pos.get("warehouse") or args.get("warehouse"),
|
||||
"expense_account": item.get("purchase_account") \
|
||||
or pos.get("expense_account") or args.get("expense_account")
|
||||
})
|
||||
|
||||
ret['expense_account'] = item and item[0].get('purchase_account') \
|
||||
or (dtl and dtl[0].get('expense_account') or args.get('expense_account'))
|
||||
|
||||
if ret['warehouse']:
|
||||
actual_qty = webnotes.conn.sql("""select actual_qty from `tabBin`
|
||||
where item_code = %s and warehouse = %s""",
|
||||
(args['item_code'], ret['warehouse']))
|
||||
ret['actual_qty']= actual_qty and flt(actual_qty[0][0]) or 0
|
||||
if ret.get("warehouse"):
|
||||
ret["actual_qty"] = flt(webnotes.conn.get_value("Bin",
|
||||
{"item_code": args.get("item_code"), "warehouse": args.get("warehouse")},
|
||||
"actual_qty"))
|
||||
return ret
|
||||
|
||||
def get_barcode_details(self, barcode):
|
||||
|
||||
@@ -90,6 +90,9 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
|
||||
old_default_company = webnotes.conn.get_default("company")
|
||||
webnotes.conn.set_default("company", "_Test Company")
|
||||
|
||||
self._insert_purchase_receipt()
|
||||
self._insert_pos_settings()
|
||||
|
||||
@@ -106,7 +109,8 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
# check stock ledger entries
|
||||
sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry`
|
||||
where voucher_type = 'Sales Invoice' and voucher_no = %s""", si.doc.name, as_dict=1)[0]
|
||||
where voucher_type = 'Sales Invoice' and voucher_no = %s""",
|
||||
si.doc.name, as_dict=1)[0]
|
||||
self.assertTrue(sle)
|
||||
self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
|
||||
["_Test Item", "_Test Warehouse", -5.0])
|
||||
@@ -145,6 +149,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
self.assertEquals(gl_count[0][0], 16)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
webnotes.conn.set_default("company", old_default_company)
|
||||
|
||||
def test_sales_invoice_gl_entry_with_aii_no_item_code(self):
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
@@ -337,7 +342,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
# change posting date but keep recuring day to be today
|
||||
si7 = webnotes.bean(copy=base_si.doclist)
|
||||
si7.doc.fields.update({
|
||||
"posting_date": add_to_date(today, days=-3)
|
||||
"posting_date": add_to_date(today, days=-1)
|
||||
})
|
||||
si7.insert()
|
||||
si7.submit()
|
||||
@@ -345,7 +350,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
# setting so that _test function works
|
||||
si7.doc.posting_date = today
|
||||
self._test_recurring_invoice(si7, True)
|
||||
|
||||
|
||||
def _test_recurring_invoice(self, base_si, first_and_last_day):
|
||||
from webnotes.utils import add_months, get_last_day, getdate
|
||||
from accounts.doctype.sales_invoice.sales_invoice import manage_recurring_invoices
|
||||
@@ -361,7 +366,8 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
manage_recurring_invoices(next_date=next_date, commit=False)
|
||||
|
||||
recurred_invoices = webnotes.conn.sql("""select name from `tabSales Invoice`
|
||||
where recurring_id=%s and docstatus=1 order by name desc""", base_si.doc.recurring_id)
|
||||
where recurring_id=%s and docstatus=1 order by name desc""",
|
||||
base_si.doc.recurring_id)
|
||||
|
||||
self.assertEquals(i+2, len(recurred_invoices))
|
||||
|
||||
@@ -395,7 +401,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
for i in xrange(count):
|
||||
base_si = _test(i)
|
||||
|
||||
test_dependencies = ["Journal Voucher", "POS Setting"]
|
||||
test_dependencies = ["Journal Voucher", "POS Setting", "Contact", "Address"]
|
||||
|
||||
test_records = [
|
||||
[
|
||||
|
||||
@@ -217,6 +217,11 @@ wn.module_page["Accounts"] = [
|
||||
route: "query-report/Payment Made With Ageing",
|
||||
doctype: "Journal Voucher"
|
||||
},
|
||||
{
|
||||
"label":wn._("Sales Partners Commission"),
|
||||
route: "query-report/Sales Partners Commission",
|
||||
doctype: "Sales Invoice"
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -20,9 +20,10 @@ from webnotes.utils import flt
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
columns, expense_accounts, tax_accounts = get_columns()
|
||||
|
||||
|
||||
invoice_list = get_invoices(filters)
|
||||
columns, expense_accounts, tax_accounts = get_columns(invoice_list)
|
||||
|
||||
invoice_expense_map = get_invoice_expense_map(invoice_list)
|
||||
invoice_tax_map = get_invoice_tax_map(invoice_list)
|
||||
invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
|
||||
@@ -55,7 +56,7 @@ def execute(filters=None):
|
||||
return columns, data
|
||||
|
||||
|
||||
def get_columns():
|
||||
def get_columns(invoice_list):
|
||||
"""return columns based on filters"""
|
||||
columns = [
|
||||
"Invoice:Link/Purchase Invoice:120", "Posting Date:Date:80", "Supplier:Link/Supplier:120",
|
||||
@@ -66,10 +67,14 @@ def get_columns():
|
||||
|
||||
expense_accounts = webnotes.conn.sql_list("""select distinct expense_head
|
||||
from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(expense_head, '') != ''
|
||||
order by expense_head""")
|
||||
and parent in (%s) order by expense_head""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||
|
||||
tax_accounts = webnotes.conn.sql_list("""select distinct account_head
|
||||
from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice'
|
||||
and docstatus = 1 and ifnull(account_head, '') != '' order by account_head""")
|
||||
and docstatus = 1 and ifnull(account_head, '') != '' and parent in (%s)
|
||||
order by account_head""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||
|
||||
columns = columns + [(account + ":Currency:120") for account in expense_accounts] + \
|
||||
["Net Total:Currency:120"] + [(account + ":Currency:120") for account in tax_accounts] + \
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-05-06 12:28:23",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-05-06 12:41:15",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"is_standard": "Yes",
|
||||
"name": "__common__",
|
||||
"query": "SELECT\n sales_partner as \"Sales Partner:Link/Sales Partner:150\",\n\tsum(net_total) as \"Invoiced Amount (Exculsive Tax):Currency:210\",\n\tsum(total_commission) as \"Total Commission:Currency:150\",\n\tsum(total_commission)*100/sum(net_total) as \"Average Commission Rate:Currency:170\"\nFROM\n\t`tabSales Invoice`\nWHERE\n\tdocstatus = 1 and ifnull(net_total, 0) > 0 and ifnull(total_commission, 0) > 0\nGROUP BY\n\tsales_partner\nORDER BY\n\t\"Total Commission:Currency:120\"",
|
||||
"ref_doctype": "Sales Invoice",
|
||||
"report_name": "Sales Partners Commission",
|
||||
"report_type": "Query Report"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"name": "Sales Partners Commission"
|
||||
}
|
||||
]
|
||||
@@ -20,9 +20,10 @@ from webnotes.utils import flt
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
columns, income_accounts, tax_accounts = get_columns()
|
||||
|
||||
invoice_list = get_invoices(filters)
|
||||
columns, income_accounts, tax_accounts = get_columns(invoice_list)
|
||||
|
||||
invoice_income_map = get_invoice_income_map(invoice_list)
|
||||
invoice_tax_map = get_invoice_tax_map(invoice_list)
|
||||
|
||||
@@ -59,7 +60,7 @@ def execute(filters=None):
|
||||
return columns, data
|
||||
|
||||
|
||||
def get_columns():
|
||||
def get_columns(invoice_list):
|
||||
"""return columns based on filters"""
|
||||
columns = [
|
||||
"Invoice:Link/Sales Invoice:120", "Posting Date:Date:80", "Customer:Link/Customer:120",
|
||||
@@ -69,11 +70,14 @@ def get_columns():
|
||||
]
|
||||
|
||||
income_accounts = webnotes.conn.sql_list("""select distinct income_account
|
||||
from `tabSales Invoice Item` where docstatus = 1 order by income_account""")
|
||||
from `tabSales Invoice Item` where docstatus = 1 and parent in (%s)
|
||||
order by income_account""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||
|
||||
tax_accounts = webnotes.conn.sql_list("""select distinct account_head
|
||||
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
|
||||
and docstatus = 1 order by account_head""")
|
||||
and docstatus = 1 and parent in (%s) order by account_head""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||
|
||||
columns = columns + [(account + ":Currency:120") for account in income_accounts] + \
|
||||
["Net Total:Currency:120"] + [(account + ":Currency:120") for account in tax_accounts] + \
|
||||
|
||||
Reference in New Issue
Block a user