Slink/sos_brm/wizard/sos_brm_report_wizard.py

64 lines
2.2 KiB
Python
Executable File

from odoo import models, fields, api
import io
from datetime import date, timedelta
from odoo.exceptions import UserError
class SOS_BRM_Report_Wizard(models.TransientModel):
_name = 'sos_brm_action_report_wizard'
_description = 'BRM Report Wizard'
cross_dept_action = fields.Selection(
selection=[
('all', 'Both'),
('cross_dept', 'Cross-Dept'),
('inter_dept', 'Intra-Dept')
],
string='Type',
default='all'
)
done_by = fields.Many2one(
'res.users',
string='Responsible')
department = fields.Many2one('sos_departments', string='Department')
status = fields.Selection([ ('all', 'All'),('open', 'Open'),('close', 'Closed'),('hold', 'Hold')], default='open' , string="Status")
def generate_report(self):
# Build domain for filtering records
domain = []
if self.done_by:
domain.append(('responsible_person', '=', self.done_by.id))
if self.status != 'all':
domain.append(('status', '=', self.status))
if self.department:
domain.append(('department', '=', self.department.id))
if self.cross_dept_action != "all":
domain.append(('cross_dept_action', '=', self.cross_dept_action))
# Search for records
records = self.env['sos_brm_action'].search(domain)
if not records:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': ('No Records Found'),
'message': ('No Records Found'),
'type': 'warning',
'sticky': False,
}
}
# Generate report with filtered record IDs
return self.env.ref('sos_brm.action_brm_summary_report').report_action(
records.ids,
data={
'done_by' : self.done_by.id,
'department':self.department.id,
'department_name':self.department.name,
'status' : self.status,
'cross_dept_action' : self.cross_dept_action
}
)