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

Hello guys i have inherited the account.analytic.line model and added a selection field on whether the duration affects the sla or not i want to compute the totals for the time that affects only sla i.e when the selection is yes the duration is computed if no it is not computed how do i go about it.Any assistance will be highly appreciated.

this is the link to my view https://ibb.co/eDr2Te

아바타
취소
베스트 답변

Hi,

code of Ibrahim  optimized

@api.multi
@api.depends('timesheet_ids', 'timesheet_ids.sla', 'timesheet_ids.duration')

def _compute_total_duration(self):

    for record in self:

    record.total_duration = sum(record.timesheet_ids.filtered(lambda rec: rec.sla == 'yes').mapped('duration'))

Regards

아바타
취소

Hi Ibrahim,

thank you ^^,

bye

작성자

Thanks Cyril and Ibrahim.THe code is running Perfectly

Hi,

I recommand you to store the value for better performance, y adding strore=True in the definition of your field. To avoid ir.rule test, and better performance, you can add compute_sudo=True too.

Bye

베스트 답변

add dependency to total compute field

ex:

api.dependency('your sla filed from line',....etc fields)

def _amount_total()

아바타
취소
베스트 답변

Hi, 
you want to calculate the Total of the time that affects only sla. 
Considering that : 
your O2M field is :  timesheet_ids

the total field is : total_duration

the affects SLA :  sla

the Duration : duration

then : 

add (compute='_compute_total_duration', store=True) to total_duration

and 

@api.multi
@api.depends('timesheet_ids', 'timesheet_ids.sla', 'timesheet_ids.duration')
def _compute_total_duration(self):
    for record in self:
        total = False
        // Filter only on record with sla = Yes
        timesheets = record.timesheet_ids.filtered(lambda rec: rec.sla == 'yes')
        if timesheets:
            for timesheet in timesheets:
                total += timesheet.duration     // here, you may want to check how to add durations based on your field's signature
        record.total_duration = total                    
아바타
취소

Hi,

I think you forgot something in your code :

total += timesheet

should be

total += timesheet.duration

Bye

second error, :

total = False

should be not before but in for record in self:

I agree Cyril. I have updated my answer

Thank you

Hi,

I add @api.muti in your code

bye

관련 게시물 답글 화면 활동
0
10월 17
6789
1
6월 25
15489
3
4월 25
5701
Compute Fields 해결 완료
2
7월 24
3377
1
1월 24
1865