Mobile Apk: Update on module related to mobile apk

This commit is contained in:
Pranay 2025-01-27 12:07:01 +05:30
parent 89295a4e5a
commit 5807943958
2 changed files with 82 additions and 17 deletions

View File

@ -15,7 +15,6 @@
# Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml # Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list # for the full list
'category': 'Flutter', 'category': 'Flutter',
'license': 'LGPL-3',
'version': '0.1', 'version': '0.1',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly

View File

@ -1,3 +1,5 @@
from logging import exception
from odoo import api, models, _, fields from odoo import api, models, _, fields
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tools.misc import format_date from odoo.tools.misc import format_date
@ -6,12 +8,29 @@ from datetime import datetime
class HRLeave(models.Model): class HRLeave(models.Model):
_inherit = "hr.leave" _inherit = "hr.leave"
def flutter_check_overlap_constrain(self,employee_id, to_date, from_date): def flutter_check_overlap_constrain(self,employee_id, to_date, from_date, fetched_leave_id=None):
if self.env.context.get('leave_skip_date_check', False): if self.env.context.get('leave_skip_date_check', False):
return return
date_from = datetime.fromisoformat(from_date).replace(hour=0, minute=0, second=0) date_from = datetime.fromisoformat(from_date).replace(hour=0, minute=0, second=0)
date_to = datetime.fromisoformat(to_date).replace(hour=23, minute=59, second=59) date_to = datetime.fromisoformat(to_date).replace(hour=23, minute=59, second=59)
employee_id = int(employee_id) employee_id = int(employee_id)
if fetched_leave_id and fetched_leave_id > 0:
all_leaves = self.search([
('date_from', '<', date_to),
('date_to', '>', date_from),
('employee_id', 'in', [employee_id]),
('id','!=', fetched_leave_id),
('state', 'not in', ['cancel', 'refuse']),
])
domain = [
('employee_id', '=', employee_id),
('date_from', '<', date_to),
('date_to', '>', date_from),
('id', '!=', fetched_leave_id),
('state', 'not in', ['cancel', 'refuse']),
]
else:
all_leaves = self.search([ all_leaves = self.search([
('date_from', '<', date_to), ('date_from', '<', date_to),
('date_to', '>', date_from), ('date_to', '>', date_from),
@ -24,6 +43,8 @@ class HRLeave(models.Model):
('date_to', '>', date_from), ('date_to', '>', date_from),
('state', 'not in', ['cancel', 'refuse']), ('state', 'not in', ['cancel', 'refuse']),
] ]
conflicting_holidays = all_leaves.filtered_domain(domain) conflicting_holidays = all_leaves.filtered_domain(domain)
if conflicting_holidays: if conflicting_holidays:
@ -102,6 +123,51 @@ Attempting to double-book your time off won't magically make your vacation 2x be
} }
@api.model @api.model
def submit_leave_flutter_odoo(self,leave_request_data): def submit_leave_flutter_odoo(self,leave_request_data, existing_leave_id = None):
print(leave_request_data) try:
pass date_from = datetime.fromisoformat(leave_request_data['date_from']).replace(hour=0, minute=0, second=0)
date_to = datetime.fromisoformat(leave_request_data['date_to']).replace(hour=23, minute=59, second=59)
if existing_leave_id and existing_leave_id > 0:
leave_id = self.env['hr.leave'].sudo().browse(existing_leave_id)
else:
leave_id = False
if leave_id:
leave_id.sudo().write({
'employee_id': leave_request_data['employee_id'],
'holiday_status_id': leave_request_data['holiday_status_id'],
'request_date_from': date_from.date(),
'request_date_to':date_to.date(),
'name': leave_request_data['description'],
'request_unit_half': leave_request_data['is_half_day'],
'request_date_from_period': 'pm' if leave_request_data['half_day_option'] == 'afternoon' else 'am',
})
leave = leave_id
else:
leave = self.env['hr.leave'].sudo().create({
'employee_id': leave_request_data['employee_id'],
'holiday_status_id': leave_request_data['holiday_status_id'],
'request_date_from': date_from.date(),
'request_date_to':date_to.date(),
'name':leave_request_data['description'],
'request_unit_half': leave_request_data['is_half_day'],
'request_date_from_period': 'pm' if leave_request_data['half_day_option'] == 'afternoon' else 'am',
})
attachment_ids = []
for attachment in leave_request_data['attachments']:
attachment_record = self.env['ir.attachment'].create({
'name': attachment['name'], # Attachment name
'datas': attachment['datas'], # Base64 encoded data
'res_model': 'hr.leave', # Model to link
'res_id': leave.id, # ID of the leave record
})
attachment_ids.append(attachment_record.id)
# Link the attachments to the leave record
if attachment_ids:
leave.supported_attachment_ids = [(6, 0, attachment_ids)]
leave._check_validity()
leave.state = 'confirm'
return {'status': 'success', 'leave_id': leave.id, 'message': ''}
except Exception as e:
return {'status': 'error','leave_id': '', 'message': str(e)}