Hi,
I need to add another behaviour in the timesheet module where i want to do evaluation by " party, by work and month" , i have developed this code but i still facing some issue and this negative point that it just show 1 record if we have 1 work done for many parties fr example if we have work 1 Done for party Maria, Diego, Alice(3 lines), the negative behaviour here that it just display 1 record for example it shows just record of party “Diego”, here is my code :
class HoursWorkMonthly(ModelSQL, ModelView):
'Hours per Work per Month'
__name__ = 'timesheet.hours_work_monthly'
year = fields.Char('Year')
month = fields.Many2One('ir.calendar.month', "Month")
party = fields.Many2One('party.party', 'Party', required=True)
duration = fields.TimeDelta('duration', 'company_work_time')
work = fields.Many2One('timesheet.work', 'work')
@classmethod
def __setup__(cls):
super(HoursWorkMonthly, cls).__setup__()
cls._order.insert(0, ('year', 'DESC'))
cls._order.insert(1, ('month.index', 'DESC'))
cls._order.insert(2, ('party', 'ASC'))
@classmethod
def table_query(cls):
pool = Pool()
Line = pool.get('timesheet.line')
Month = pool.get('ir.calendar.month')
line = Line.__table__()
month = Month.__table__()
type_name = cls.year.sql_type().base
year_column = Extract('YEAR', line.date).cast(type_name).as_('year')
month_index = Extract('MONTH', line.date)
return line.join(month, condition=month_index == month.id).select(
Max(Extract('MONTH', line.date)
+ Extract('YEAR', line.date) * 100
+ line.work * 1000000).as_('id'),
Max(line.create_uid).as_('create_uid'),
Max(line.create_date).as_('create_date'),
Max(line.write_uid).as_('write_uid'),
Max(line.write_date).as_('write_date'),
year_column,
month.id.as_('month'),
line.work,
line.party,
Sum(line.duration).as_('duration'),
group_by=(year_column, month.id, line.work, line.party)
)
for now this code display if paryt1 do work1 in duration 2h in september and party1 do work1 in duration 3h in september it will show me just 1 record say party1 do work1 duration 5h ins eptember and that what i need but also i need another behaviour that it must show me all the records(all the lines i mean) for 1 work if this work done for many parties for example we have work 1 Done for party Maria, Diego, Alice, I want to show me all the lines and not just 1 record( 1line)
any help will be appreciated, thanks.