Merge branch 'pawan_branch' into 'development'

update code for timesheet entry

See merge request prakash.jain/cor-odoo!79
This commit is contained in:
pawan.sharma 2021-01-13 05:27:03 -08:00
commit 23b957d9d0
3 changed files with 32 additions and 34 deletions

View File

@ -121,37 +121,18 @@ class AccountAnalyticLine(models.Model):
def create(self, vals):
if vals.get('unit_amount') == 0.0:
raise ValidationError(_("Your can not fill 0.0 hour entry"))
"""if vals.get('employee_id') and vals.get('project_id'):
project = self.env['project.project'].search([('id', '=', vals.get('project_id'))])
if project:
for rec in project.sale_line_employee_ids:
if rec.employee_id.id == vals.get('employee_id'):
remain_hour = rec.budgeted_qty - rec.timesheet_hour
if vals.get('unit_amount') > remain_hour:
raise ValidationError(_("Your can not fill entry more than Budgeted hours"))"""
if vals.get('employee_id') and vals.get('project_id'):
print('VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', self, vals.get('employee_id'), vals.get('project_id'))
project = self.env['project.project'].search([('id', '=', vals.get('project_id'))])
if project:
if project.consultant_timesheet_hrs:
for record in project.consultant_timesheet_hrs:
if record.employee_id.id == vals.get('employee_id'):
record.timesheet_hour = record.timesheet_hour + vals.get('unit_amount')
else:
project.consultant_timesheet_hrs.create({'project_id': vals.get('project_id'),
'employee_id': vals.get('employee_id'),
'timesheet_hour': vals.get('unit_amount')})
else:
project.consultant_timesheet_hrs.create({'project_id': vals.get('project_id'),
'employee_id': vals.get('employee_id'),
'timesheet_hour': vals.get('unit_amount')})
value = super(AccountAnalyticLine, self).create(vals)
# if self.project_id:
# self.project_id._compute_consultant_timesheet_hour()
# print('WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW')
if value and value.project_id:
value.project_id._onchange_calculate_timesheet_hours()
return value
def write(self, vals):
print('AAAAAAAAAA', self)
if vals.get('unit_amount') == 0.0:
raise ValidationError(_("Your can not fill 0.0 hour entry"))
return super().write(vals)
value = super(AccountAnalyticLine, self).write(vals)
print('BBBBBBBBBBBBB', self, vals)
if self.project_id:
self.project_id._onchange_calculate_timesheet_hours()
return value

View File

@ -68,6 +68,22 @@ class Project(models.Model):
consultant_timesheet_hrs = fields.One2many('consultant.timesheet.hrs', 'project_id', "Timesheet Hrs",
copy=False, help="Consultant timesheet hours")
def _onchange_calculate_timesheet_hours(self):
self.consultant_timesheet_hrs = [(6, 0, False)]
if self._origin.id:
self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line
where project_id = %(project_id)s
GROUP BY project_id, employee_id''',
{'project_id': self._origin.id})
res = self._cr.fetchall()
print('RESSSSSSSSSS', res)
if res:
for rec in res:
print('RECCCCCCCCCCCCCCCC', rec)
self.consultant_timesheet_hrs.create({'project_id': rec[0],
'employee_id': rec[1],
'timesheet_hour': rec[2]})
@api.depends('cost', 'expenses_amt', 'budgeted_revenue')
def _compute_calc(self):
for record in self:
@ -133,7 +149,7 @@ class Project(models.Model):
record.cost = cost
record.budgeted_hour_week = budgeted_hour_week
#@api.depends('pricing_type')
# @api.depends('pricing_type')
def _compute_consultant_timesheet_hour(self):
for val in self:
val.consultant_timesheet_hrs = False
@ -145,14 +161,15 @@ class Project(models.Model):
print('TTTTTTTTTTTTTT', res)
if res:
create_timesheet = val.consultant_timesheet_hrs.create({'project_id': res[0],
'employee_id': res[1],
'timesheet_hour': res[2]})
'employee_id': res[1],
'timesheet_hour': res[2]})
print('RRRRRRRRRRRRRRRRRRR', create_timesheet)
for rec in create_timesheet:
print('vvvvvvvvvvvv', rec)
else:
val.consultant_timesheet_hrs = False
#val.consultant_timesheet_hrs = False
# val.consultant_timesheet_hrs = False
class ProjectConsultantTimesheetHrs(models.Model):
_name = 'consultant.timesheet.hrs'

View File

@ -114,7 +114,7 @@
<field name="consultant_cost" invisible="0"/>
</tree>
</field>
<group attrs="{'invisible': [('pricing_type','=','fixed_rate')]}">
<group>
<group>
<!--<field name="cost"/>-->
<field name="consultant_cost"/>
@ -123,7 +123,7 @@
<field name="profit_amt"/>
<field name="profit_per"/>
</group>
<group>
<group attrs="{'invisible': [('pricing_type','=','fixed_rate')]}">
<field name="budgeted_hours"
attrs="{'invisible': [('project_type','!=','hours_in_consultant')]}"/>
<field name="budgeted_hours2" attrs="{'invisible': [('project_type','!=','hours_no_limit')],