From 78b63663254de23d6b0eac588ae1ab9629025832 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 19 Aug 2014 12:20:48 +0530 Subject: [PATCH 1/5] [fix] Error Reports --- erpnext/controllers/stock_controller.py | 22 +++++++++---------- .../doctype/customer_group/customer_group.js | 3 +-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index a1d9a5b00d..2460a26de4 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -166,21 +166,19 @@ class StockController(AccountsController): 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/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js index 03c5c2bfdf..2e8cd7e6c4 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.js +++ b/erpnext/setup/doctype/customer_group/customer_group.js @@ -19,8 +19,7 @@ cur_frm.cscript.set_root_readonly = function(doc) { //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" } From 0a35effe49f8125ef250dfc877dea4201b47ad5b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Aug 2014 12:39:40 +0530 Subject: [PATCH 2/5] Precision issue in tax calculation --- .../purchase_invoice/purchase_invoice.py | 21 +++++++++---------- erpnext/controllers/accounts_controller.py | 2 +- erpnext/public/js/transaction.js | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 68a21d9117..af7c85a83f 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -273,10 +273,10 @@ class PurchaseInvoice(BuyingController): 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 @@ -329,32 +329,31 @@ class PurchaseInvoice(BuyingController): "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 @@ -364,7 +363,7 @@ class PurchaseInvoice(BuyingController): 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, @@ -374,7 +373,7 @@ class PurchaseInvoice(BuyingController): "remarks": self.remarks or "Accounting Entry for Stock" }) ) - + i += 1 # writeoff account includes petty difference in the invoice amount diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 3df62e7934..59a49afb22 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -209,7 +209,7 @@ class AccountsController(TransactionBase): 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/public/js/transaction.js b/erpnext/public/js/transaction.js index dd11fab6f9..801ea57d21 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -647,7 +647,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ // 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)); } }); From cca6460e65ceac1001ceed2faf085c35392d297a Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 19 Aug 2014 16:05:54 +0530 Subject: [PATCH 3/5] [fix] Error Reports --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 6 ++++-- .../production_planning_tool/production_planning_tool.py | 2 +- erpnext/stock/doctype/material_request/material_request.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 9a3b3121f4..076cccc179 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -135,8 +135,10 @@ def get_pricing_rule_for_item(args): 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/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 14418a8b41..0d55f8bb5e 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 @@ class ProductionPlanningTool(Document): 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/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js index e592f8df4d..3729b55c7e 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -96,7 +96,7 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten 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"} From 237f3765e560b4e69f0d84f30125da6d30f8b122 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Aug 2014 16:29:06 +0530 Subject: [PATCH 4/5] Bank reconciliation statement: show amounts which has cleared in the bank but not registered in the system --- .../bank_reconciliation_statement.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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 119de09e41..2c0a6afb79 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py @@ -15,25 +15,36 @@ def execute(filters=None): 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), + get_balance_row("Balance as per system", balance_as_per_system), ["", "Amounts not reflected in bank", total_debit, total_credit, "", "", "", ""], + get_balance_row("Amounts not reflected in system", amounts_not_reflected_in_system), get_balance_row("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 +66,4 @@ def get_balance_row(label, amount): if amount > 0: return ["", label, amount, 0, "", "", "", ""] else: - return ["", label, 0, amount, "", "", "", ""] + return ["", label, 0, abs(amount), "", "", "", ""] From 432431f2e6d392d2684705d98cb2b26a18ad6656 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Aug 2014 16:49:44 +0530 Subject: [PATCH 5/5] fix for translation --- .../bank_reconciliation_statement.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 2c0a6afb79..4fda0300b6 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 = {} @@ -35,10 +36,12 @@ def execute(filters=None): + amounts_not_reflected_in_system data += [ - get_balance_row("Balance as per system", balance_as_per_system), - ["", "Amounts not reflected in bank", total_debit, total_credit, "", "", "", ""], - get_balance_row("Amounts not reflected in system", amounts_not_reflected_in_system), - 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