Merge branch 'cor_cr' into 'master'
Cor cr See merge request prakash.jain/cor-odoo!251
This commit is contained in:
commit
e4a0954bb1
|
@ -73,12 +73,37 @@ with pro_data as (
|
|||
LEFT JOIN custom_project_tags as tag_master ON tag_master.id = cus_pro_tag.custom_project_tags_id
|
||||
group by pro.id
|
||||
),
|
||||
sub_pro_data as (
|
||||
SELECT
|
||||
PRO.parent_project as pproject_id,
|
||||
PRO.date_start as pro_sdate,
|
||||
PRO.date as pro_edate,
|
||||
PRO.active as project_active,
|
||||
PRO.project_type,
|
||||
PRO.pricing_type,
|
||||
PRO.is_sub_project,
|
||||
PRO.id as sub_project,
|
||||
(select project_id from project_subproject_rel as par where pro.id=par.id limit 1) as parent_project,
|
||||
--(select PRO.id from project_subproject_rel as PAR where PRO.id=PAR.project_id limit 1) as parent_project,
|
||||
STRING_AGG(distinct tag_master.name, ', ') as tag_name,
|
||||
PRO.partner_id AS partner_id,
|
||||
PRO.budgeted_revenue as budgeted_revenue,
|
||||
PRO.budgeted_hours2 as budgeted_hours,
|
||||
PRO.expenses_amt as expenses_amt,
|
||||
PRO.hourly_rate AS pro_hourly_rate
|
||||
FROM project_project PRO
|
||||
LEFT JOIN custom_project_tags_project_project_rel AS cus_pro_tag ON pro.id = cus_pro_tag.project_project_id
|
||||
LEFT JOIN custom_project_tags as tag_master ON tag_master.id = cus_pro_tag.custom_project_tags_id
|
||||
where PRO.is_sub_project=True
|
||||
group by pro.id
|
||||
),
|
||||
cons_data1 as (
|
||||
SELECT
|
||||
date_trunc('month', min(PRO_EMP.start_date)) AS min,
|
||||
date_trunc('month', coalesce(max(PRO_EMP.end_date), current_date AT TIME ZONE 'UTC')) AS max,
|
||||
PRO_EMP.start_date as start_date,
|
||||
coalesce(PRO_EMP.end_date, current_date AT TIME ZONE 'UTC') as end_date,
|
||||
PRO_EMP.end_date as end_date,
|
||||
--coalesce(PRO_EMP.end_date, current_date AT TIME ZONE 'UTC') as end_date,
|
||||
PRO_EMP.project_id,
|
||||
PRO_EMP.employee_id,
|
||||
PRO_EMP.role,
|
||||
|
@ -98,14 +123,6 @@ tsheet_data1 as (
|
|||
FROM account_analytic_line AAL
|
||||
group by AAL.project_id, AAL.employee_id
|
||||
),
|
||||
drange_data1 as (
|
||||
SELECT
|
||||
tsheet_data1.project_id,
|
||||
tsheet_data1.employee_id,
|
||||
generate_series(min, max,'1 month'):: date AS start_date,
|
||||
(generate_series(min, max, '1 month'):: date + '1 month' :: interval - '1 day' :: interval):: date AS end_date
|
||||
FROM tsheet_data1
|
||||
),
|
||||
drange_data2 as (
|
||||
SELECT
|
||||
cons_data1.project_id,
|
||||
|
@ -259,6 +276,50 @@ SELECT
|
|||
pro_data.budgeted_hours,
|
||||
pro_data.expenses_amt
|
||||
),
|
||||
data2_sub_project as (
|
||||
SELECT
|
||||
min(sub_pro_data.pro_sdate) as start_date,
|
||||
max(sub_pro_data.pro_edate)as end_date,
|
||||
sub_pro_data.parent_project as project_id,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
null::char as role,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.partner_id,
|
||||
null::int AS employee_id,
|
||||
null::int As timesheet_id,
|
||||
null::timestamp as timesheet_sdatetime,
|
||||
0 as overall_budgeted_revenue,
|
||||
sub_pro_data.budgeted_revenue,
|
||||
sub_pro_data.budgeted_hours,
|
||||
0 as overall_hourly_rate,
|
||||
0 as unit_amount,
|
||||
0.0 AS pro_hourly_rate,
|
||||
0 as timesheet_cost,
|
||||
0.0 AS actual_revenue,
|
||||
0 as actual_cost,
|
||||
sub_pro_data.expenses_amt,
|
||||
0.0 AS profit_amt,
|
||||
0.0 AS profit_per
|
||||
FROM sub_pro_data
|
||||
WHERE sub_pro_data.pricing_type='employee_rate' and sub_pro_data.project_type='hours_no_limit'
|
||||
and sub_pro_data.is_sub_project = TRUE
|
||||
group by
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.partner_id,
|
||||
sub_pro_data.budgeted_revenue,
|
||||
sub_pro_data.budgeted_hours,
|
||||
sub_pro_data.expenses_amt
|
||||
),
|
||||
data3 as (
|
||||
SELECT
|
||||
coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date,
|
||||
|
@ -310,7 +371,6 @@ SELECT
|
|||
pro_data.project_type,
|
||||
pro_data.pricing_type,
|
||||
pro_data.parent_project,
|
||||
--AAL.sub_project,
|
||||
null::int as sub_project,
|
||||
cons_data1.role,
|
||||
pro_data.tag_name,
|
||||
|
@ -383,10 +443,11 @@ SELECT
|
|||
FROM pro_data
|
||||
left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id
|
||||
left join cons_data1 on cons_data1.project_id=AAL.project_id and cons_data1.employee_id=AAL.employee_id
|
||||
and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
|
||||
>= cons_data1.start_date::date + '00:00:00'::time AT TIME ZONE 'UTC'
|
||||
and AAL.end_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
|
||||
<= cons_data1.end_date::date + '23:59:59'::time AT TIME ZONE 'UTC'
|
||||
and (AAL.start_datetime, AAL.end_datetime) OVERLAPS (cons_data1.start_date::date, cons_data1.end_date::date)
|
||||
--and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
|
||||
-- >= cons_data1.start_date::date + '00:00:00'::time AT TIME ZONE 'UTC'
|
||||
--and AAL.end_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
|
||||
-- <= cons_data1.end_date::date + '23:59:59'::time AT TIME ZONE 'UTC'
|
||||
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
|
||||
and COALESCE(pro_data.is_sub_project, FALSE) = False
|
||||
group by
|
||||
|
@ -407,6 +468,103 @@ SELECT
|
|||
cons_data1.cons_timesheet_cost,
|
||||
cons_data1.cons_hourly_cost
|
||||
),
|
||||
data3_sub_project as (
|
||||
SELECT
|
||||
min(sub_pro_data.pro_sdate) as start_date,
|
||||
max(sub_pro_data.pro_edate) as end_date,
|
||||
sub_pro_data.parent_project as project_id,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
null::char as role,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.partner_id,
|
||||
null::int as employee_id,
|
||||
null::int As timesheet_id,
|
||||
null::timestamp as timesheet_sdatetime,
|
||||
sub_pro_data.budgeted_revenue AS overall_budgeted_revenue,
|
||||
0 as budgeted_revenue,
|
||||
0 as budgeted_hours,
|
||||
sub_pro_data.pro_hourly_rate AS overall_hourly_rate,
|
||||
0.0 as unit_amount,
|
||||
0.0 as pro_hourly_rate,
|
||||
0.0 as timesheet_cost,
|
||||
0.0 as actual_revenue,
|
||||
0.0 as actual_cost,
|
||||
sub_pro_data.expenses_amt,
|
||||
0.0 as profit_amt,
|
||||
0.0 as profit_per
|
||||
FROM sub_pro_data
|
||||
where sub_pro_data.pricing_type='employee_rate' and sub_pro_data.project_type='hours_in_consultant'
|
||||
and sub_pro_data.is_sub_project = True
|
||||
group by
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
sub_pro_data.budgeted_revenue,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.partner_id,
|
||||
sub_pro_data.pro_hourly_rate,
|
||||
sub_pro_data.expenses_amt
|
||||
UNION
|
||||
SELECT
|
||||
drange_data2.start_date,
|
||||
drange_data2.end_date,
|
||||
sub_pro_data.parent_project as project_id,
|
||||
--drange_data2.project_id,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
cons_data1.role,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.partner_id,
|
||||
drange_data2.employee_id,
|
||||
null::int As timesheet_id,
|
||||
null::timestamp as timesheet_sdatetime,
|
||||
0 as overall_budgeted_revenue,
|
||||
cons_data1.budgeted_revenue,
|
||||
cons_data1.budgeted_hours,
|
||||
0 as overall_hourly_rate,
|
||||
0 as unit_amount,
|
||||
0 as pro_hourly_rate,
|
||||
0 as timesheet_cost,
|
||||
0 as actual_revenue,
|
||||
0 as actual_cost,
|
||||
0 as expenses_amt,
|
||||
0 as profit_amt,
|
||||
0 as profit_per
|
||||
FROM drange_data2
|
||||
left join sub_pro_data on sub_pro_data.sub_project = drange_data2.project_id
|
||||
left join cons_data1 on cons_data1.project_id = drange_data2.project_id
|
||||
and cons_data1.employee_id=drange_data2.employee_id
|
||||
and (drange_data2.start_date, drange_data2.end_date) OVERLAPS (cons_data1.start_date, cons_data1.end_date)
|
||||
--and drange_data2.start_date >= cons_data1.start_date
|
||||
--and drange_data2.end_date <= cons_data1.end_date
|
||||
where sub_pro_data.pricing_type='employee_rate' and sub_pro_data.project_type='hours_in_consultant'
|
||||
and sub_pro_data.is_sub_project = True
|
||||
group by
|
||||
drange_data2.start_date,
|
||||
drange_data2.end_date,
|
||||
sub_pro_data.parent_project,
|
||||
drange_data2.employee_id,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
cons_data1.role,
|
||||
cons_data1.budgeted_revenue,
|
||||
cons_data1.budgeted_hours,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.partner_id
|
||||
),
|
||||
invoice_data as (SELECT
|
||||
invoice_date.date as start_date,
|
||||
invoice_date.date as end_date,
|
||||
|
@ -436,17 +594,54 @@ invoice_data as (SELECT
|
|||
0.0 AS profit_per
|
||||
from invoice_date
|
||||
left join pro_data on pro_data.pproject_id = invoice_date.project_id --and pro_data.employee_id = invoice_date.employee_id
|
||||
--left join drange_data1 on invoice_date.project_id = drange_data1.project_id and invoice_date.employee_id = drange_data1.employee_id
|
||||
--and invoice_date.date >= drange_data1.start_date and invoice_date.date <= drange_data1.end_date
|
||||
where COALESCE(pro_data.is_sub_project, FALSE) = False
|
||||
),
|
||||
invoice_data_sub as (SELECT
|
||||
invoice_date.date as start_date,
|
||||
invoice_date.date as end_date,
|
||||
--invoice_date.project_id,
|
||||
sub_pro_data.parent_project as project_id,
|
||||
sub_pro_data.project_active,
|
||||
sub_pro_data.project_type,
|
||||
sub_pro_data.pricing_type,
|
||||
sub_pro_data.parent_project,
|
||||
sub_pro_data.sub_project,
|
||||
null::char as role,
|
||||
sub_pro_data.tag_name,
|
||||
sub_pro_data.partner_id,
|
||||
invoice_date.employee_id,
|
||||
null::int As timesheet_id,
|
||||
null::timestamp as timesheet_sdatetime,
|
||||
0 as overall_budgeted_revenue,
|
||||
0 as budgeted_revenue,
|
||||
0 as budgeted_hours,
|
||||
0 as overall_hourly_rate,
|
||||
0 as unit_amount,
|
||||
0 as pro_hourly_rate,
|
||||
0 as timesheet_cost,
|
||||
invoice_date.fixed_amount as actual_revenue,
|
||||
0 as actual_cost,
|
||||
0.0 AS expenses_amt,
|
||||
0.0 AS profit_amt,
|
||||
0.0 AS profit_per
|
||||
from invoice_date
|
||||
left join sub_pro_data on sub_pro_data.sub_project = invoice_date.project_id
|
||||
where sub_pro_data.is_sub_project = True
|
||||
),
|
||||
res as (
|
||||
select * from data1
|
||||
UNION
|
||||
select * from data2
|
||||
UNION
|
||||
select * from data2_sub_project
|
||||
UNION
|
||||
select * from data3
|
||||
UNION
|
||||
select * from data3_sub_project
|
||||
UNION
|
||||
select * from invoice_data
|
||||
UNION
|
||||
select * from invoice_data_sub
|
||||
)
|
||||
select
|
||||
ROW_NUMBER() OVER() as id,
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<search string="Revenue Analysis">
|
||||
<field name="project_id"/>
|
||||
<field name="sub_project"/>
|
||||
<field name="employee_id"/>
|
||||
<field name="tag_name"/>
|
||||
<filter string="Fixed rate" name="fixed" domain="[('pricing_type','=','fixed_rate')]"/>
|
||||
|
|
|
@ -8,13 +8,14 @@ class EmployeeInherit(models.Model):
|
|||
_inherit = 'hr.employee'
|
||||
|
||||
permission_block_history = fields.One2many(comodel_name="timesheet.block.history", inverse_name="employee_id",
|
||||
string="History", required=False )
|
||||
string="History", required=False)
|
||||
|
||||
|
||||
class EmployeePublicInherit(models.Model):
|
||||
_inherit = 'hr.employee.public'
|
||||
|
||||
permission_block_history = fields.One2many(comodel_name="timesheet.block.history", inverse_name="employee_id",
|
||||
string="History", required=False )
|
||||
string="History", required=False)
|
||||
|
||||
|
||||
class TimesheetBlock(models.Model):
|
||||
|
@ -32,60 +33,57 @@ class TimehseetBlock(models.Model):
|
|||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
entry_start_date = datetime.strptime(str(values['start_datetime']),"%Y-%m-%d %H:%M:%S").date()
|
||||
entry_end_date = datetime.strptime(values['end_datetime'],"%Y-%m-%d %H:%M:%S").date()
|
||||
employee_object = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
|
||||
format = "%Y-%m-%d %H:%M:%S"
|
||||
entry_start_date = datetime.strptime(str(values['start_datetime']), format).date()
|
||||
entry_end_date = datetime.strptime(values['end_datetime'], format).date()
|
||||
emp_obj = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
|
||||
# project_manager_group = self.env.ref('hr_timesheet.group_timesheet_manager')
|
||||
permission_block_object = employee_object.permission_block_history.search(
|
||||
[('employee_id', '=', employee_object.id)], order='create_date desc', limit=1)
|
||||
if permission_block_object:
|
||||
if (permission_block_object.start_date <= entry_start_date and permission_block_object.end_date >= entry_start_date) or (
|
||||
permission_block_object.start_date <= entry_end_date and permission_block_object.end_date >= entry_end_date) or (
|
||||
permission_block_object.start_date >= entry_start_date and permission_block_object.end_date <= entry_end_date
|
||||
block_obj = emp_obj.permission_block_history.search(
|
||||
[('employee_id', '=', emp_obj.id)], order='create_date desc', limit=1)
|
||||
if block_obj:
|
||||
if (block_obj.start_date <= entry_start_date and block_obj.end_date >= entry_start_date) or (
|
||||
block_obj.start_date <= entry_end_date and block_obj.end_date >= entry_end_date) or (
|
||||
block_obj.start_date >= entry_start_date and block_obj.end_date <= entry_end_date
|
||||
) or (
|
||||
permission_block_object.end_date >= entry_start_date and permission_block_object.end_date <= entry_end_date
|
||||
block_obj.end_date >= entry_start_date and block_obj.end_date <= entry_end_date
|
||||
):
|
||||
raise AccessError('You are not allowed to create entry for this date!')
|
||||
else:
|
||||
pass
|
||||
return super(TimehseetBlock, self).create(values)
|
||||
|
||||
|
||||
def write(self, record):
|
||||
format = "%Y-%m-%d %H:%M:%S"
|
||||
if 'start_datetime' in record or 'end_datetime' in record or 'project_id' in record or 'sub_project' in record or 'task_id' in record or 'description' in record:
|
||||
if 'start_datetime' in record and 'end_datetime' not in record:
|
||||
entry_start_date = datetime.strptime(str(record['start_datetime']),"%Y-%m-%d %H:%M:%S").date()
|
||||
entry_end_date = datetime.strptime(str(self.end_datetime),"%Y-%m-%d %H:%M:%S").date()
|
||||
entry_start_date = datetime.strptime(str(record['start_datetime']), format).date()
|
||||
entry_end_date = datetime.strptime(str(self.end_datetime), format).date()
|
||||
elif 'start_datetime' not in record and 'end_datetime' in record:
|
||||
entry_start_date = datetime.strptime(str(self.start_datetime), "%Y-%m-%d %H:%M:%S").date()
|
||||
entry_end_date = datetime.strptime(str(record['end_datetime']), "%Y-%m-%d %H:%M:%S").date()
|
||||
entry_start_date = datetime.strptime(str(self.start_datetime), format).date()
|
||||
entry_end_date = datetime.strptime(str(record['end_datetime']), format).date()
|
||||
elif 'start_datetime' in record and 'end_datetime' in record:
|
||||
entry_start_date = datetime.strptime(str(record['start_datetime']),"%Y-%m-%d %H:%M:%S").date()
|
||||
entry_end_date = datetime.strptime(str(record['end_datetime']), "%Y-%m-%d %H:%M:%S").date()
|
||||
entry_start_date = datetime.strptime(str(record['start_datetime']), format).date()
|
||||
entry_end_date = datetime.strptime(str(record['end_datetime']), format).date()
|
||||
else:
|
||||
res_start_date = str(self.start_datetime).split('.', 1)[0]
|
||||
res_end_date = str(self.end_datetime).split('.', 1)[0]
|
||||
entry_start_date = datetime.strptime(str(res_start_date), '%Y-%m-%d %H:%M:%S').date()
|
||||
entry_end_date = datetime.strptime(str(res_end_date), '%Y-%m-%d %H:%M:%S').date()
|
||||
employee_object = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
|
||||
entry_start_date = datetime.strptime(str(res_start_date), format).date()
|
||||
entry_end_date = datetime.strptime(str(res_end_date), format).date()
|
||||
emp_obj = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
|
||||
# project_manager_group = self.env.ref('hr_timesheet.group_timesheet_manager')
|
||||
if self.user_id.id == self.env.uid:
|
||||
permission_block_object = employee_object.permission_block_history.search(
|
||||
[('employee_id', '=', employee_object.id)], order='create_date desc', limit=1)
|
||||
if permission_block_object:
|
||||
if (
|
||||
permission_block_object.start_date <= entry_start_date and permission_block_object.end_date >= entry_start_date) or (
|
||||
permission_block_object.start_date <= entry_end_date and permission_block_object.end_date >= entry_end_date) or (
|
||||
permission_block_object.start_date >= entry_start_date and permission_block_object.end_date <= entry_end_date
|
||||
) or (
|
||||
permission_block_object.end_date >= entry_start_date and permission_block_object.end_date <= entry_end_date
|
||||
):
|
||||
block_obj = emp_obj.permission_block_history.search(
|
||||
[('employee_id', '=', emp_obj.id)], order='create_date desc', limit=1)
|
||||
if block_obj:
|
||||
if (block_obj.start_date <= entry_start_date and block_obj.end_date >= entry_start_date) or (
|
||||
block_obj.start_date <= entry_end_date and block_obj.end_date >= entry_end_date) or (
|
||||
block_obj.start_date >= entry_start_date and block_obj.end_date <= entry_end_date) or (
|
||||
block_obj.end_date >= entry_start_date and block_obj.end_date <= entry_end_date):
|
||||
raise AccessError('You are not allowed to edit entry for this date!')
|
||||
else:
|
||||
pass
|
||||
return super(TimehseetBlock, self).write(record)
|
||||
|
||||
|
||||
# @api.constrains('unit_amount')
|
||||
# def _check_unit_amount(self):
|
||||
# for rec in self:
|
||||
|
@ -100,4 +98,3 @@ class TimehseetBlock(models.Model):
|
|||
end_date = datetime.strptime(str(self.end_datetime), "%Y-%m-%d %H:%M:%S").date()
|
||||
if end_date > current_date:
|
||||
raise AccessError('End date cannot be a future date!')
|
||||
|
||||
|
|
Loading…
Reference in New Issue