콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

Hi guys, i need your help with the redefinition of following function fields. I don't really get behind the store parameter in the 'amount' field. Any help or hints appreciated.

def _amount(self, cr, uid, ids, field_name, arg, context=None):

res= {}

for expense in self.browse(cr, uid, ids, context=context):

total = 0.0

for line in expense.line_ids:

total += line.unit_amount * line.unit_quantity

res[expense.id] = total

return res



def _get_expense_from_line(self, cr, uid, ids, context=None):

return [line.expense_id.id for line in self.pool.get('hr.expense.line').browse(cr, uid, ids,

        context=context)]



'amount': fields.function(_amount, string='Total Amount', digits_compute=dp.get_precision('Account'),

store={

'hr.expense.line': (_get_expense_from_line, ['unit_amount','unit_quantity'], 10)

}),

아바타
취소
작성자

Hi Prashant thank you for your answer. Unfortunately i can't answer you under your comment. I think you got me wrong. I want to translate this code from old api to new api and i'm stuck on the store parameter of the 'amount' field.

베스트 답변

Peter, the declaration of computed fields in the new API is explained in the documentation.

Using the new syntax the old `store` dictionary becomes simply `store=True` with an appropriate `@api.depends` decorator on the function implementing the field. The dependencies declared in this manner act as recompute triggers.

Here is an example in the 9.0 source code.

Not sure that's the info you were looking for, though.

아바타
취소
베스트 답변

As long as I know you will not be able to translate that into the new api, the store value dict is not supported anymore in favor of the @api.depends and @api.onchange, but I couldn't find the flexibility of the store with a value dict with triggers. Maybe @fpodoo or @odony or someone that works for Odoo could bring some light to this

아바타
취소
베스트 답변

i think type is missing in your field defining like type= float or char etc.

Otherwise every thing is fine.

아바타
취소
관련 게시물 답글 화면 활동
0
7월 19
3161
1
12월 17
9472
6
1월 16
8100
1
8월 25
931
1
8월 25
1130