CWF TIMESHEET added Month

This commit is contained in:
Pranay 2025-05-08 16:42:19 +05:30
parent 6c86169ee3
commit e9b9eb92ae
3 changed files with 91 additions and 23 deletions

View File

@ -3,6 +3,8 @@ from odoo.exceptions import ValidationError, UserError
from datetime import datetime, timedelta from datetime import datetime, timedelta
import datetime as dt import datetime as dt
from odoo import _ from odoo import _
from calendar import month_name, month
from datetime import date
class CwfTimesheetYearly(models.Model): class CwfTimesheetYearly(models.Model):
_name = 'cwf.timesheet.calendar' _name = 'cwf.timesheet.calendar'
@ -67,6 +69,32 @@ class CwfTimesheet(models.Model):
], default='draft', string='Status') ], default='draft', string='Status')
lines = fields.One2many('cwf.timesheet.line','week_id') lines = fields.One2many('cwf.timesheet.line','week_id')
cwf_calendar_id = fields.Many2one('cwf.timesheet.calendar') 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') @api.depends('name','week_start_date','week_end_date')
def _compute_display_name(self): def _compute_display_name(self):
@ -142,20 +170,46 @@ class CwfWeeklyTimesheet(models.Model):
def _default_week_id(self): def _default_week_id(self):
timesheet = False
current_date = fields.Date.today() current_date = fields.Date.today()
timesheet = self.env['cwf.timesheet'].sudo().search([('week_start_date','<=',current_date),('week_end_date','>=',current_date)],limit=1) timesheet = self.env['cwf.timesheet'].sudo().search([
if timesheet: ('week_start_date', '<=', current_date),
return timesheet.id ('week_end_date', '>=', current_date)
return timesheet ], 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()) 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) 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') cwf_timesheet_lines = fields.One2many('cwf.timesheet.line' ,'weekly_timesheet')
status = fields.Selection([('draft','Draft'),('submitted','Submitted')], default='draft') status = fields.Selection([('draft','Draft'),('submitted','Submitted')], default='draft')
week_start_date = fields.Date(related='week_id.week_start_date') week_start_date = fields.Date(related='week_id.week_start_date')
week_end_date = fields.Date(related='week_id.week_end_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') @api.constrains('week_id', 'employee_id')
def _check_unique_week_employee(self): def _check_unique_week_employee(self):
for record in self: for record in self:

View File

@ -7,7 +7,8 @@
<sheet> <sheet>
<group> <group>
<field name="name"/> <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> </group>
<notebook> <notebook>
<page string="Weeks"> <page string="Weeks">
@ -16,8 +17,13 @@
<field name="name"/> <field name="name"/>
<field name="week_start_date"/> <field name="week_start_date"/>
<field name="week_end_date"/> <field name="week_end_date"/>
<field name="start_month" column_invisible="1"/>
<field name="end_month" column_invisible="1"/>
<field name="status"/> <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> </list>
</field> </field>
</page> </page>
@ -43,23 +49,29 @@
<field name="view_mode">list,form</field> <field name="view_mode">list,form</field>
</record> </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">
<record id="view_timesheet_form" model="ir.ui.view">
<field name="name">cwf.timesheet.form</field> <field name="name">cwf.timesheet.form</field>
<field name="model">cwf.timesheet</field> <field name="model">cwf.timesheet</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Timesheet"> <form string="Timesheet">
<header> <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> </header>
<sheet> <sheet>
<div class="oe_title"> <div class="oe_title">
<label for="name"/> <label for="name"/>
<h1><field name="name" class="oe_inline" readonly="status != 'draft'"/></h1> <h1>
</div> <field name="name" class="oe_inline" readonly="status != 'draft'"/>
</h1>
</div>
<group> <group>
<!-- Section for Employee and Date Range --> <!-- Section for Employee and Date Range -->
<group> <group>
@ -71,7 +83,7 @@
</form> </form>
</field> </field>
</record> </record>
<record id="view_timesheet_list" model="ir.ui.view"> <record id="view_timesheet_list" model="ir.ui.view">
<field name="name">cwf.timesheet.list</field> <field name="name">cwf.timesheet.list</field>
<field name="model">cwf.timesheet</field> <field name="model">cwf.timesheet</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
@ -81,7 +93,7 @@
<field name="week_end_date"/> <field name="week_end_date"/>
</list> </list>
</field> </field>
</record> </record>
<record id="action_cwf_timesheet" model="ir.actions.act_window"> <record id="action_cwf_timesheet" model="ir.actions.act_window">
<field name="name">CWF Timesheet</field> <field name="name">CWF Timesheet</field>
<field name="res_model">cwf.timesheet</field> <field name="res_model">cwf.timesheet</field>
@ -89,5 +101,4 @@
</record> </record>
</odoo> </odoo>

View File

@ -14,11 +14,13 @@
</header> </header>
<sheet> <sheet>
<group> <group>
<field name="week_id" readonly="0"/> <field name="month_id"/>
<field name="employee_id" readonly="1"/> <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"/> <label for="week_start_date" string="Dates"/>
<div class="o_row"> <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"/> <field name="week_end_date" invisible="1"/>
</div> </div>
</group> </group>
@ -147,9 +149,10 @@
</record> </record>
<menuitem id="menu_timesheet_form" name="CWF Weekly Timesheet " <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" <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> </odoo>