我必须在Odoo 8中存储一个现有的计算字段(仅因为它应该对用户可排序)。字段为debit
,您可以在模块 analytics ,文件 analytic.py ,模型account.analytic.account
中找到。
不幸的是,问题在于该字段是在旧API中声明的,而我正尝试使用该API进行存储。顺便说一句,仅将store=True
添加到该字段是行不通的(此后,每笔记录借记都为0,即使我一次从数据库中删除了列debit
并更新了模块以重新生成它,也是如此),因此我必须使用“旧” @api.depends
。
模型account.analytic.account
具有一个名为line_ids
的One2many字段,该字段指向account.analytic.line
。字段debit
取决于此字段line_ids
和account_id
模型的字段date
,amount
和account.analytic.line
。因此,在新的API中,compute方法应在上面具有此装饰器:
@api.depends('line_ids', 'line_ids.account_id', 'line_ids.date', 'line_ids.amount')
但是我必须用旧的API来告诉我,所以我做了我所知道的。
我的代码:
def _get_analytic_account_to_update_from_analytic_line(self, cr, uid, line_ids,
context=None):
if context is None:
context = {}
lines = self.browse(cr, uid, line_ids, context=context)
analytic_ids = []
for line in lines:
if line.account_id and line.account_id.id not in analytic_ids:
analytic_ids.append(line.account_id.id)
return analytic_ids
_columns = {
'debit': osv_fields.function(
_debit_credit_bal_qtty,
type='float',
string='Debit',
multi='debit_credit_bal_qtty',
digits_compute=dp.get_precision('Account'),
store={
'account.analytic.line': (
_get_analytic_account_to_update_from_analytic_line,
['account_id', 'date', 'amount'],
10
)
},
),
}
但是一定有一个错误,因为每个记录的借方都是0(就像我放store=True
一样)。但是,如果我输入store=False
,则会正确计算每个记录借方。
应该计算值时,工作流甚至都没有进入我的方法_get_analytic_account_to_update_from_analytic_line
。
有人记得这个古老的API store
词典吗?有什么建议吗?
您是否会将整个计算方法迁移到新的API,仅使其存储在数据库中?