Merge branch 'master' into develop

This commit is contained in:
Nabin Hait 2017-05-26 21:35:42 +05:30
commit 6a541a6f7a
9 changed files with 80 additions and 24 deletions

View File

@ -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):

View File

@ -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;
}
},

View File

@ -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"

View File

@ -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);
}
});
},

View File

@ -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() {

View File

@ -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)
}
});
}
}
});

View File

@ -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");
}
},

View File

@ -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"))

View File

@ -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')