fixes for base_rate, base_amount, tax_amount: mass search and replace

This commit is contained in:
Nabin Hait 2015-02-23 16:58:30 +05:30
parent 37b047d9a8
commit 82e3e25cdb
20 changed files with 113 additions and 91 deletions

View File

@ -275,36 +275,36 @@ class PurchaseInvoice(BuyingController):
# tax table gl entries # tax table gl entries
valuation_tax = {} valuation_tax = {}
for tax in self.get("taxes"): for tax in self.get("taxes"):
if tax.category in ("Total", "Valuation and Total") and flt(tax.tax_amount): if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": tax.account_head, "account": tax.account_head,
"against": self.credit_to, "against": self.credit_to,
"debit": tax.add_deduct_tax == "Add" and tax.tax_amount or 0, "debit": tax.add_deduct_tax == "Add" and tax.base_tax_amount_after_discount_amount or 0,
"credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0, "credit": tax.add_deduct_tax == "Deduct" and tax.base_tax_amount_after_discount_amount or 0,
"remarks": self.remarks, "remarks": self.remarks,
"cost_center": tax.cost_center "cost_center": tax.cost_center
}) })
) )
# accumulate valuation tax # accumulate valuation tax
if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount): if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
if auto_accounting_for_stock and not tax.cost_center: if auto_accounting_for_stock and not tax.cost_center:
frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category))) frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
valuation_tax.setdefault(tax.cost_center, 0) valuation_tax.setdefault(tax.cost_center, 0)
valuation_tax[tax.cost_center] += \ valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount) (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
# item gl entries # item gl entries
negative_expense_to_be_booked = 0.0 negative_expense_to_be_booked = 0.0
stock_items = self.get_stock_items() stock_items = self.get_stock_items()
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_amount): if flt(item.base_net_amount):
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": item.expense_account, "account": item.expense_account,
"against": self.credit_to, "against": self.credit_to,
"debit": item.base_amount, "debit": item.base_net_amount,
"remarks": self.remarks, "remarks": self.remarks,
"cost_center": item.cost_center "cost_center": item.cost_center
}) })

View File

@ -496,12 +496,12 @@ class SalesInvoice(SellingController):
def make_tax_gl_entries(self, gl_entries): def make_tax_gl_entries(self, gl_entries):
for tax in self.get("taxes"): for tax in self.get("taxes"):
if flt(tax.tax_amount_after_discount_amount): if flt(tax.base_tax_amount_after_discount_amount):
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": tax.account_head, "account": tax.account_head,
"against": self.debit_to, "against": self.debit_to,
"credit": flt(tax.tax_amount_after_discount_amount), "credit": flt(tax.base_tax_amount_after_discount_amount),
"remarks": self.remarks, "remarks": self.remarks,
"cost_center": tax.cost_center "cost_center": tax.cost_center
}) })
@ -510,12 +510,12 @@ class SalesInvoice(SellingController):
def make_item_gl_entries(self, gl_entries): def make_item_gl_entries(self, gl_entries):
# income account gl entries # income account gl entries
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_amount): if flt(item.base_net_amount):
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": item.income_account, "account": item.income_account,
"against": self.debit_to, "against": self.debit_to,
"credit": item.base_amount, "credit": item.base_net_amount,
"remarks": self.remarks, "remarks": self.remarks,
"cost_center": item.cost_center "cost_center": item.cost_center
}) })

View File

@ -95,7 +95,7 @@ class GrossProfitGenerator(object):
if self.skip_row(row, self.sales_boms): if self.skip_row(row, self.sales_boms):
continue continue
row.selling_amount = flt(row.base_amount) row.selling_amount = flt(row.base_net_amount)
sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.name, frappe._dict()) sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.name, frappe._dict())
@ -175,7 +175,7 @@ class GrossProfitGenerator(object):
# sorted by posting_date desc, posting_time desc # sorted by posting_date desc, posting_time desc
if item_code in self.non_stock_items: if item_code in self.non_stock_items:
# average purchasing rate for non-stock items # average purchasing rate for non-stock items
item_rate = frappe.db.sql("""select sum(base_amount) / sum(qty) item_rate = frappe.db.sql("""select sum(base_net_amount) / sum(qty)
from `tabPurchase Invoice Item` from `tabPurchase Invoice Item`
where item_code = %s and docstatus=1""", item_code) where item_code = %s and docstatus=1""", item_code)
@ -211,7 +211,7 @@ class GrossProfitGenerator(object):
si.customer, si.customer_group, si.territory, si.customer, si.customer_group, si.territory,
item.item_code, item.item_name, item.description, item.warehouse, item.item_code, item.item_name, item.description, item.warehouse,
item.item_group, item.brand, item.dn_detail, item.delivery_note, item.item_group, item.brand, item.dn_detail, item.delivery_note,
item.qty, item.base_rate, item.base_amount, item.name as "item_row", item.qty, item.base_net_rate, item.base_net_amount, item.name as "item_row",
sales.sales_person, sales.sales_designation, sales.allocated_amount, sales.sales_person, sales.sales_designation, sales.allocated_amount,
sales.incentives sales.incentives
from `tabSales Invoice` si from `tabSales Invoice` si

View File

@ -28,13 +28,13 @@ def execute(filters=None):
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, d.supplier, 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,
purchase_receipt, expense_account, d.qty, d.base_rate, d.base_amount] purchase_receipt, expense_account, d.qty, d.base_net_rate, d.base_net_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))
total_tax = sum(row[last_col:]) total_tax = sum(row[last_col:])
row += [total_tax, d.base_amount + total_tax] row += [total_tax, d.base_net_amount + total_tax]
data.append(row) data.append(row)
@ -70,7 +70,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.base_net_total, pi_item.item_code, pi_item.item_name, pi_item.item_group, pi.supplier, pi.remarks, pi.base_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.po_detail 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_net_rate, pi_item.base_net_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
order by pi.posting_date desc, pi_item.item_code desc""" % (conditions, match_conditions), filters, as_dict=1) order by pi.posting_date desc, pi_item.item_code desc""" % (conditions, match_conditions), filters, as_dict=1)
@ -86,7 +86,7 @@ def get_tax_accounts(item_list, columns):
for d in item_list: for d in item_list:
invoice_wise_items.setdefault(d.parent, []).append(d) 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 tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, base_tax_amount_after_discount_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(invoice_wise_items)), tuple(invoice_wise_items.keys())) and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)), tuple(invoice_wise_items.keys()))
@ -107,7 +107,7 @@ def get_tax_accounts(item_list, columns):
elif charge_type == "Actual" and tax_amount: elif charge_type == "Actual" and tax_amount:
for d in invoice_wise_items.get(parent, []): for d in invoice_wise_items.get(parent, []):
item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \ item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
(tax_amount * d.base_amount) / d.base_net_total (tax_amount * d.base_net_amount) / d.base_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]

View File

@ -26,13 +26,13 @@ def execute(filters=None):
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.customer, d.customer_name, 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, 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] delivery_note, d.income_account, d.qty, d.base_net_rate, d.base_net_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))
total_tax = sum(row[last_col:]) total_tax = sum(row[last_col:])
row += [total_tax, d.base_amount + total_tax] row += [total_tax, d.base_net_amount + total_tax]
data.append(row) data.append(row)
@ -69,7 +69,7 @@ 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.base_net_total, si_item.item_code, si_item.item_name, si.customer, si.remarks, si.territory, si.company, si.base_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_net_rate, si_item.base_net_amount, si.customer_name,
si.customer_group, si_item.so_detail 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
@ -83,7 +83,8 @@ def get_tax_accounts(item_list, columns):
for d in item_list: for d in item_list:
invoice_wise_items.setdefault(d.parent, []).append(d) 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 tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail,
charge_type, base_tax_amount_after_discount_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(invoice_wise_items)), and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)),
@ -104,7 +105,7 @@ def get_tax_accounts(item_list, columns):
elif charge_type == "Actual" and tax_amount: elif charge_type == "Actual" and tax_amount:
for d in invoice_wise_items.get(parent, []): for d in invoice_wise_items.get(parent, []):
item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \ item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
flt((tax_amount * d.base_amount) / d.base_net_total) flt((tax_amount * d.base_net_amount) / d.base_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]

View File

@ -114,7 +114,7 @@ def get_invoices(filters):
def get_invoice_expense_map(invoice_list): def get_invoice_expense_map(invoice_list):
expense_details = frappe.db.sql("""select parent, expense_account, sum(base_amount) as amount expense_details = frappe.db.sql("""select parent, expense_account, sum(base_net_amount) as amount
from `tabPurchase Invoice Item` where parent in (%s) group by parent, expense_account""" % from `tabPurchase Invoice Item` where parent in (%s) group by parent, expense_account""" %
', '.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)
@ -126,7 +126,7 @@ def get_invoice_expense_map(invoice_list):
return invoice_expense_map return invoice_expense_map
def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts): def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
tax_details = frappe.db.sql("""select parent, account_head, sum(tax_amount) as tax_amount tax_details = frappe.db.sql("""select parent, account_head, sum(base_tax_amount_after_discount_amount) as tax_amount
from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" % from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" %
', '.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)

View File

@ -78,7 +78,7 @@ def get_columns(invoice_list):
tax_accounts = frappe.db.sql_list("""select distinct account_head tax_accounts = frappe.db.sql_list("""select distinct account_head
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice' from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
and docstatus = 1 and ifnull(tax_amount_after_discount_amount, 0) != 0 and docstatus = 1 and ifnull(base_tax_amount_after_discount_amount, 0) != 0
and parent in (%s) order by account_head""" % and parent in (%s) order by account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list])) ', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
@ -113,7 +113,7 @@ def get_invoices(filters):
conditions, filters, as_dict=1) conditions, filters, as_dict=1)
def get_invoice_income_map(invoice_list): def get_invoice_income_map(invoice_list):
income_details = frappe.db.sql("""select parent, income_account, sum(base_amount) as amount income_details = frappe.db.sql("""select parent, income_account, sum(base_net_amount) as amount
from `tabSales Invoice Item` where parent in (%s) group by parent, income_account""" % from `tabSales Invoice Item` where parent in (%s) group by parent, income_account""" %
', '.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)
@ -126,7 +126,7 @@ def get_invoice_income_map(invoice_list):
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts): def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
tax_details = frappe.db.sql("""select parent, account_head, tax_details = frappe.db.sql("""select parent, account_head,
sum(tax_amount_after_discount_amount) as tax_amount sum(base_tax_amount_after_discount_amount) as tax_amount
from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" % from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" %
', '.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)

View File

@ -209,7 +209,7 @@ erpnext.PurchaseAnalytics = frappe.views.TreeGridReport.extend({
if (posting_date >= from_date && posting_date <= to_date) { if (posting_date >= from_date && posting_date <= to_date) {
var item = me.item_by_name[tl[me.tree_grid.item_key]] || var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
me.item_by_name['Not Set']; me.item_by_name['Not Set'];
item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty); item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
} }
} }
}); });

View File

@ -94,16 +94,16 @@ class BuyingController(StockController):
for d in self.get(parentfield): for d in self.get(parentfield):
if d.item_code and d.item_code in stock_items: if d.item_code and d.item_code in stock_items:
stock_items_qty += flt(d.qty) stock_items_qty += flt(d.qty)
stock_items_amount += flt(d.base_amount) stock_items_amount += flt(d.base_net_amount)
last_stock_item_idx = d.idx last_stock_item_idx = d.idx
total_valuation_amount = sum([flt(d.tax_amount) for d in self.get("taxes") total_valuation_amount = sum([flt(d.base_tax_amount_after_discount_amount) for d in self.get("taxes")
if d.category in ["Valuation", "Valuation and Total"]]) if d.category in ["Valuation", "Valuation and Total"]])
valuation_amount_adjustment = total_valuation_amount valuation_amount_adjustment = total_valuation_amount
for i, item in enumerate(self.get(parentfield)): for i, item in enumerate(self.get(parentfield)):
if item.item_code and item.qty and item.item_code in stock_items: if item.item_code and item.qty and item.item_code in stock_items:
item_proportion = flt(item.base_amount) / stock_items_amount if stock_items_amount \ item_proportion = flt(item.base_net_amount) / stock_items_amount if stock_items_amount \
else flt(item.qty) / stock_items_qty else flt(item.qty) / stock_items_qty
if i == (last_stock_item_idx - 1): if i == (last_stock_item_idx - 1):
@ -124,7 +124,7 @@ class BuyingController(StockController):
landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \ landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \
if self.doctype == "Purchase Receipt" else 0.0 if self.doctype == "Purchase Receipt" else 0.0
item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + rm_supp_cost
+ landed_cost_voucher_amount) / qty_in_stock_uom) + landed_cost_voucher_amount) / qty_in_stock_uom)
else: else:
item.valuation_rate = 0.0 item.valuation_rate = 0.0

View File

@ -132,9 +132,9 @@ def period_wise_columns_query(filters, trans):
else: else:
pwc = [_(filters.get("fiscal_year")) + " ("+_("Qty") + "):Float:120", pwc = [_(filters.get("fiscal_year")) + " ("+_("Qty") + "):Float:120",
_(filters.get("fiscal_year")) + " ("+ _("Amt") + "):Currency:120"] _(filters.get("fiscal_year")) + " ("+ _("Amt") + "):Currency:120"]
query_details = " SUM(t2.qty), SUM(t2.base_amount)," query_details = " SUM(t2.qty), SUM(t2.base_net_amount),"
query_details += 'SUM(t2.qty), SUM(t2.base_amount)' query_details += 'SUM(t2.qty), SUM(t2.base_net_amount)'
return pwc, query_details return pwc, query_details
def get_period_wise_columns(bet_dates, period, pwc): def get_period_wise_columns(bet_dates, period, pwc):
@ -147,7 +147,7 @@ def get_period_wise_columns(bet_dates, period, pwc):
def get_period_wise_query(bet_dates, trans_date, query_details): def get_period_wise_query(bet_dates, trans_date, query_details):
query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)), query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)),
SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_amount, NULL)), SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_net_amount, NULL)),
""" % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]}
return query_details return query_details

View File

@ -13,19 +13,19 @@ def execute(filters=None):
data = [] data = []
for project in proj_details: for project in proj_details:
data.append([project.name, pr_item_map.get(project.name, 0), data.append([project.name, pr_item_map.get(project.name, 0),
se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0), se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0),
project.project_name, project.status, project.company, project.project_name, project.status, project.company,
project.customer, project.project_value, project.project_start_date, project.customer, project.project_value, project.project_start_date,
project.completion_date]) project.completion_date])
return columns, data return columns, data
def get_columns(): def get_columns():
return [_("Project Id") + ":Link/Project:140", _("Cost of Purchased Items") + ":Currency:160", return [_("Project Id") + ":Link/Project:140", _("Cost of Purchased Items") + ":Currency:160",
_("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160", _("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160",
_("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100", _("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100",
_("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120", _("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120",
_("Project Start Date") + ":Date:120", _("Completion Date") + ":Date:120"] _("Project Start Date") + ":Date:120", _("Completion Date") + ":Date:120"]
def get_project_details(): def get_project_details():
@ -33,8 +33,8 @@ def get_project_details():
project_start_date, completion_date from tabProject where docstatus < 2""", as_dict=1) project_start_date, completion_date from tabProject where docstatus < 2""", as_dict=1)
def get_purchased_items_cost(): def get_purchased_items_cost():
pr_items = frappe.db.sql("""select project_name, sum(base_amount) as amount pr_items = frappe.db.sql("""select project_name, sum(base_net_amount) as amount
from `tabPurchase Receipt Item` where ifnull(project_name, '') != '' from `tabPurchase Receipt Item` where ifnull(project_name, '') != ''
and docstatus = 1 group by project_name""", as_dict=1) and docstatus = 1 group by project_name""", as_dict=1)
pr_item_map = {} pr_item_map = {}
@ -46,7 +46,7 @@ def get_purchased_items_cost():
def get_issued_items_cost(): def get_issued_items_cost():
se_items = frappe.db.sql("""select se.project_name, sum(se_item.amount) as amount se_items = frappe.db.sql("""select se.project_name, sum(se_item.amount) as amount
from `tabStock Entry` se, `tabStock Entry Detail` se_item from `tabStock Entry` se, `tabStock Entry Detail` se_item
where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = '' where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = ''
and ifnull(se.project_name, '') != '' group by se.project_name""", as_dict=1) and ifnull(se.project_name, '') != '' group by se.project_name""", as_dict=1)
se_item_map = {} se_item_map = {}
@ -56,14 +56,14 @@ def get_issued_items_cost():
return se_item_map return se_item_map
def get_delivered_items_cost(): def get_delivered_items_cost():
dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_amount) as amount dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_net_amount) as amount
from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item
where dn.name = dn_item.parent and dn.docstatus = 1 and ifnull(dn.project_name, '') != '' where dn.name = dn_item.parent and dn.docstatus = 1 and ifnull(dn.project_name, '') != ''
group by dn.project_name""", as_dict=1) group by dn.project_name""", as_dict=1)
si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_amount) as amount si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_net_amount) as amount
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 and ifnull(si.update_stock, 0) = 1 where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1
and ifnull(si.is_pos, 0) = 1 and ifnull(si.project_name, '') != '' and ifnull(si.is_pos, 0) = 1 and ifnull(si.project_name, '') != ''
group by si.project_name""", as_dict=1) group by si.project_name""", as_dict=1)
@ -75,4 +75,4 @@ def get_delivered_items_cost():
for item in si_items: for item in si_items:
dn_item_map.setdefault(item.project_name, item.amount) dn_item_map.setdefault(item.project_name, item.amount)
return dn_item_map return dn_item_map

View File

@ -111,34 +111,54 @@ erpnext.feature_setup.feature_dict = {
'Sales Order': {'items':['page_break']} 'Sales Order': {'items':['page_break']}
}, },
'fs_exports': { 'fs_exports': {
'Delivery Note': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}, 'Delivery Note': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'POS Setting': {'fields':['conversion_rate','currency']}, 'POS Setting': {'fields':['conversion_rate','currency']},
'Quotation': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}, 'Quotation': {
'Sales Invoice': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}, 'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Sales Invoice': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Sales BOM': {'fields':['currency']}, 'Sales BOM': {'fields':['currency']},
'Sales Order': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']} 'Sales Order': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
}
}, },
'fs_imports': { 'fs_imports': {
'Purchase Invoice': { 'Purchase Invoice': {
'fields': ['conversion_rate', 'currency', 'base_grand_total', 'fields': ['conversion_rate', 'currency', 'base_grand_total', 'base_discount_amount',
'base_in_words', 'base_net_total', 'base_taxes_and_charges_added', 'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added',
'base_taxes_and_charges_deducted'], 'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate', 'base_amount','base_rate'] 'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount']
}, },
'Purchase Order': { 'Purchase Order': {
'fields': ['conversion_rate','currency', 'base_grand_total', 'fields': ['conversion_rate','currency', 'base_grand_total', 'base_discount_amount',
'base_in_words', 'base_net_total', 'base_taxes_and_charges_added', 'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added',
'base_taxes_and_charges_deducted'], 'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate', 'base_amount','base_rate'] 'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount']
}, },
'Purchase Receipt': { 'Purchase Receipt': {
'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total',
'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted'], 'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted',
'items': ['base_price_list_rate','base_amount','base_rate'] 'base_total_taxes_and_charges', 'base_discount_amount'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
}, },
'Supplier Quotation': { 'Supplier Quotation': {
'fields':['conversion_rate','currency'] 'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total',
'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted',
'base_total_taxes_and_charges', 'base_discount_amount'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
} }
}, },

View File

@ -204,7 +204,7 @@ erpnext.SalesAnalytics = frappe.views.TreeGridReport.extend({
if (posting_date >= from_date && posting_date <= to_date) { if (posting_date >= from_date && posting_date <= to_date) {
var item = me.item_by_name[tl[me.tree_grid.item_key]] || var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
me.item_by_name['Not Set']; me.item_by_name['Not Set'];
item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty); item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
} }
} }
}); });

View File

@ -82,7 +82,7 @@ def get_target_distribution_details(filters):
def get_achieved_details(filters): def get_achieved_details(filters):
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:] start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date, item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date,
st.sales_person, MONTHNAME(so.transaction_date) as month_name st.sales_person, MONTHNAME(so.transaction_date) as month_name
from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st
where soi.parent=so.name and so.docstatus=1 and where soi.parent=so.name and so.docstatus=1 and
@ -125,7 +125,7 @@ def get_salesperson_item_month_map(filters):
if (filters["target_on"] == "Amount"): if (filters["target_on"] == "Amount"):
tav_dict.target = flt(sd.target_amount) * month_percentage / 100 tav_dict.target = flt(sd.target_amount) * month_percentage / 100
if ad.month_name == month: if ad.month_name == month:
tav_dict.achieved += ad.base_amount tav_dict.achieved += ad.base_net_amount
return sim_map return sim_map

View File

@ -16,7 +16,7 @@ def execute(filters=None):
data.append([ data.append([
d.name, d.customer, d.territory, d.posting_date, d.item_code, d.name, d.customer, d.territory, d.posting_date, d.item_code,
item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"), item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
d.qty, d.base_amount, d.sales_person, d.allocated_percentage, d.contribution_amt d.qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
]) ])
return columns, data return columns, data
@ -36,8 +36,8 @@ def get_entries(filters):
date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date" date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date"
conditions, items = get_conditions(filters, date_field) conditions, items = get_conditions(filters, date_field)
entries = frappe.db.sql("""select dt.name, dt.customer, dt.territory, dt.%s as posting_date, entries = frappe.db.sql("""select dt.name, dt.customer, dt.territory, dt.%s as posting_date,
dt_item.item_code, dt_item.qty, dt_item.base_amount, st.sales_person, dt_item.item_code, dt_item.qty, dt_item.base_net_amount, st.sales_person,
st.allocated_percentage, dt_item.base_amount*st.allocated_percentage/100 as contribution_amt st.allocated_percentage, dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt
from `tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st from `tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st
where st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s where st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
and dt.docstatus = 1 %s order by st.sales_person, dt.name desc""" % and dt.docstatus = 1 %s order by st.sales_person, dt.name desc""" %

View File

@ -5,7 +5,6 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe import _, msgprint from frappe import _, msgprint
from frappe.utils import flt from frappe.utils import flt
import time
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year
from erpnext.controllers.trends import get_period_date_ranges, get_period_month_ranges from erpnext.controllers.trends import get_period_date_ranges, get_period_month_ranges
@ -81,7 +80,7 @@ def get_target_distribution_details(filters):
def get_achieved_details(filters): def get_achieved_details(filters):
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:] start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date, item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date,
so.territory, MONTHNAME(so.transaction_date) as month_name so.territory, MONTHNAME(so.transaction_date) as month_name
from `tabSales Order Item` soi, `tabSales Order` so from `tabSales Order Item` soi, `tabSales Order` so
where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and
@ -125,7 +124,7 @@ def get_territory_item_month_map(filters):
if (filters["target_on"] == "Amount"): if (filters["target_on"] == "Amount"):
tav_dict.target = flt(td.target_amount) * month_percentage / 100 tav_dict.target = flt(td.target_amount) * month_percentage / 100
if ad.month_name == month: if ad.month_name == month:
tav_dict.achieved += ad.base_amount tav_dict.achieved += ad.base_net_amount
return tim_map return tim_map

View File

@ -141,7 +141,7 @@ def decorate_quotation_doc(quotation_doc):
d["formatted_amount"] = fmt_money(d.get("amount"), currency=doc.currency) d["formatted_amount"] = fmt_money(d.get("amount"), currency=doc.currency)
for d in doc.get("taxes", []): for d in doc.get("taxes", []):
d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount")) / doc.conversion_rate, d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount_after_discount_amount")),
currency=doc.currency) currency=doc.currency)
doc.formatted_grand_total_export = fmt_money(doc.grand_total, doc.formatted_grand_total_export = fmt_money(doc.grand_total,

View File

@ -174,7 +174,7 @@ data_map = {
} }
}, },
"Sales Invoice Item": { "Sales Invoice Item": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"], "columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent", "order_by": "parent",
"links": { "links": {
@ -192,7 +192,7 @@ data_map = {
} }
}, },
"Sales Order Item[Sales Analytics]": { "Sales Order Item[Sales Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"], "columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent", "order_by": "parent",
"links": { "links": {
@ -210,7 +210,7 @@ data_map = {
} }
}, },
"Delivery Note Item[Sales Analytics]": { "Delivery Note Item[Sales Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"], "columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent", "order_by": "parent",
"links": { "links": {
@ -242,7 +242,7 @@ data_map = {
} }
}, },
"Purchase Invoice Item": { "Purchase Invoice Item": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"], "columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent", "order_by": "parent",
"links": { "links": {
@ -260,7 +260,7 @@ data_map = {
} }
}, },
"Purchase Order Item[Purchase Analytics]": { "Purchase Order Item[Purchase Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"], "columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent", "order_by": "parent",
"links": { "links": {
@ -278,7 +278,7 @@ data_map = {
} }
}, },
"Purchase Receipt Item[Purchase Analytics]": { "Purchase Receipt Item[Purchase Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"], "columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent", "order_by": "parent",
"links": { "links": {

View File

@ -295,7 +295,7 @@ class PurchaseReceipt(BuyingController):
"cost_center": d.cost_center, "cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"), "remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor), "debit": flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
self.precision("base_amount", d)) self.precision("base_net_amount", d))
})) }))
# stock received but not billed # stock received but not billed
@ -304,7 +304,7 @@ class PurchaseReceipt(BuyingController):
"against": warehouse_account[d.warehouse], "against": warehouse_account[d.warehouse],
"cost_center": d.cost_center, "cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"), "remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(d.base_amount, self.precision("base_amount", d)) "credit": flt(d.base_net_amount, self.precision("base_net_amount", d))
})) }))
negative_expense_to_be_booked += flt(d.item_tax_amount) negative_expense_to_be_booked += flt(d.item_tax_amount)
@ -332,12 +332,12 @@ class PurchaseReceipt(BuyingController):
# divisional loss adjustment # divisional loss adjustment
if not self.get("other_charges"): if not self.get("other_charges"):
sle_valuation_amount = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor), sle_valuation_amount = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
self.precision("base_amount", d)) self.precision("base_net_amount", d))
distributed_amount = flt(flt(d.base_amount, self.precision("base_amount", d))) + \ distributed_amount = flt(flt(d.base_net_amount, self.precision("base_net_amount", d))) + \
flt(d.landed_cost_voucher_amount) + flt(d.rm_supp_cost) flt(d.landed_cost_voucher_amount) + flt(d.rm_supp_cost)
divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_amount", d)) divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_net_amount", d))
if divisional_loss: if divisional_loss:
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": stock_rbnb, "account": stock_rbnb,
@ -354,12 +354,12 @@ class PurchaseReceipt(BuyingController):
# Cost center-wise amount breakup for other charges included for valuation # Cost center-wise amount breakup for other charges included for valuation
valuation_tax = {} valuation_tax = {}
for tax in self.get("taxes"): for tax in self.get("taxes"):
if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount): if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
if not tax.cost_center: if not tax.cost_center:
frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category))) frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
valuation_tax.setdefault(tax.cost_center, 0) valuation_tax.setdefault(tax.cost_center, 0)
valuation_tax[tax.cost_center] += \ valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount) (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
if negative_expense_to_be_booked and valuation_tax: if negative_expense_to_be_booked and valuation_tax:
# Backward compatibility: # Backward compatibility:

View File

@ -170,6 +170,8 @@ def get_basic_details(args, item):
"base_rate": 0.0, "base_rate": 0.0,
"amount": 0.0, "amount": 0.0,
"base_amount": 0.0, "base_amount": 0.0,
"net_rate": 0.0,
"net_amount": 0.0,
"discount_percentage": 0.0 "discount_percentage": 0.0
}) })