Merge https://github.com/frappe/erpnext into purchase-invoice-fix
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 9a3b312..076cccc 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -135,8 +135,10 @@
frappe.throw(_("Item Group not mentioned in item master for item {0}").format(args.item_code))
if args.customer and not (args.customer_group and args.territory):
- args.customer_group, args.territory = frappe.db.get_value("Customer", args.customer,
- ["customer_group", "territory"])
+ customer = frappe.db.get_value("Customer", args.customer, ["customer_group", "territory"])
+ if customer:
+ args.customer_group, args.territory = customer
+
elif args.supplier and not args.supplier_type:
args.supplier_type = frappe.db.get_value("Supplier", args.supplier, "supplier_type")
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 79f433c..956dacb 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -263,10 +263,10 @@
def make_gl_entries(self):
auto_accounting_for_stock = \
cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))
-
+
stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
-
+
gl_entries = []
# parent's gl entry
@@ -319,32 +319,31 @@
"cost_center": item.cost_center
})
)
-
+
if auto_accounting_for_stock and item.item_code in stock_items and item.item_tax_amount:
# Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt
negative_expense_booked_in_pi = None
if item.purchase_receipt:
negative_expense_booked_in_pi = frappe.db.sql("""select name from `tabGL Entry`
- where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""",
+ where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""",
(item.purchase_receipt, expenses_included_in_valuation))
-
+
if not negative_expense_booked_in_pi:
gl_entries.append(
self.get_gl_dict({
"account": stock_received_but_not_billed,
"against": self.credit_to,
- "debit": flt(item.item_tax_amount),
+ "debit": flt(item.item_tax_amount, self.precision("item_tax_amount", item)),
"remarks": self.remarks or "Accounting Entry for Stock"
})
)
-
- negative_expense_to_be_booked += flt(item.item_tax_amount)
+ negative_expense_to_be_booked += flt(item.item_tax_amount, self.precision("item_tax_amount", item))
if negative_expense_to_be_booked and valuation_tax:
# credit valuation tax amount in "Expenses Included In Valuation"
# this will balance out valuation amount included in cost of goods sold
-
+
total_valuation_amount = sum(valuation_tax.values())
amount_including_divisional_loss = negative_expense_to_be_booked
i = 1
@@ -354,7 +353,7 @@
else:
applicable_amount = negative_expense_to_be_booked * (amount / total_valuation_amount)
amount_including_divisional_loss -= applicable_amount
-
+
gl_entries.append(
self.get_gl_dict({
"account": expenses_included_in_valuation,
@@ -364,7 +363,7 @@
"remarks": self.remarks or "Accounting Entry for Stock"
})
)
-
+
i += 1
# writeoff account includes petty difference in the invoice amount
diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
index 119de09..4fda030 100644
--- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
+++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import flt
+from frappe import _
def execute(filters=None):
if not filters: filters = {}
@@ -15,25 +16,38 @@
data = get_entries(filters)
from erpnext.accounts.utils import get_balance_on
- balance_as_per_company = get_balance_on(filters["account"], filters["report_date"])
+ balance_as_per_system = get_balance_on(filters["account"], filters["report_date"])
total_debit, total_credit = 0,0
for d in data:
total_debit += flt(d[2])
total_credit += flt(d[3])
- bank_bal = flt(balance_as_per_company) - flt(total_debit) + flt(total_credit)
+ amounts_not_reflected_in_system = frappe.db.sql("""select sum(ifnull(jvd.debit, 0) - ifnull(jvd.credit, 0))
+ from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
+ where jvd.parent = jv.name and jv.docstatus=1 and jvd.account=%s
+ and jv.posting_date > %s and jv.clearance_date <= %s
+ """, (filters["account"], filters["report_date"], filters["report_date"]))
+
+ amounts_not_reflected_in_system = flt(amounts_not_reflected_in_system[0][0]) \
+ if amounts_not_reflected_in_system else 0.0
+
+ bank_bal = flt(balance_as_per_system) - flt(total_debit) + flt(total_credit) \
+ + amounts_not_reflected_in_system
data += [
- get_balance_row("Balance as per company books", balance_as_per_company),
- ["", "Amounts not reflected in bank", total_debit, total_credit, "", "", "", ""],
- get_balance_row("Balance as per bank", bank_bal)
+ get_balance_row(_("System Balance"), balance_as_per_system),
+ [""]*len(columns),
+ ["", _("Amounts not reflected in bank"), total_debit, total_credit, "", "", "", ""],
+ get_balance_row(_("Amounts not reflected in system"), amounts_not_reflected_in_system),
+ [""]*len(columns),
+ get_balance_row(_("Expected balance as per bank"), bank_bal)
]
return columns, data
def get_columns():
- return ["Posting Date:Date:100", "Journal Voucher:Link/Journal Voucher:200",
+ return ["Posting Date:Date:100", "Journal Voucher:Link/Journal Voucher:220",
"Debit:Currency:120", "Credit:Currency:120",
"Against Account:Link/Account:200", "Reference::100", "Ref Date:Date:110", "Clearance Date:Date:110"
]
@@ -55,4 +69,4 @@
if amount > 0:
return ["", label, amount, 0, "", "", "", ""]
else:
- return ["", label, 0, amount, "", "", "", ""]
+ return ["", label, 0, abs(amount), "", "", "", ""]
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 3df62e7..59a49af 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -209,7 +209,7 @@
def calculate_taxes(self):
# maintain actual tax rate based on idx
- actual_tax_dict = dict([[tax.idx, tax.rate] for tax in self.tax_doclist
+ actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.tax_doclist
if tax.charge_type == "Actual"])
for n, item in enumerate(self.item_doclist):
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index a1d9a5b..2460a26 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -166,21 +166,19 @@
def get_future_stock_vouchers(self):
- future_stock_vouchers = []
-
- if hasattr(self, "fname"):
+ condition = ""
+ item_list = []
+ if getattr(self, "fname", None):
item_list = [d.item_code for d in self.get(self.fname)]
- condition = ''.join(['and item_code in (\'', '\', \''.join(item_list) ,'\')'])
- else:
- condition = ""
+ if item_list:
+ condition = "and item_code in ({})".format(", ".join(["%s"] * len(item_list)))
- for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
+ future_stock_vouchers = frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
from `tabStock Ledger Entry` sle
- where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) %s
- order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""" %
- ('%s', '%s', condition), (self.posting_date, self.posting_time),
- as_dict=True):
- future_stock_vouchers.append([d.voucher_type, d.voucher_no])
+ where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) {condition}
+ order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""".format(
+ condition=condition), tuple([self.posting_date, self.posting_date] + item_list),
+ as_list=True)
return future_stock_vouchers
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 14418a8..0d55f8b 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -324,7 +324,7 @@
total_qty = sum([flt(d[0]) for d in so_item_qty])
if total_qty > item_projected_qty.get(item, 0):
# shortage
- requested_qty = total_qty - item_projected_qty.get(item, 0)
+ requested_qty = total_qty - flt(item_projected_qty.get(item))
# consider minimum order qty
requested_qty = requested_qty > flt(so_item_qty[0][3]) and \
requested_qty or flt(so_item_qty[0][3])
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index dd11fab..801ea57 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -647,7 +647,7 @@
// maintain actual tax rate based on idx
$.each(this.frm.tax_doclist, function(i, tax) {
if (tax.charge_type == "Actual") {
- actual_tax_dict[tax.idx] = flt(tax.rate);
+ actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
}
});
diff --git a/erpnext/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js
index 03c5c2b..2e8cd7e 100644
--- a/erpnext/setup/doctype/customer_group/customer_group.js
+++ b/erpnext/setup/doctype/customer_group/customer_group.js
@@ -19,8 +19,7 @@
//get query select Customer Group
cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) {
- return{
- searchfield:['name', 'parent_customer_group'],
+ return {
filters: {
'is_group': "Yes"
}
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index e592f8d..3729b55 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -96,7 +96,7 @@
title: __("Get Items from BOM"),
fields: [
{"fieldname":"bom", "fieldtype":"Link", "label":__("BOM"),
- options:"BOM"},
+ options:"BOM", reqd: 1},
{"fieldname":"fetch_exploded", "fieldtype":"Check",
"label":__("Fetch exploded BOM (including sub-assemblies)"), "default":1},
{fieldname:"fetch", "label":__("Get Items from BOM"), "fieldtype":"Button"}