我正在尝试创建一个从数据库中获取两个不同日期的模块,create_date和won_date,计算它们之间的天数,并将结果存储在新字段compare_dates中。
代码如下:
def action_set_won(self, cr, uid, ids, context=None):
""" Won semantic: probability = 100 (active untouched) """
stages_leads = {}
for lead in self.browse(cr, uid, ids, context=context):
stage_id = self.stage_find(cr, uid, [lead], lead.team_id.id or False, [(
'probability', '=', 100.0), ('on_change', '=', True)], context=context)
if stage_id:
if stages_leads.get(stage_id):
stages_leads[stage_id].append(lead.id)
else:
stages_leads[stage_id] = [lead.id]
for stage_id, lead_ids in stages_leads.items():
self.write(cr, uid, lead_ids, {'stage_id': stage_id}, context=context)
return self.write(cr, uid, ids, {'probability': 100, 'won_date': datetime.now(), 'compare_dates': abs('won_date' - 'create_date')}, context=context)
File "/mnt/extra-addons/crm_updates/models/models.py", line 37, in action_set_won
return self.write(cr, uid, ids, {'probability': 100, 'won_date': datetime.now(), 'compare_dates': abs(('won_date') - ('create_date'))}, context=context)
TypeError:不支持的操作数类型为-:‘str’和‘str’
发布于 2018-08-02 10:57:18
以下是一个相当简单的解决方案:
# You need the datetime package to calculate between dates
from datetime import datetime
compare_dates = abs((won_date - create_date).days)
https://stackoverflow.com/questions/-100001855
复制相似问题