rewrite Supplier test cases

This commit is contained in:
tunde 2017-09-04 19:37:54 +01:00
parent 57171cdc48
commit 635423d70f
5 changed files with 170 additions and 1 deletions

View File

@ -0,0 +1,34 @@
[
{
"doctype":"Payment Term",
"due_date_based_on":"Day(s) after invoice date",
"payment_term_name":"_Test N30",
"description":"_Test Net 30 Days",
"invoice_portion":50,
"credit_days":30
},
{
"doctype":"Payment Term",
"due_date_based_on":"Day(s) after invoice date",
"payment_term_name":"_Test COD",
"description":"_Test Cash on Delivery",
"invoice_portion":50,
"credit_days":0
},
{
"doctype":"Payment Term",
"due_date_based_on":"Month(s) after the end of the invoice month",
"payment_term_name":"_Test EONM",
"description":"_Test End of Next Month",
"invoice_portion":100,
"credit_months":1
},
{
"doctype":"Payment Term",
"due_date_based_on":"Day(s) after invoice date",
"payment_term_name":"_Test N30 1",
"description":"_Test Net 30 Days",
"invoice_portion":100,
"credit_days":30
}
]

View File

@ -0,0 +1,60 @@
[
{
"doctype":"Payment Terms Template",
"terms":[
{
"doctype":"Payment Terms Template Detail",
"due_date_based_on":"Day(s) after invoice date",
"idx":1,
"description":"Cash on Delivery",
"invoice_portion":50,
"credit_days":0,
"credit_months":0,
"payment_term":"_Test COD"
},
{
"doctype":"Payment Terms Template Detail",
"due_date_based_on":"Day(s) after invoice date",
"idx":2,
"description":"Net 30 Days ",
"invoice_portion":50,
"credit_days":30,
"credit_months":0,
"payment_term":"_Test N30"
}
],
"template_name":"_Test Payment Term Template"
},
{
"doctype":"Payment Terms Template",
"terms":[
{
"doctype":"Payment Terms Template Detail",
"due_date_based_on":"Month(s) after the end of the invoice month",
"idx":1,
"description":"_Test End of Next Months",
"invoice_portion":100,
"credit_days":0,
"credit_months":1,
"payment_term":"_Test EONM"
}
],
"template_name":"_Test Payment Term Template 1"
},
{
"doctype":"Payment Terms Template",
"terms":[
{
"doctype":"Payment Terms Template Detail",
"due_date_based_on":"Day(s) after invoice date",
"idx":1,
"description":"_Test Net Within 30 days",
"invoice_portion":100,
"credit_days":30,
"credit_months":0,
"payment_term":"_Test N30 1"
}
],
"template_name":"_Test Payment Term Template 3"
}
]

View File

@ -1,4 +1,10 @@
[
{
"doctype": "Supplier",
"supplier_name": "_Test Supplier With Template 1",
"supplier_type": "_Test Supplier Type",
"payment_terms": "_Test Payment Term Template 3"
},
{
"doctype": "Supplier",
"supplier_name": "_Test Supplier P",

View File

@ -5,13 +5,59 @@ from __future__ import unicode_literals
import frappe, unittest
from erpnext.accounts.party import get_due_date
from erpnext.exceptions import PartyFrozen, PartyDisabled
from erpnext.exceptions import PartyDisabled
from frappe.test_runner import make_test_records
from frappe.utils import add_days, add_months, get_last_day
test_dependencies = ['Payment Term', 'Payment Terms Template']
test_records = frappe.get_test_records('Supplier')
class TestSupplier(unittest.TestCase):
def test_supplier_default_payment_terms(self):
# Payment Term based on Days after invoice date
frappe.db.set_value(
"Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 3")
due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
self.assertEqual(due_date, "2016-02-21")
due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
self.assertEqual(due_date, "2017-02-21")
# Payment Term based on last day of month
frappe.db.set_value(
"Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 1")
due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
self.assertEqual(due_date, "2016-02-29")
due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
self.assertEqual(due_date, "2017-02-28")
frappe.db.set_value("Supplier", "_Test Supplier With Template 1", "payment_terms", "")
# Set credit limit for the supplier type instead of supplier and evaluate the due date
# frappe.db.set_value("Supplier Type", "_Test Supplier Type", "credit_days_based_on",
# "Fixed Days")
# frappe.db.set_value("Supplier Type", "_Test Supplier Type", "credit_days", 10)
#
# due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier", "_Test Company")
# self.assertEqual(due_date, "2016-02-01")
#
# # Set credit limit for the supplier type instead of supplier and evaluate the due date
# # based on Last day of next month
# frappe.db.set_value("Supplier", "_Test Supplier Type", "credit_days", 0)
# frappe.db.set_value("Supplier Type", "_Test Supplier Type", "credit_days_based_on",
# "Last Day of the Next Month")
#
# # Leap year
# due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier", "_Test Company")
# self.assertEqual(due_date, "2016-02-29")
# # Non Leap year
# due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier", "_Test Company")
# self.assertEqual(due_date, "2017-02-28")
def test_supplier_disabled(self):
make_test_records("Item")

View File

@ -0,0 +1,23 @@
/* eslint-disable */
// rename this file from _test_[name] to test_[name] to activate
// and remove above this line
QUnit.test("test: Supplier Type", function (assert) {
let done = assert.async();
// number of asserts
assert.expect(1);
frappe.run_serially([
// insert a new Supplier Type
() => frappe.tests.make('Supplier Type', [
// values to be set
{key: 'value'}
]),
() => {
assert.equal(cur_frm.doc.key, 'value');
},
() => done()
]);
});