From 7b2177a544ecc4b829c4b4e1a752fb8d34daf6b4 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 26 Dec 2016 15:31:05 +0530 Subject: [PATCH] [test] Fixed test cases for LCV --- .../test_landed_cost_voucher.py | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) 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 c58607fe05..409770e91b 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 @@ -5,6 +5,7 @@ from __future__ import unicode_literals 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 from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice @@ -23,7 +24,7 @@ class TestLandedCostVoucher(unittest.TestCase): }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) - self.submit_landed_cost_voucher("Purchase Receipt", pr.name) + submit_landed_cost_voucher("Purchase Receipt", pr.name) pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount") self.assertEquals(pr_lc_value, 25.0) @@ -75,7 +76,7 @@ class TestLandedCostVoucher(unittest.TestCase): }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) - self.submit_landed_cost_voucher("Purchase Invoice", pi.name) + submit_landed_cost_voucher("Purchase Invoice", pi.name) pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name}, "landed_cost_voucher_amount") @@ -121,7 +122,7 @@ class TestLandedCostVoucher(unittest.TestCase): serial_no_rate = frappe.db.get_value("Serial No", "SN001", "purchase_rate") - self.submit_landed_cost_voucher("Purchase Receipt", pr.name) + submit_landed_cost_voucher("Purchase Receipt", pr.name) serial_no = frappe.db.get_value("Serial No", "SN001", ["warehouse", "purchase_rate"], as_dict=1) @@ -131,27 +132,37 @@ class TestLandedCostVoucher(unittest.TestCase): set_perpetual_inventory(0) - def submit_landed_cost_voucher(self, receipt_document_type, receipt_document): - ref_doc = frappe.get_doc(receipt_document_type, receipt_document) - - lcv = frappe.new_doc("Landed Cost Voucher") - lcv.company = "_Test Company" - lcv.set("purchase_receipts", [{ - "receipt_document_type": receipt_document_type, - "receipt_document": receipt_document, - "supplier": ref_doc.supplier, - "posting_date": ref_doc.posting_date, - "grand_total": ref_doc.base_grand_total - }]) - - lcv.set("taxes", [{ - "description": "Insurance Charges", - "account": "_Test Account Insurance Charges - _TC", - "amount": 50 - }]) - - lcv.insert() - lcv.submit() +def submit_landed_cost_voucher(receipt_document_type, receipt_document): + ref_doc = frappe.get_doc(receipt_document_type, receipt_document) + + lcv = frappe.new_doc("Landed Cost Voucher") + lcv.company = "_Test Company" + lcv.distribute_charges_based_on = 'Amount' + + lcv.set("purchase_receipts", [{ + "receipt_document_type": receipt_document_type, + "receipt_document": receipt_document, + "supplier": ref_doc.supplier, + "posting_date": ref_doc.posting_date, + "grand_total": ref_doc.base_grand_total + }]) + + lcv.set("taxes", [{ + "description": "Insurance Charges", + "account": "_Test Account Insurance Charges - _TC", + "amount": 50 + }]) + lcv.insert() + + distribute_landed_cost_on_items(lcv) + + lcv.submit() + +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) test_records = frappe.get_test_records('Landed Cost Voucher')