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
This commit is contained in:
tunde 2017-08-18 13:25:02 +01:00
parent be1b871c53
commit c7f46218d7
4 changed files with 49 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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