我对openerp很新,并且已经完成了任务。我的第一个问题听起来很愚蠢,我怎么能在开幕式上把日期字段搅拌到一个月。 2.使用下面的代码我试图获得水库中的水平衡基本上从水表中计算出来 - 以获得平衡这必须像库存控制中的数量一样工作
def _water_balance(self, cr, uid, ids, field_name, arg, context):
res = {}
bal = 0.0
for rec in self.browse(cr, uid, ids, context=context):
for traject in rec.trajectory_ids:
trajectory_balance = self.pool.get('supply.trajectory').browse(cr, uid, traject.id , context=context).trajectory_balance
bal += float(trajectory_balance)
res[rec.id] = bal
return res
答案 0 :(得分:0)
您可以使用strftime函数(例如
)从datetime字段获取月份month = datetimefield.strftime("%m") # Month of the datetimefield
month = datetime.now().strftime("%m") # Current month
刚刚更改了几个代码尝试以下,
def _water_balance(self, cr, uid, ids, field_name, arg, context):
res = {}
for rec in self.browse(cr, uid, ids, context=context):
res[rec.id] = 0.00
bal = 0.0
for traject in rec.trajectory_ids:
bal += float(traject.trajectory_balance)
res[rec.id] = bal
return res