我试图创建从工厂日起2个月的预期日期时间。我的代码是:
@api.one
@api.depends('date_plant','nursery_plandate')
def calculateplandate(self):
fmt = '%Y-%m-%d'
if self.date_plant:
d1 = self.date_plant
conv = datetime.date(d1)
d2 = datetime.strptimes(str(conv),fmt)
d3 = d2.month
hasil = d3+2
self.nursery_plandate = hasil
我的错误是:
^{pr2}$
在odoo 9.0中-字段。日期以及字段。日期时间有from_string()和to_string()方法。 您可以使用这些来创建日期/日期时间对象,然后根据需要进行操作。在
此错误的原因是,您将字符串而不是日期传递给日期时间.日期()。当我们收到一个日期数据时,它将是字符串类型,你必须把它转换成日期类型。在
试试这个代码:-I我包括一个样本代码增加60天你的工厂日期。请根据您的需要进行必要的修改。在
希望这有帮助。在
谢谢你的回答,我为我的案子找到了另一个答案,像这样:
我发现了另一个问题,我不能得到月的价值浮动,例如我得到价值月为1,5,我希望从种植日的预期日是1,5个月。在
相关问题 更多 >
编程相关推荐