[fix] add round off difference to last row in landed cost voucher (#8989)
* [fix] add round off difference to last row in landed cost voucher * Add test case for odd numbers * Add assertEquals to verify applicable charges * Use make_purchase_receipt, move round off logic * Allow rounding difference * Specify cost center to pass test
This commit is contained in:
parent
d45a036b5e
commit
7b0c682635
@ -102,9 +102,17 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
|
|||||||
total_item_cost += flt(d[based_on])
|
total_item_cost += flt(d[based_on])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var total_charges = 0.0;
|
||||||
$.each(this.frm.doc.items || [], function(i, item) {
|
$.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[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");
|
refresh_field("items");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
|
from frappe.model.meta import get_field_precision
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||||
|
|
||||||
@ -71,7 +72,17 @@ class LandedCostVoucher(Document):
|
|||||||
if not total:
|
if not total:
|
||||||
frappe.throw(_("Total {0} for all items is zero, may be you should change 'Distribute Charges Based On'").format(based_on))
|
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"))
|
frappe.throw(_("Total Applicable Charges in Purchase Receipt Items table must be same as Total Taxes and Charges"))
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import unittest
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \
|
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
|
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||||
|
|
||||||
class TestLandedCostVoucher(unittest.TestCase):
|
class TestLandedCostVoucher(unittest.TestCase):
|
||||||
@ -133,7 +133,29 @@ class TestLandedCostVoucher(unittest.TestCase):
|
|||||||
|
|
||||||
set_perpetual_inventory(0)
|
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)
|
ref_doc = frappe.get_doc(receipt_document_type, receipt_document)
|
||||||
|
|
||||||
lcv = frappe.new_doc("Landed Cost Voucher")
|
lcv = frappe.new_doc("Landed Cost Voucher")
|
||||||
@ -151,7 +173,7 @@ def submit_landed_cost_voucher(receipt_document_type, receipt_document):
|
|||||||
lcv.set("taxes", [{
|
lcv.set("taxes", [{
|
||||||
"description": "Insurance Charges",
|
"description": "Insurance Charges",
|
||||||
"account": "_Test Account Insurance Charges - _TC",
|
"account": "_Test Account Insurance Charges - _TC",
|
||||||
"amount": 50
|
"amount": charges
|
||||||
}])
|
}])
|
||||||
|
|
||||||
lcv.insert()
|
lcv.insert()
|
||||||
@ -160,10 +182,14 @@ def submit_landed_cost_voucher(receipt_document_type, receipt_document):
|
|||||||
|
|
||||||
lcv.submit()
|
lcv.submit()
|
||||||
|
|
||||||
|
return lcv
|
||||||
|
|
||||||
def distribute_landed_cost_on_items(lcv):
|
def distribute_landed_cost_on_items(lcv):
|
||||||
based_on = lcv.distribute_charges_based_on.lower()
|
based_on = lcv.distribute_charges_based_on.lower()
|
||||||
total = sum([flt(d.get(based_on)) for d in lcv.get("items")])
|
total = sum([flt(d.get(based_on)) for d in lcv.get("items")])
|
||||||
|
|
||||||
for item 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.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')
|
test_records = frappe.get_test_records('Landed Cost Voucher')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user