CWF TIMESHEET added Month
This commit is contained in:
parent
6c86169ee3
commit
e9b9eb92ae
|
|
@ -3,6 +3,8 @@ from odoo.exceptions import ValidationError, UserError
|
|||
from datetime import datetime, timedelta
|
||||
import datetime as dt
|
||||
from odoo import _
|
||||
from calendar import month_name, month
|
||||
from datetime import date
|
||||
|
||||
class CwfTimesheetYearly(models.Model):
|
||||
_name = 'cwf.timesheet.calendar'
|
||||
|
|
@ -67,6 +69,32 @@ class CwfTimesheet(models.Model):
|
|||
], default='draft', string='Status')
|
||||
lines = fields.One2many('cwf.timesheet.line','week_id')
|
||||
cwf_calendar_id = fields.Many2one('cwf.timesheet.calendar')
|
||||
start_month = fields.Selection(
|
||||
[(str(i), month_name[i]) for i in range(1, 13)],
|
||||
string='Start Month',
|
||||
compute='_compute_months',
|
||||
store=True
|
||||
)
|
||||
|
||||
end_month = fields.Selection(
|
||||
[(str(i), month_name[i]) for i in range(1, 13)],
|
||||
string='End Month',
|
||||
compute='_compute_months',
|
||||
store=True
|
||||
)
|
||||
|
||||
@api.depends('week_start_date', 'week_end_date')
|
||||
def _compute_months(self):
|
||||
for rec in self:
|
||||
if rec.week_start_date:
|
||||
rec.start_month = str(rec.week_start_date.month)
|
||||
else:
|
||||
rec.start_month = False
|
||||
|
||||
if rec.week_end_date:
|
||||
rec.end_month = str(rec.week_end_date.month)
|
||||
else:
|
||||
rec.end_month = False
|
||||
|
||||
@api.depends('name','week_start_date','week_end_date')
|
||||
def _compute_display_name(self):
|
||||
|
|
@ -142,20 +170,46 @@ class CwfWeeklyTimesheet(models.Model):
|
|||
|
||||
|
||||
def _default_week_id(self):
|
||||
timesheet = False
|
||||
current_date = fields.Date.today()
|
||||
timesheet = self.env['cwf.timesheet'].sudo().search([('week_start_date','<=',current_date),('week_end_date','>=',current_date)],limit=1)
|
||||
if timesheet:
|
||||
return timesheet.id
|
||||
return timesheet
|
||||
timesheet = self.env['cwf.timesheet'].sudo().search([
|
||||
('week_start_date', '<=', current_date),
|
||||
('week_end_date', '>=', current_date)
|
||||
], limit=1)
|
||||
return timesheet.id if timesheet else False
|
||||
|
||||
def _get_week_id_domain(self):
|
||||
for rec in self:
|
||||
return [('week_start_date.month_number','=',2)]
|
||||
pass
|
||||
|
||||
month_id = fields.Selection(
|
||||
[(str(i), month_name[i]) for i in range(1, 13)],
|
||||
string='Month'
|
||||
)
|
||||
week_id = fields.Many2one('cwf.timesheet', 'Week', default=lambda self: self._default_week_id())
|
||||
|
||||
employee_id = fields.Many2one('hr.employee', default=lambda self: self.env.user.employee_id.id)
|
||||
cwf_timesheet_lines = fields.One2many('cwf.timesheet.line' ,'weekly_timesheet')
|
||||
status = fields.Selection([('draft','Draft'),('submitted','Submitted')], default='draft')
|
||||
week_start_date = fields.Date(related='week_id.week_start_date')
|
||||
week_end_date = fields.Date(related='week_id.week_end_date')
|
||||
|
||||
@api.onchange('month_id')
|
||||
def _onchange_month(self):
|
||||
if self.month_id:
|
||||
year = self.week_start_date.year if self.week_start_date else fields.Date.today().year
|
||||
start = date(year, int(self.month_id), 1)
|
||||
if int(self.month_id) == 12:
|
||||
end = date(year + 1, 1, 1) - timedelta(days=1)
|
||||
else:
|
||||
end = date(year, int(self.month_id) + 1, 1) - timedelta(days=1)
|
||||
self = self.with_context(month_start=start, month_end=end)
|
||||
|
||||
@api.onchange('week_id')
|
||||
def _onchange_week_id(self):
|
||||
if self.week_id and self.week_id.week_start_date:
|
||||
self.month_id = str(self.week_id.week_start_date.month)
|
||||
|
||||
@api.constrains('week_id', 'employee_id')
|
||||
def _check_unique_week_employee(self):
|
||||
for record in self:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<button name="action_generate_weeks" string="Generate Week Periods" type="object" class="oe_highlight"/>
|
||||
<button name="action_generate_weeks" string="Generate Week Periods" type="object"
|
||||
class="oe_highlight"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Weeks">
|
||||
|
|
@ -16,8 +17,13 @@
|
|||
<field name="name"/>
|
||||
<field name="week_start_date"/>
|
||||
<field name="week_end_date"/>
|
||||
<field name="start_month" column_invisible="1"/>
|
||||
<field name="end_month" column_invisible="1"/>
|
||||
<field name="status"/>
|
||||
<button name="send_timesheet_update_email" string="Send Update Email" invisible="status == 'submitted'" type="object" confirm="You can't revert this action. Please check twice before Submitting?" class="oe_highlight"/>
|
||||
<button name="send_timesheet_update_email" string="Send Update Email"
|
||||
invisible="status == 'submitted'" type="object"
|
||||
confirm="You can't revert this action. Please check twice before Submitting?"
|
||||
class="oe_highlight"/>
|
||||
</list>
|
||||
</field>
|
||||
</page>
|
||||
|
|
@ -43,8 +49,11 @@
|
|||
<field name="view_mode">list,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_timesheet_calendar_form" name="CWF Timesheet Calendar" parent="hr_attendance_extended.menu_attendance_attendance" action="cwf_timesheet.action_cwf_timesheet_calendar" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
|
||||
<menuitem id="menu_cwf_attendance_attendance" name="CWF" parent="hr_attendance.menu_hr_attendance_root"
|
||||
sequence="6" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
|
||||
|
||||
<menuitem id="menu_timesheet_calendar_form" name="CWF Timesheet Calendar" parent="menu_cwf_attendance_attendance"
|
||||
action="cwf_timesheet.action_cwf_timesheet_calendar" groups="hr_attendance.group_hr_attendance_manager"/>
|
||||
|
||||
|
||||
<record id="view_timesheet_form" model="ir.ui.view">
|
||||
|
|
@ -53,12 +62,15 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Timesheet">
|
||||
<header>
|
||||
<button name="send_timesheet_update_email" string="Send Email" type="object" invisible="status != 'draft'"/>
|
||||
<button name="send_timesheet_update_email" string="Send Email" type="object"
|
||||
invisible="status != 'draft'"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_title">
|
||||
<label for="name"/>
|
||||
<h1><field name="name" class="oe_inline" readonly="status != 'draft'"/></h1>
|
||||
<h1>
|
||||
<field name="name" class="oe_inline" readonly="status != 'draft'"/>
|
||||
</h1>
|
||||
</div>
|
||||
<group>
|
||||
<!-- Section for Employee and Date Range -->
|
||||
|
|
@ -89,5 +101,4 @@
|
|||
</record>
|
||||
|
||||
|
||||
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@
|
|||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="week_id" readonly="0"/>
|
||||
<field name="employee_id" readonly="1"/>
|
||||
<field name="month_id"/>
|
||||
<field name="week_id" readonly="0" domain="['|',('start_month','=',month_id),('end_month','=',month_id)]"/>
|
||||
<field name="employee_id" readonly="0" groups="hr_attendance.group_hr_attendance_manager"/>
|
||||
<field name="employee_id" readonly="1" groups="hr_employee_extended.group_external_user"/>
|
||||
<label for="week_start_date" string="Dates"/>
|
||||
<div class="o_row">
|
||||
<field name="week_start_date" widget="daterange" options="{'end_date_field': 'week_end_date'}"/>
|
||||
<field name="week_start_date" widget="daterange" options="{'end_date_field.month()': 'week_end_date'}"/>
|
||||
<field name="week_end_date" invisible="1"/>
|
||||
</div>
|
||||
</group>
|
||||
|
|
@ -147,9 +149,10 @@
|
|||
</record>
|
||||
|
||||
|
||||
|
||||
<menuitem id="menu_timesheet_form" name="CWF Weekly Timesheet "
|
||||
parent="hr_attendance_extended.menu_attendance_attendance" action="action_cwf_weekly_timesheet" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
|
||||
parent="menu_cwf_attendance_attendance" action="action_cwf_weekly_timesheet" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
|
||||
<menuitem id="menu_timesheet_form_line" name="CWF Timesheet Lines"
|
||||
parent="hr_attendance_extended.menu_attendance_attendance" action="action_cwf_timesheet_line" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
|
||||
parent="menu_cwf_attendance_attendance" action="action_cwf_timesheet_line" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
|
||||
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue