update timesheet entry for fixex type

This commit is contained in:
Pawan Kumar 2021-01-11 15:15:46 +05:30
parent 468b0b010f
commit 6a71b602b4
4 changed files with 68 additions and 10 deletions

View File

@ -24,7 +24,7 @@
# always loaded
'data': [
#'security/ir.model.access.csv',
'security/ir.model.access.csv',
#'security/cor_custom_security.xml',
'views/crm_view.xml',
'views/sale_views.xml',

View File

@ -65,6 +65,9 @@ class Project(models.Model):
manager_hour = fields.Float(string='Manager Hour')
employee_hour = fields.Float(string='Employee Hour')
consultant_timesheet_hrs = fields.One2many('consultant.timesheet.hrs', 'project_id', "Timesheet Hrs",
copy=False, compute='_compute_consultant_timesheet_hour',
help="Consultant timesheet hours")
@api.depends('cost', 'expenses_amt', 'budgeted_revenue')
def _compute_calc(self):
@ -131,6 +134,48 @@ class Project(models.Model):
record.cost = cost
record.budgeted_hour_week = budgeted_hour_week
def _compute_consultant_timesheet_hour(self):
for val in self:
print('1111111111111', val._origin.id)
print('222222222222')
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': val._origin.id})
res = self._cr.fetchone()
print('RESSSSSSS', res)
print('55555555', res[0], type(res[0]), res[1], type(res[1]), res[2], type(res[2]))
val.consultant_timesheet_hrs.create({'project_id': res[0],
'employee_id': res[1],
'timesheet_hour': res[2]})
class ProjectConsultantTimesheetHrs(models.Model):
_name = 'consultant.timesheet.hrs'
_description = 'Project Consultant Timesheet Hrs'
project_id = fields.Many2one('project.project', "Project", required=True)
employee_id = fields.Many2one('hr.employee')
timesheet_hour = fields.Float("Timesheet Hour", default=0.0)
consultant_cost = fields.Float("Actual Cost", default=0.0)
# def _compute_consultant_timesheet_hour(self):
# for val in self:
# print('1111111111111', val.project_id._origin.id)
# print('222222222222')
# 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': val.project_id._origin.id})
# res = self._cr.fetchone()
# print('RESSSSSSS', res)
# val.create((0, 0, {'project_id': res[0],
# 'employee_id': res[1],
# 'timesheet_hour': res[2]}))
# if res and res[1] and res[2]:
# val.employee_id = res[1]
# val.timesheet_hour = res[2]
# else:
# val.timesheet_hour = 0.0
class InheritProjectProductEmployeeMap(models.Model):
_inherit = 'project.sale.line.employee.map'
@ -180,17 +225,17 @@ class InheritProjectProductEmployeeMap(models.Model):
if val.hour_distribution == 'Percentage':
if val.role == 'Manager':
val.cost = val.project_id.budgeted_revenue * (val.project_id.manager_per / 100) * (
val.distribution_per / 100)
val.distribution_per / 100)
else:
val.cost = val.project_id.budgeted_revenue * (val.project_id.employee_per / 100) * (
val.distribution_per / 100)
val.distribution_per / 100)
if val.price_unit > 0.0:
val.budgeted_qty = val.cost / val.price_unit
else:
val.cost = 0.0
# val.cost = val.budgeted_qty * val.price_unit
#val.consultant_cost = val.timesheet_hour * val.employee_price
#self.project_id.onchange_budgeted_hour()
# val.consultant_cost = val.timesheet_hour * val.employee_price
# self.project_id.onchange_budgeted_hour()
@api.depends('sale_line_id', 'sale_line_id.price_unit', 'timesheet_product_id')
def _compute_price_unit(self):
@ -203,4 +248,4 @@ class InheritProjectProductEmployeeMap(models.Model):
line.currency_id = line.timesheet_product_id.currency_id
else:
# line.price_unit = 0
line.currency_id = False
line.currency_id = False

View File

@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_cor_custom_cor_custom,cor_custom.cor_custom,model_cor_custom_cor_custom,base.group_user,1,1,1,1
access_consultant_timesheet_hrs_puser,consultant.timesheet.hrs,model_consultant_timesheet_hrs,project.group_project_user,1,0,0,0
access_consultant_timesheet_hrs_pmanager,consultant.timesheet.hrs,model_consultant_timesheet_hrs,project.group_project_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_cor_custom_cor_custom access_consultant_timesheet_hrs_puser cor_custom.cor_custom consultant.timesheet.hrs model_cor_custom_cor_custom model_consultant_timesheet_hrs base.group_user project.group_project_user 1 1 0 1 0 1 0
3 access_consultant_timesheet_hrs_pmanager consultant.timesheet.hrs model_consultant_timesheet_hrs project.group_project_manager 1 1 1 1

View File

@ -45,8 +45,9 @@
widget="radio"/>
<field name="project_type" attrs="{'invisible': [('pricing_type', '=', 'fixed_rate')]}"
widget="radio"/>
<field name="budgeted_revenue"
attrs="{'invisible': [('pricing_type','=','fixed_rate')], 'required': [('pricing_type','!=','fixed_rate')]}"/>
<field name="budgeted_revenue" required="1" />
<!-- attrs="{'invisible': [('pricing_type','=','fixed_rate')], 'required': [('pricing_type','!=','fixed_rate')]}"-->
<field name="hour_distribution" widget="radio"
attrs="{'invisible': ['|',('project_type','!=','hours_in_consultant'),('pricing_type','=','fixed_rate')]}"/>
<field name="manager_per" attrs="{'invisible': [('hour_distribution','!=','Percentage')]}"/>
@ -60,8 +61,11 @@
<label for="timesheet_product_id" string="Service"
attrs="{'invisible': [('bill_type', '=', 'customer_task')]}"/>
</div>
<field name="timesheet_product_id" nolabel="1"
<!--<field name="timesheet_product_id" nolabel="1"
attrs="{'invisible': ['|', '|', ('allow_timesheets', '=', False), ('sale_order_id', '!=', False), '&amp;', ('pricing_type', '!=', 'fixed_rate'), ('bill_type', '!=', 'customer_task')], 'required': ['&amp;', ('allow_billable', '=', True), ('allow_timesheets', '=', True)]}"
context="{'default_type': 'service', 'default_service_policy': 'delivered_timesheet', 'default_service_type': 'timesheet'}"/>-->
<field name="timesheet_product_id" nolabel="1"
invisible="1"
context="{'default_type': 'service', 'default_service_policy': 'delivered_timesheet', 'default_service_type': 'timesheet'}"/>
<field name="sale_order_id" invisible="1"/>
<field name="sale_line_id" string="Default Sales Order Item"
@ -101,6 +105,14 @@
<field name="budgeted_hour_week"/>
</tree>
</field>
<field name="consultant_timesheet_hrs" attrs="{'invisible': [('pricing_type','!=','fixed_rate')]}">
<tree editable="top">
<field name="project_id" invisible="1"/>
<field name="employee_id" invisible="0"/>
<field name="timesheet_hour" invisible="0"/>
<field name="consultant_cost" invisible="0"/>
</tree>
</field>
<group attrs="{'invisible': [('pricing_type','=','fixed_rate')]}">
<group>
<!--<field name="cost"/>-->