- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究订阅管理系统。我在计算订阅到期日时遇到问题。场景如下,
如果一个人订阅了 1 个月,比如 1/11/2018 到 30/11/2018 [DD/MM/YYYY] 总共 30 天,但他想从每周 30 天中排除周五和周六。那么我应该如何计算到期日?
Logic is : Say End Date = Expiry Date then find Fri/Sat from 1/11/2018 to 30/11/2018 which comes out 5 Fri & 4 Sat = 9 days. Add to Expiry Date which will be 09/12/2018. Now search Fur & Sat between End Date & Expiry Date which comes out 1 Fri & 2 Sat = 3 days. Now End Date = Expiry Date and Expiry Date + 3 Days = 12/12/2018. Search between End Date & Expiry Date for Fri & Sat which is 0 so the Expiry Date is 12/12/2018 return value <<
以下代码执行此操作,但方法返回 09/12/2018 而不是 12/12/2018。这有什么问题??
@api.one
def get_expiry_date(self, start, end, day_selection):
print("i am in 2nd", start, end, day_selection)
dayformat = '%Y-%m-%d'
current_date = datetime.now().date()
if start:
start = datetime.strptime(str(start), dayformat).date()
if end:
end = datetime.strptime(str(end), dayformat).date()
if day_selection:
selected_days = day_selection
if start < current_date:
start = datetime.strptime(str(start), dayformat).date()
weekdays = self.weekday_count(start,end)
print("days for start and end date",start,end, day_selection)
adddays = 0
if weekdays:
for i in range(len(day_selection)):
for item in weekdays[0]:
weekdays_dict = item
print("dict", type(weekdays), type(weekdays[0]), weekdays_dict)
print("compare", selected_days[i], weekdays_dict, selected_days[i] == weekdays_dict)
if selected_days[i] == item:
adddays = adddays + weekdays[0].get(item)
new_start = end
end = datetime.strptime(str(end), dayformat).date() + timedelta(days=adddays)
start = new_start
print("New Expiry Date", start, end, adddays)
if adddays > 0:
self.get_expiry_date(start, end, day_selection)
print("type of end is ", type(end))
print("selected days are", selected_days[i],weekdays[0], weekdays[0].get(item), adddays)
print("last returned values is",end)
返回结束
最佳答案
在你的问题中,没有 day_selection
的定义也不是 weekday_count
因此很难看出发生了什么。可能问题在于递归,这不是必需的。
如 day_selection
定义为选择排除的天数( strftime('%a')
的列表,如 ['Mon', 'Tue']
),然后:
from datetime import datetime, timedelta
def get_expiry_date(start, end, day_selection):
dayformat = '%Y-%m-%d'
weekdays= {}
start = datetime.strptime(str(start), dayformat).date()
end = datetime.strptime(str(end), dayformat).date()
# Count weekdays
for i in range((end - start).days+1):
weekday = (start + timedelta(i)).strftime('%a')
weekdays[weekday] = 1 + weekdays.setdefault(weekday, 0)
# Count subscription days to add
sub_days_to_add = 0
for selected in day_selection:
sub_days_to_add += weekdays.setdefault(selected, 0)
# Count calender days to add
cal_days_extension = 0
while sub_days_to_add > 0:
if (end + timedelta(days=cal_days_extension + 1)).strftime('%a') not in day_selection:
sub_days_to_add -= 1
cal_days_extension += 1
# Add to end day
return end + timedelta(days=cal_days_extension)
print (get_expiry_date('2018-11-01', '2018-11-30', ['Fri', 'Sat']))
# ---> 2018-12-12
print (get_expiry_date('2018-11-01', '2018-11-30', []))
# ---> 2018-11-30
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
会更安全比
dayformat = '%Y-%m-%d'
.对于像
start
这样的参数&
end
,如果它们是强制性的,可以在 Odoo 中使这些字段成为必需的。
关于python-3.x - odoo 11/Python 3 : How to find expiry date of subscription if some weekdays are excluded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53427062/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我想,如果我单击按钮,删除数据并返回 TreeView 。我可以使用 unlink 方法删除数据。但我不能重定向到 TreeView 。我该怎么做? 这是我的代码: def action_de
我最近安装了 Odoo 9.0。但是,我需要一个仅适用于 Odoo 8.0 的模块。 我想知道是否可以对此模块进行微小的更改以使其兼容 Odoo 9.0?新模块只是一个日历,仅使用 Web 界面:Li
嗨,我很难确定人类的权限Odoo10 的资源模块涉及休假管理工作流程。 我在休假类型中激活了双重验证。假设我有一个部门,拥有以下员工: Manager01 (Manager of the Depart
我正在尝试将 odoo 安装从 8.0 升级到 9.0。到目前为止,我所做的如下: 从生产系统备份 odoo 数据库 在我当前的系统中安装了备份数据库作为测试 复制了我系统文件夹中的 odoo 文件夹
如何在 odoo 8.0 (OpenERP) 上删除“Powered by Odoo”? 最佳答案 首先转到您的 Odoo Web 模块并打开以下文件。 addons => web => views
我开发了一个同时支持 odoo 10 和 odoo 11 的应用程序,我想在一个部署下部署这个应用程序。意思是如果我访问我的 odoo 应用程序,我应该看到一个应用程序而不是两个应用程序,当我从下拉列
我已经按照教程安装了 odoo+postgres当我尝试在我的 linux 终端中运行 ./odoo-bin 命令时,我得到了这个错误: 2019-09-15 08:48:30,765 5126 ER
我按照教程在 Odoo 8 中创建了一个模块。我在用户中激活了技术功能,然后更新了模块列表,但它没有出现在列表中。 我该怎么办? 最佳答案 跟踪以下内容: checkout __init__.py,
我需要将“Powered by Odoo”页脚中的“Powered”更改为“Made”, 所以我的 Odoo(以前的 OpenERP)版本 8.0-aab3d9f 的页脚将是“Made by Odoo
默认情况下,当我在 odoo 中创建新数据库时,表是在公共(public)模式中创建的。有没有办法更改此配置以及 odoo 创建和使用另一个定义的方案? 最佳答案 没有办法做到这一点,odoo 默认使
我正在尝试使用与 Django 相同的功能: 在 Odoo 中,我有: 如果“c.id = cat_id”,我需要附加“active”类 它是如何在 Odoo 中完成的? 我正在使用:
我已经发送了一些电子邮件营销事件,在“群发邮件”中,我有“电子邮件”按钮的详细信息。当我点击它时,我有“邮件 ID(技术)”、“消息 ID”、“已发送”等列。但是我看不到我发送的电子邮件。 我怎么能看
在 Odoo 中创建发票时,我想过滤“客户”的可用合作伙伴选择。具体来说,我想将合作伙伴联系记录限制为“发票地址”类型的记录,即 res_partner 上的域。的 [('type','=','inv
我是 ODOO 新手,正在寻找捕获 的方法考勤模块中的地理位置 ODOO 的。需要同时记录入住和退房地点 最佳答案 检查此模块,它捕获地理位置:https://odoo-community.org/s
Odoo 中的 Product Master 需要两个不同的表是什么? product.product 和 product.template 有何不同? 最佳答案 由于产品变体,Odoo 有两种产品模
在V11企业版中,部分机型有存档功能,但公司没有。如果我有多家公司,但有一家公司已经停业,我如何禁用或存档该公司,使其不会出现在所有模块中,甚至管理员也无法将其分配给任何用户?似乎一旦创建了公司,即使
是否有一种简单的方法将 OpenERP (oodo) 中的新自定义字段(在客户记录或订单项目中)与外部链接(即描述或 iframe)关联起来,以便它可以链接到不同的系统? 创建记录时,是否有一种简单的
我在odoo社区版中更改了我的公司数据,但它从未反射(reflect)出来,即使我在浏览器缓存中进行了更改。请帮忙enter image description here ODoo 最佳答案 你有两个
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是一名优秀的程序员,十分优秀!