Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
6 Ответы
6614 Представления

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

Related Posts Ответы Просмотры Активность
0
окт. 17
6762
1
июн. 25
15437
3
апр. 25
5619
Compute Fields Решено
2
июл. 24
3167
1
янв. 24
1851