diff --git a/erpnext/__init__.py b/erpnext/__init__.py index f11555fc26..eb7f91d2ca 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import frappe -__version__ = '8.0.39' +__version__ = '8.0.40' def get_default_company(user=None): diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index 9261fa4f39..223e915fe3 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -709,7 +709,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ filter: function (item, input) { var value = item.value.toLowerCase(); if (value.indexOf('is_action') !== -1 || - value.indexOf(input) !== -1) { + value.indexOf(input.toLowerCase()) !== -1) { return true; } }, diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index a1c76974cd..a6ca3b6061 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -366,8 +366,10 @@ def get_timeline_data(doctype, name): def get_dashboard_info(party_type, party): current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True) - party_account_currency = get_party_account_currency(party_type, party, frappe.db.get_default("company")) - company_default_currency = get_default_currency() + company = frappe.db.get_default("company") or frappe.get_all("Company")[0].name + party_account_currency = get_party_account_currency(party_type, party, company) + company_default_currency = get_default_currency() \ + or frappe.db.get_value('Company', company, 'default_currency') if party_account_currency==company_default_currency: total_field = "base_grand_total" diff --git a/erpnext/hr/doctype/offer_letter/offer_letter.js b/erpnext/hr/doctype/offer_letter/offer_letter.js index 643eaa88e7..125a425b6c 100755 --- a/erpnext/hr/doctype/offer_letter/offer_letter.js +++ b/erpnext/hr/doctype/offer_letter/offer_letter.js @@ -5,8 +5,10 @@ frappe.provide("erpnext.offer_letter"); frappe.ui.form.on("Offer Letter", { select_terms: function(frm) { - frappe.model.get_value("Terms and Conditions", frm.doc.select_terms, "terms", function(value) { - frm.set_value("terms", value.terms); + erpnext.utils.get_terms(frm.doc.select_terms, frm.doc, function(r) { + if(!r.exc) { + me.frm.set_value("terms", r.message); + } }); }, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 2d0d83b125..6357a52102 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -993,20 +993,12 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ get_terms: function() { var me = this; - if(this.frm.doc.tc_name) { - return frappe.call({ - method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions', - args: { - template_name: this.frm.doc.tc_name, - doc: this.frm.doc - }, - callback: function(r) { - if(!r.exc) { - me.frm.set_value("terms", r.message); - } - } - }); - } + + erpnext.utils.get_terms(this.frm.doc.tc_name, this.frm.doc, function(r) { + if(!r.exc) { + me.frm.set_value("terms", r.message); + } + }); }, taxes_and_charges: function() { diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 3a2254e24c..d618fbe5dd 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -104,6 +104,21 @@ $.extend(erpnext.utils, { } } refresh_field(table_fieldname); + }, + + get_terms: function(tc_name, doc, callback) { + if(tc_name) { + return frappe.call({ + method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions', + args: { + template_name: tc_name, + doc: doc + }, + callback: function(r) { + callback(r) + } + }); + } } }); diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js index b97378f6d8..3ae61b9020 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js @@ -102,9 +102,17 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({ total_item_cost += flt(d[based_on]) }); + var total_charges = 0.0; $.each(this.frm.doc.items || [], function(i, item) { item.applicable_charges = flt(item[based_on]) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost) + item.applicable_charges = flt(item.applicable_charges, precision("applicable_charges", item)) + total_charges += item.applicable_charges }); + + if (total_charges != this.frm.doc.total_taxes_and_charges){ + var diff = this.frm.doc.total_taxes_and_charges - flt(total_charges) + this.frm.doc.items.slice(-1)[0].applicable_charges += diff + } refresh_field("items"); } }, diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py index 0eaf5ba8ca..a2d3606a89 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.utils import flt +from frappe.model.meta import get_field_precision from frappe.model.document import Document from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos @@ -71,7 +72,17 @@ class LandedCostVoucher(Document): if not total: frappe.throw(_("Total {0} for all items is zero, may be you should change 'Distribute Charges Based On'").format(based_on)) - if self.total_taxes_and_charges != sum([flt(d.applicable_charges) for d in self.get("items")]): + total_applicable_charges = sum([flt(d.applicable_charges) for d in self.get("items")]) + + precision = get_field_precision(frappe.get_meta("Landed Cost Item").get_field("applicable_charges"), + currency=frappe.db.get_value("Company", self.company, "default_currency", cache=True)) + + diff = flt(self.total_taxes_and_charges) - flt(total_applicable_charges) + diff = flt(diff, precision) + + if abs(diff) < (2.0 / (10**precision)): + self.items[-1].applicable_charges += diff + else: frappe.throw(_("Total Applicable Charges in Purchase Receipt Items table must be same as Total Taxes and Charges")) diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index 930896c91c..eb8f8b84f0 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -7,7 +7,7 @@ import unittest import frappe from frappe.utils import flt from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \ - import set_perpetual_inventory, get_gl_entries, test_records as pr_test_records + import set_perpetual_inventory, get_gl_entries, test_records as pr_test_records, make_purchase_receipt from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice class TestLandedCostVoucher(unittest.TestCase): @@ -133,7 +133,29 @@ class TestLandedCostVoucher(unittest.TestCase): set_perpetual_inventory(0) -def submit_landed_cost_voucher(receipt_document_type, receipt_document): + def test_landed_cost_voucher_for_odd_numbers (self): + set_perpetual_inventory(1) + + pr = make_purchase_receipt(do_not_save=True) + pr.items[0].cost_center = "_Test Company - _TC" + for x in range(2): + pr.append("items", { + "item_code": "_Test Item", + "warehouse": "_Test Warehouse - _TC", + "cost_center": "_Test Company - _TC", + "qty": 5, + "rate": 50 + }) + pr.submit() + + lcv = submit_landed_cost_voucher("Purchase Receipt", pr.name, 123.22) + + self.assertEquals(lcv.items[0].applicable_charges, 41.07) + self.assertEquals(lcv.items[2].applicable_charges, 41.08) + + set_perpetual_inventory(0) + +def submit_landed_cost_voucher(receipt_document_type, receipt_document, charges=50): ref_doc = frappe.get_doc(receipt_document_type, receipt_document) lcv = frappe.new_doc("Landed Cost Voucher") @@ -151,7 +173,7 @@ def submit_landed_cost_voucher(receipt_document_type, receipt_document): lcv.set("taxes", [{ "description": "Insurance Charges", "account": "_Test Account Insurance Charges - _TC", - "amount": 50 + "amount": charges }]) lcv.insert() @@ -159,11 +181,15 @@ def submit_landed_cost_voucher(receipt_document_type, receipt_document): distribute_landed_cost_on_items(lcv) lcv.submit() + + return lcv def distribute_landed_cost_on_items(lcv): based_on = lcv.distribute_charges_based_on.lower() total = sum([flt(d.get(based_on)) for d in lcv.get("items")]) + for item in lcv.get("items"): item.applicable_charges = flt(item.get(based_on)) * flt(lcv.total_taxes_and_charges) / flt(total) + item.applicable_charges = flt(item.applicable_charges, lcv.precision("applicable_charges", item)) test_records = frappe.get_test_records('Landed Cost Voucher')