-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: option to limit reposting in certain timeslot
- Loading branch information
Showing
7 changed files
with
210 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 66 additions & 5 deletions
71
erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,72 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors | ||
# See license.txt | ||
from __future__ import unicode_literals | ||
|
||
# import frappe | ||
import unittest | ||
|
||
import frappe | ||
|
||
from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import ( | ||
in_configured_timeslot, | ||
) | ||
|
||
|
||
class TestRepostItemValuation(unittest.TestCase): | ||
pass | ||
def test_repost_time_slot(self): | ||
repost_settings = frappe.get_doc("Stock Reposting Settings") | ||
|
||
positive_cases = [ | ||
{"limit_reposting_timeslot": 0}, | ||
{ | ||
"limit_reposting_timeslot": 1, | ||
"start_time": "18:00:00", | ||
"end_time": "09:00:00", | ||
"current_time": "20:00:00", | ||
}, | ||
{ | ||
"limit_reposting_timeslot": 1, | ||
"start_time": "09:00:00", | ||
"end_time": "18:00:00", | ||
"current_time": "12:00:00", | ||
}, | ||
{ | ||
"limit_reposting_timeslot": 1, | ||
"start_time": "23:00:00", | ||
"end_time": "09:00:00", | ||
"current_time": "2:00:00", | ||
}, | ||
] | ||
|
||
for case in positive_cases: | ||
repost_settings.update(case) | ||
self.assertTrue( | ||
in_configured_timeslot(repost_settings, case.get("current_time")), | ||
msg=f"Exepcted true from : {case}", | ||
) | ||
|
||
negative_cases = [ | ||
{ | ||
"limit_reposting_timeslot": 1, | ||
"start_time": "18:00:00", | ||
"end_time": "09:00:00", | ||
"current_time": "09:01:00", | ||
}, | ||
{ | ||
"limit_reposting_timeslot": 1, | ||
"start_time": "09:00:00", | ||
"end_time": "18:00:00", | ||
"current_time": "19:00:00", | ||
}, | ||
{ | ||
"limit_reposting_timeslot": 1, | ||
"start_time": "23:00:00", | ||
"end_time": "09:00:00", | ||
"current_time": "22:00:00", | ||
}, | ||
] | ||
|
||
for case in negative_cases: | ||
repost_settings.update(case) | ||
self.assertFalse( | ||
in_configured_timeslot(repost_settings, case.get("current_time")), | ||
msg=f"Exepcted false from : {case}", | ||
) |
Empty file.
8 changes: 8 additions & 0 deletions
8
erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Stock Reposting Settings', { | ||
// refresh: function(frm) { | ||
|
||
// } | ||
}); |
72 changes: 72 additions & 0 deletions
72
erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"creation": "2021-10-01 10:56:30.814787", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"scheduling_section", | ||
"limit_reposting_timeslot", | ||
"start_time", | ||
"end_time", | ||
"limits_dont_apply_on" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "scheduling_section", | ||
"fieldtype": "Section Break", | ||
"label": "Scheduling" | ||
}, | ||
{ | ||
"depends_on": "limit_reposting_timeslot", | ||
"fieldname": "start_time", | ||
"fieldtype": "Time", | ||
"label": "Start Time", | ||
"mandatory_depends_on": "limit_reposting_timeslot" | ||
}, | ||
{ | ||
"depends_on": "limit_reposting_timeslot", | ||
"fieldname": "end_time", | ||
"fieldtype": "Time", | ||
"label": "End Time", | ||
"mandatory_depends_on": "limit_reposting_timeslot" | ||
}, | ||
{ | ||
"depends_on": "limit_reposting_timeslot", | ||
"fieldname": "limits_dont_apply_on", | ||
"fieldtype": "Select", | ||
"label": "Limits don't apply on", | ||
"options": "\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\nSunday" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "limit_reposting_timeslot", | ||
"fieldtype": "Check", | ||
"label": "Limit timeslot for Stock Reposting" | ||
} | ||
], | ||
"index_web_pages_for_search": 1, | ||
"issingle": 1, | ||
"links": [], | ||
"modified": "2021-10-01 11:27:28.981594", | ||
"modified_by": "Administrator", | ||
"module": "Stock", | ||
"name": "Stock Reposting Settings", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"print": 1, | ||
"read": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"track_changes": 1 | ||
} |
28 changes: 28 additions & 0 deletions
28
erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
from frappe.model.document import Document | ||
from frappe.utils import add_to_date, get_datetime, get_time_str, time_diff_in_hours | ||
|
||
|
||
class StockRepostingSettings(Document): | ||
|
||
|
||
def validate(self): | ||
self.set_minimum_reposting_time_slot() | ||
|
||
def set_minimum_reposting_time_slot(self): | ||
"""Ensure that timeslot for reposting is at least 12 hours.""" | ||
if not self.limit_reposting_timeslot: | ||
return | ||
|
||
start_time = get_datetime(self.start_time) | ||
end_time = get_datetime(self.end_time) | ||
|
||
if start_time > end_time: | ||
end_time = add_to_date(end_time, days=1, as_datetime=True) | ||
|
||
diff = time_diff_in_hours(end_time, start_time) | ||
|
||
if diff < 12: | ||
self.end_time = get_time_str(add_to_date(self.start_time, hours=12, as_datetime=True)) |
9 changes: 9 additions & 0 deletions
9
erpnext/stock/doctype/stock_reposting_settings/test_stock_reposting_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
import unittest | ||
|
||
|
||
class TestStockRepostingSettings(unittest.TestCase): | ||
pass |