Added the credit_days_based_on field to Supplier and Supplier Type doctype

This commit is contained in:
shreyas 2016-01-25 12:44:14 +05:30
parent 7633aca7c1
commit 28a6578ba2
4 changed files with 177 additions and 28 deletions

View File

@ -237,16 +237,11 @@ def get_due_date(posting_date, party_type, party, company):
due_date = None due_date = None
if posting_date and party: if posting_date and party:
due_date = posting_date due_date = posting_date
if party_type=="Customer": credit_days_based_on, credit_days = get_credit_days(party_type, party, company)
credit_days_based_on, credit_days = get_credit_days(party_type, party, company) if credit_days_based_on == "Fixed Days" and credit_days:
if credit_days_based_on == "Fixed Days" and credit_days: due_date = add_days(posting_date, credit_days)
due_date = add_days(posting_date, credit_days) elif credit_days_based_on == "Last Day of the Next Month":
elif credit_days_based_on == "Last Day of the Next Month": due_date = (get_first_day(posting_date, 0, 2) + datetime.timedelta(-1)).strftime("%Y-%m-%d")
due_date = (get_first_day(posting_date, 0, 2) + datetime.timedelta(-1)).strftime("%Y-%m-%d")
else:
credit_days = get_credit_days(party_type, party, company)
if credit_days:
due_date = add_days(posting_date, credit_days)
return due_date return due_date
@ -255,20 +250,21 @@ def get_credit_days(party_type, party, company):
if party_type == "Customer": if party_type == "Customer":
credit_days_based_on, credit_days, customer_group = \ credit_days_based_on, credit_days, customer_group = \
frappe.db.get_value(party_type, party, ["credit_days_based_on", "credit_days", "customer_group"]) frappe.db.get_value(party_type, party, ["credit_days_based_on", "credit_days", "customer_group"])
if not credit_days_based_on:
credit_days_based_on, credit_days = \
frappe.db.get_value("Customer Group", customer_group, ["credit_days_based_on", "credit_days"]) \
or frappe.db.get_value("Company", company, ["credit_days_based_on", "credit_days"])
return credit_days_based_on, credit_days
else: else:
credit_days, supplier_type = frappe.db.get_value(party_type, party, ["credit_days", "supplier_type"]) credit_days_based_on, credit_days, supplier_type = \
if not credit_days: frappe.db.get_value(party_type, party, ["credit_days_based_on", "credit_days", "supplier_type"])
credit_days = frappe.db.get_value("Supplier Type", supplier_type, "credit_days") \
or frappe.db.get_value("Company", company, "credit_days")
return credit_days if not credit_days_based_on:
if party_type == "Customer":
credit_days_based_on, credit_days = \
frappe.db.get_value("Customer Group", customer_group, ["credit_days_based_on", "credit_days"]) \
or frappe.db.get_value("Company", company, ["credit_days_based_on", "credit_days"])
else:
credit_days_based_on, credit_days = \
frappe.db.get_value("Supplier Type", supplier_type, ["credit_days_based_on", "credit_days"])\
or frappe.db.get_value("Company", company, ["credit_days_based_on", "credit_days"] )
return credit_days_based_on, credit_days
def validate_due_date(posting_date, due_date, party_type, party, company): def validate_due_date(posting_date, due_date, party_type, party, company):
if getdate(due_date) < getdate(posting_date): if getdate(due_date) < getdate(posting_date):

View File

@ -230,10 +230,60 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"fieldname": "section_credit_limit",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Limit",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "credit_days_based_on",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Days Based On",
"length": 0,
"no_copy": 0,
"options": "\nFixed Days\nLast Day of the Next Month",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:doc.credit_days_based_on == 'Fixed Days'",
"fieldname": "credit_days", "fieldname": "credit_days",
"fieldtype": "Int", "fieldtype": "Int",
"hidden": 0, "hidden": 0,
@ -485,7 +535,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-01-06 02:35:18.285473", "modified": "2016-01-22 02:18:14.158258",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Buying", "module": "Buying",
"name": "Supplier", "name": "Supplier",
@ -635,5 +685,6 @@
"read_only": 0, "read_only": 0,
"read_only_onload": 0, "read_only_onload": 0,
"search_fields": "supplier_name, supplier_type", "search_fields": "supplier_name, supplier_type",
"sort_order": "ASC",
"title_field": "supplier_name" "title_field": "supplier_name"
} }

View File

@ -2,6 +2,53 @@
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
import unittest
from erpnext.accounts.party import get_due_date
test_records = frappe.get_test_records('Supplier') test_records = frappe.get_test_records('Supplier')
class TestSupplier(unittest.TestCase):
def test_supplier_due_date_against_supplier_credit_limit(self):
# Set Credit Limit based on Fixed days
frappe.db.set_value("Supplier", "_Test Supplier", "credit_days_based_on", "Fixed Days")
frappe.db.set_value("Supplier", "_Test Supplier", "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 based on Last day next month
frappe.db.set_value("Supplier", "_Test Supplier", "credit_days", 0)
frappe.db.set_value("Supplier", "_Test Supplier", "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")
frappe.db.set_value("Supplier", "_Test Supplier", "credit_days_based_on", "")
# Set credit limit for the supplier type instead of supplier and evaluate the due date
# based on Fixed days
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")

View File

@ -26,6 +26,7 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
@ -33,10 +34,59 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 1,
"fieldname": "section_credit_limit",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Limit",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "credit_days_based_on",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Days Based On",
"length": 0,
"no_copy": 0,
"options": "\nFixed Days\nLast Day of the Next Month",
"permlevel": 1,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:doc.credit_days_based_on=='Fixed Days'",
"fieldname": "credit_days", "fieldname": "credit_days",
"fieldtype": "Int", "fieldtype": "Int",
"hidden": 0, "hidden": 0,
@ -46,8 +96,10 @@
"label": "Credit Days", "label": "Credit Days",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 1, "permlevel": 0,
"precision": "",
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -70,6 +122,7 @@
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -95,6 +148,7 @@
"options": "Party Account", "options": "Party Account",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -113,7 +167,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2015-11-16 06:29:58.970888", "modified": "2016-01-25 02:09:49.846022",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Setup", "module": "Setup",
"name": "Supplier Type", "name": "Supplier Type",
@ -241,5 +295,6 @@
} }
], ],
"read_only": 0, "read_only": 0,
"read_only_onload": 0 "read_only_onload": 0,
"sort_order": "ASC"
} }