item-wise tax distribution if amount entered in actual
This commit is contained in:
parent
0c883500bb
commit
1dc8ff5220
@ -59,7 +59,7 @@ def get_items(filters):
|
|||||||
match_conditions = frappe.build_match_conditions("Purchase Invoice")
|
match_conditions = frappe.build_match_conditions("Purchase Invoice")
|
||||||
|
|
||||||
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.net_total, 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.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
|
||||||
@ -74,12 +74,16 @@ def get_tax_accounts(item_list, columns):
|
|||||||
item_tax = {}
|
item_tax = {}
|
||||||
tax_accounts = []
|
tax_accounts = []
|
||||||
|
|
||||||
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail
|
invoice_wise_items = {}
|
||||||
|
for d in item_list:
|
||||||
|
invoice_wise_items.setdefault(d.parent, []).append(d)
|
||||||
|
|
||||||
|
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount
|
||||||
from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice'
|
from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice'
|
||||||
and docstatus = 1 and ifnull(account_head, '') != '' and category in ('Total', 'Valuation and Total')
|
and docstatus = 1 and ifnull(account_head, '') != '' and category in ('Total', 'Valuation and Total')
|
||||||
and parent in (%s)""" % ', '.join(['%s']*len(item_list)), tuple([item.parent for item in item_list]))
|
and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)), tuple(invoice_wise_items.keys()))
|
||||||
|
|
||||||
for parent, account_head, item_wise_tax_detail in tax_details:
|
for parent, account_head, item_wise_tax_detail, charge_type, tax_amount in tax_details:
|
||||||
if account_head not in tax_accounts:
|
if account_head not in tax_accounts:
|
||||||
tax_accounts.append(account_head)
|
tax_accounts.append(account_head)
|
||||||
|
|
||||||
@ -92,6 +96,10 @@ def get_tax_accounts(item_list, columns):
|
|||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
elif charge_type == "Actual" and tax_amount:
|
||||||
|
for d in invoice_wise_items.get(parent, []):
|
||||||
|
item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
|
||||||
|
(tax_amount * d.base_amount) / d.net_total
|
||||||
|
|
||||||
tax_accounts.sort()
|
tax_accounts.sort()
|
||||||
columns += [account_head + ":Currency:80" for account_head in tax_accounts]
|
columns += [account_head + ":Currency:80" for account_head in tax_accounts]
|
||||||
|
@ -57,7 +57,7 @@ def get_conditions(filters):
|
|||||||
def get_items(filters):
|
def get_items(filters):
|
||||||
conditions = get_conditions(filters)
|
conditions = get_conditions(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.net_total, 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
|
||||||
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
|
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
|
||||||
@ -69,13 +69,17 @@ def get_tax_accounts(item_list, columns):
|
|||||||
item_tax = {}
|
item_tax = {}
|
||||||
tax_accounts = []
|
tax_accounts = []
|
||||||
|
|
||||||
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail
|
invoice_wise_items = {}
|
||||||
|
for d in item_list:
|
||||||
|
invoice_wise_items.setdefault(d.parent, []).append(d)
|
||||||
|
|
||||||
|
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount
|
||||||
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
|
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
|
||||||
and docstatus = 1 and ifnull(account_head, '') != ''
|
and docstatus = 1 and ifnull(account_head, '') != ''
|
||||||
and parent in (%s)""" % ', '.join(['%s']*len(item_list)),
|
and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)),
|
||||||
tuple([item.parent for item in item_list]))
|
tuple(invoice_wise_items.keys()))
|
||||||
|
|
||||||
for parent, account_head, item_wise_tax_detail in tax_details:
|
for parent, account_head, item_wise_tax_detail, charge_type, tax_amount in tax_details:
|
||||||
if account_head not in tax_accounts:
|
if account_head not in tax_accounts:
|
||||||
tax_accounts.append(account_head)
|
tax_accounts.append(account_head)
|
||||||
|
|
||||||
@ -87,6 +91,10 @@ def get_tax_accounts(item_list, columns):
|
|||||||
flt(tax_amount[1]) if isinstance(tax_amount, list) else flt(tax_amount)
|
flt(tax_amount[1]) if isinstance(tax_amount, list) else flt(tax_amount)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
elif charge_type == "Actual" and tax_amount:
|
||||||
|
for d in invoice_wise_items.get(parent, []):
|
||||||
|
item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
|
||||||
|
flt((tax_amount * d.base_amount) / d.net_total)
|
||||||
|
|
||||||
tax_accounts.sort()
|
tax_accounts.sort()
|
||||||
columns += [account_head + ":Currency:80" for account_head in tax_accounts]
|
columns += [account_head + ":Currency:80" for account_head in tax_accounts]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user