From c7f46218d724751af26fb05312047c2b755c3479 Mon Sep 17 00:00:00 2001 From: tunde Date: Fri, 18 Aug 2017 13:25:02 +0100 Subject: [PATCH] tests and test fixes fixes test case: make sales invoice using customer that does not have credit_days_based_on 'Last Day Of Next Month' so that it doesn't conflict with payment term due date fix test case: create purchase invoice with new supplier with credit_days_based_on "Fixed Days" as the default "Last Day of Month" does not apply when using payment terms --- .../purchase_invoice/test_purchase_invoice.py | 34 ++++++++++++++++++- .../sales_invoice/test_sales_invoice.py | 4 +-- .../buying/doctype/supplier/test_records.json | 6 ++++ .../doctype/customer/test_records.json | 8 +++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 3454a2e9b49..f189bf849af 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import unittest import frappe, erpnext import frappe.model -from frappe.utils import cint, flt, today, nowdate +from frappe.utils import cint, flt, today, nowdate, getdate, add_days import frappe.defaults from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \ test_records as pr_test_records @@ -551,6 +551,38 @@ class TestPurchaseInvoice(unittest.TestCase): #check outstanding after advance cancellation self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total + pi.total_advance)) + def test_gl_entry_based_on_payment_schedule(self): + pi = make_purchase_invoice(do_not_save=True, supplier="_Test Supplier P") + pi.append("payment_schedule", { + "due_date": add_days(nowdate(), 15), + "payment_amount": 100 + }) + pi.append("payment_schedule", { + "due_date": add_days(nowdate(), 45), + "payment_amount": 150 + }) + + pi.save() + pi.submit() + + gl_entries = frappe.db.sql("""select account, debit, credit, due_date + from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s + order by account asc, debit asc""", pi.name, as_dict=1) + self.assertTrue(gl_entries) + + expected_gl_entries = sorted([ + [pi.credit_to, 0.0, 100.0, add_days(nowdate(), 15)], + [pi.credit_to, 0.0, 150.0, add_days(nowdate(), 45)], + ["_Test Account Cost for Goods Sold - _TC", 250.0, 0.0, None] + ]) + + for i, gle in enumerate(sorted(gl_entries, key=lambda gle: gle.account)): + self.assertEquals(expected_gl_entries[i][0], gle.account) + self.assertEquals(expected_gl_entries[i][1], gle.debit) + self.assertEquals(expected_gl_entries[i][2], gle.credit) + self.assertEquals(getdate(expected_gl_entries[i][3]), getdate(gle.due_date)) + + def unlink_payment_on_cancel_of_invoice(enable=1): accounts_settings = frappe.get_doc("Accounts Settings") accounts_settings.unlink_payment_on_cancellation_of_invoice = enable diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index bb4cab4817c..331aee9e9b3 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1273,7 +1273,7 @@ class TestSalesInvoice(unittest.TestCase): return si def test_gl_entry_based_on_payment_schedule(self): - si = create_sales_invoice(do_not_save=True) + si = create_sales_invoice(do_not_save=True, customer="_Test Customer P") si.append("payment_schedule", { "due_date": add_days(nowdate(), 15), "payment_amount": 20 @@ -1302,7 +1302,7 @@ class TestSalesInvoice(unittest.TestCase): self.assertEquals(expected_gl_entries[i][1], gle.debit) self.assertEquals(expected_gl_entries[i][2], gle.credit) self.assertEquals(getdate(expected_gl_entries[i][3]), getdate(gle.due_date)) - + def create_sales_invoice(**args): si = frappe.new_doc("Sales Invoice") diff --git a/erpnext/buying/doctype/supplier/test_records.json b/erpnext/buying/doctype/supplier/test_records.json index d2b399544f9..fa728bed114 100644 --- a/erpnext/buying/doctype/supplier/test_records.json +++ b/erpnext/buying/doctype/supplier/test_records.json @@ -1,4 +1,10 @@ [ + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier P", + "supplier_type": "_Test Supplier Type", + "credit_days_based_on": "Fixed Days" + }, { "doctype": "Supplier", "supplier_name": "_Test Supplier with Country", diff --git a/erpnext/selling/doctype/customer/test_records.json b/erpnext/selling/doctype/customer/test_records.json index 94f14ed6fb0..43d6beb0cbf 100644 --- a/erpnext/selling/doctype/customer/test_records.json +++ b/erpnext/selling/doctype/customer/test_records.json @@ -1,4 +1,12 @@ [ + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer P", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + "credit_days_based_on": "Fixed Days" + }, { "customer_group": "_Test Customer Group", "customer_name": "_Test Customer",