Merge branch 'development' of http://103.74.223.20:8085/prakash.jain/cor-odoo into pawan_branch

This commit is contained in:
Pawan Kumar 2021-01-07 15:10:12 +05:30
commit 77cba6b0f2
5 changed files with 70 additions and 18 deletions

View File

@ -14,7 +14,52 @@ class AccountAnalyticLine(models.Model):
start_time = fields.Float(string='Start Time', digits=(16, 2))
end_time = fields.Float(string='End Time', digits=(16, 2))
unit_amount = fields.Float('Duration', default=0.0)
@api.onchange('employee_id')
def _onchange_employee_id(self):
domain = []
if self.employee_id and self.employee_id.user_id:
manager_id = self.env['project.project'].search(
[('user_id', '=', self.employee_id.user_id.id), ('allow_forecast', '=', True)]).ids
emp_project_ids = self.env['project.project'].search(
[('privacy_visibility', 'in', ('employees', 'portal')), ('allow_forecast', '=', True)]).ids
project_ids = self.env['project.project'].search(
[('privacy_visibility', '=', 'followers'), ('allow_forecast', '=', True),
('allowed_internal_user_ids', 'in', self.employee_id.user_id.id)]).ids
consul_ids = self.env['project.sale.line.employee.map'].search([('employee_id', '=', self.employee_id.id)])
consul_project_ids = [val.project_id.id for val in consul_ids]
emp_all_project_ids = manager_id + emp_project_ids + project_ids + consul_project_ids
domain = [('id', 'in', list(set(emp_all_project_ids)))]
result = {
'domain': {'project_id': domain},
}
return result
@api.onchange('project_id')
def _onchange_project_id(self):
domain = [] if not self.project_id else [('project_id', '=', self.project_id.id)]
manager_id = []
user_ids = []
consul_project_ids = []
if self.project_id:
consul_ids = self.env['project.sale.line.employee.map'].search([('project_id', '=', self.project_id.id)])
consul_project_ids = [val.employee_id.id for val in consul_ids]
if self.project_id and self.project_id.user_id:
manager_id = self.env['hr.employee'].search([('user_id', '=', self.project_id.user_id.id)]).ids
if self.project_id and self.project_id.privacy_visibility in ('employees', 'portal'):
user_ids = self.env['hr.employee'].search([('user_id', '!=', False)]).ids
if self.project_id and self.project_id.privacy_visibility == 'followers':
user_ids = self.env['hr.employee'].search(
[('user_id', 'in', self.project_id.allowed_internal_user_ids.ids)]).ids
project_all_emp_ids = manager_id + user_ids + consul_project_ids
result = {
'domain': {'task_id': domain, 'employee_id': [('id', 'in', project_all_emp_ids)]},
}
if self.project_id != self.task_id.project_id:
# reset task when changing project
self.task_id = False
return result
_sql_constraints = [
('check_start_time_lower_than_24', 'CHECK(start_time <= 24)', 'You cannot have a start hour greater than 24'),

View File

@ -41,13 +41,13 @@ class Project(models.Model):
start_date = fields.Date(string='Start Date')
end_date = fields.Date(string='End Date')
budgeted_hours = fields.Float(string='Total Budgeted Hours', compute='_compute_consultant_timesheet_hours')
budgeted_hours = fields.Float(string='Total Budgeted Hours', compute='_compute_calc')
budgeted_hours2 = fields.Float(string='Total Budgeted Hours')
budgeted_revenue = fields.Float(string='Budgeted Revenue', digits=(16, 2))
expenses_per = fields.Float(string='Expenses (%)', digits=(16, 2))
expenses_amt = fields.Float(string='Expenses Amount', digits=(16, 2))
cost = fields.Float("Total Revenue", compute='onchange_compute_values', store=True)
consultant_cost = fields.Float("Actual Cost", compute='_compute_consultant_timesheet_hours')
consultant_cost = fields.Float("Actual Cost", compute='_compute_calc')
other_expenses = fields.Float(string='Other Expenses', related='expenses_amt')
total_expenses = fields.Float(string='Total Expenses', digits=(16, 2), compute='_compute_calc', store=True)
hourly_rate = fields.Float("Hourly Rate", default=0.0)
@ -65,6 +65,8 @@ class Project(models.Model):
manager_hour = fields.Float(string='Manager Hour')
employee_hour = fields.Float(string='Employee Hour')
@api.depends('cost', 'expenses_amt', 'budgeted_revenue')
def _compute_consultant_timesheet_hours(self):
for record in self:
consultant_cost = 0.0
@ -76,6 +78,10 @@ class Project(models.Model):
record.budgeted_hours = hour
total_exp = record.consultant_cost + record.expenses_amt
record.total_expenses = total_exp
profit_amt = record.budgeted_revenue - total_exp
record.profit_amt = profit_amt
if record.profit_amt > 0 and record.budgeted_revenue > 0:
record.profit_per = (record.profit_amt / record.budgeted_revenue) * 100
if record.project_type == 'hours_in_consultant' and record.budgeted_hours > 0.0:
record.hourly_rate = (record.budgeted_revenue / record.budgeted_hours)
if record.project_type == 'hours_no_limit' and record.budgeted_hours2 > 0.0:
@ -113,16 +119,6 @@ class Project(models.Model):
if self.budgeted_hours > 0.0:
self.hourly_rate = (self.budgeted_revenue / self.budgeted_hours)
@api.depends('cost', 'expenses_amt', 'budgeted_revenue')
def _compute_calc(self):
for record in self:
total_exp = record.consultant_cost + record.expenses_amt
record.total_expenses = total_exp
profit_amt = record.budgeted_revenue - total_exp
record.profit_amt = profit_amt
if record.profit_amt > 0 and record.budgeted_revenue > 0:
record.profit_per = (record.profit_amt / record.budgeted_revenue) * 100
@api.depends('sale_line_employee_ids')
def onchange_compute_values(self):
for record in self:
@ -159,7 +155,7 @@ class InheritProjectProductEmployeeMap(models.Model):
def _compute_timesheet_hour(self):
for val in self:
self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line
self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line
where project_id = %(project_id)s and employee_id = %(employee_id)s
GROUP BY project_id, employee_id''',
{'project_id': val.project_id._origin.id, 'employee_id': val.employee_id.id, })
@ -207,4 +203,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

@ -15,6 +15,17 @@
</field>
</record>-->
<record id="view_account_analytic_line_inherit1" model="ir.ui.view">
<field name="name">Analytic line</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="analytic.view_account_analytic_line_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='unit_amount']" position="replace">
<field name="unit_amount" string="Quantity"/>
</xpath>
</field>
</record>
<record id="hr_timesheet_line_tree_inherit1" model="ir.ui.view">
<field name="name">account.analytic.line.tree.hr_timesheet_inherit1</field>
<field name="model">account.analytic.line</field>

View File

@ -6,11 +6,11 @@
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<!--<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="action_view_account_analytic_line" icon="fa-usd"
attrs="{'invisible': [('allow_billable','=',False)]}" string="Cost/Revenue" widget="statinfo">
</button>
</div>
</div>-->
<xpath expr="//field[@name='user_id']" position="replace">
<field name="user_id" string="Project Manager" widget="many2one_avatar_user" required="0"
attrs="{'readonly':[('active','=',False)]}" domain="[('share', '=', False)]"/>

View File

@ -321,8 +321,8 @@ class Planning(models.Model):
)
else:
name = '%s - %s %s' % (
start_datetime.date(),
end_datetime.date(),
datetime.strftime(start_datetime.date(), "%d/%m/%Y"),
datetime.strftime(end_datetime.date(), "%d/%m/%Y"),
name
)