You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							108 lines
						
					
					
						
							4.3 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							108 lines
						
					
					
						
							4.3 KiB
						
					
					
				
								# -*- coding: utf-8 -*-
							 | 
						|
								#############################################################################
							 | 
						|
								#
							 | 
						|
								#    Cybrosys Technologies Pvt. Ltd.
							 | 
						|
								#
							 | 
						|
								#    Copyright (C) 2019-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
							 | 
						|
								#    Author: Cybrosys Techno Solutions(odoo@cybrosys.com)
							 | 
						|
								#
							 | 
						|
								#    You can modify it under the terms of the GNU AFFERO
							 | 
						|
								#    GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
							 | 
						|
								#
							 | 
						|
								#    This program is distributed in the hope that it will be useful,
							 | 
						|
								#    but WITHOUT ANY WARRANTY; without even the implied warranty of
							 | 
						|
								#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
							 | 
						|
								#    GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
							 | 
						|
								#
							 | 
						|
								#    You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
							 | 
						|
								#    (AGPL v3) along with this program.
							 | 
						|
								#    If not, see <http://www.gnu.org/licenses/>.
							 | 
						|
								#
							 | 
						|
								#############################################################################
							 | 
						|
								
							 | 
						|
								from datetime import datetime, date, timedelta
							 | 
						|
								
							 | 
						|
								from odoo import models, fields, api, _
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class HrEmployeeDocument(models.Model):
							 | 
						|
								    _name = 'hr.employee.document'
							 | 
						|
								    _description = 'HR Employee Documents'
							 | 
						|
								
							 | 
						|
								    def mail_reminder(self):
							 | 
						|
								        now = datetime.now() + timedelta(days=1)
							 | 
						|
								        date_now = now.date()
							 | 
						|
								        match = self.search([])
							 | 
						|
								        for i in match:
							 | 
						|
								            if i.expiry_date:
							 | 
						|
								                exp_date = i.expiry_date - timedelta(days=7)
							 | 
						|
								                if date_now >= exp_date:
							 | 
						|
								                    mail_content = "  Hello  " + i.employee_ref.name + ",<br>Your Document " + i.name + "is going to expire on " + \
							 | 
						|
								                                   str(i.expiry_date) + ". Please renew it before expiry date"
							 | 
						|
								                    main_content = {
							 | 
						|
								                        'subject': _('Document-%s Expired On %s') % (i.name, i.expiry_date),
							 | 
						|
								                        'author_id': self.env.user.partner_id.id,
							 | 
						|
								                        'body_html': mail_content,
							 | 
						|
								                        'email_to': i.employee_ref.work_email,
							 | 
						|
								                    }
							 | 
						|
								                    self.env['mail.mail'].create(main_content).send()
							 | 
						|
								
							 | 
						|
								    @api.onchange('expiry_date')
							 | 
						|
								    def check_expr_date(self):
							 | 
						|
								        for each in self:
							 | 
						|
								            exp_date = each.expiry_date
							 | 
						|
								            if exp_date and exp_date < date.today():
							 | 
						|
								                return {
							 | 
						|
								                    'warning': {
							 | 
						|
								                        'title': _('Document Expired.'),
							 | 
						|
								                        'message': _("Your Document Is Already Expired.")
							 | 
						|
								                    }
							 | 
						|
								                }
							 | 
						|
								
							 | 
						|
								    name = fields.Char(string='Document Number', required=True, copy=False)
							 | 
						|
								    document_name = fields.Many2one('employee.checklist', string='Document', required=True)
							 | 
						|
								    description = fields.Text(string='Description', copy=False)
							 | 
						|
								    expiry_date = fields.Date(string='Expiry Date', copy=False)
							 | 
						|
								    employee_ref = fields.Many2one('hr.employee', copy=False)
							 | 
						|
								    doc_attachment_id = fields.Many2many('ir.attachment', 'doc_attach_rel', 'doc_id', 'attach_id3', string="Attachment",
							 | 
						|
								                                         help='You can attach the copy of your document', copy=False)
							 | 
						|
								    issue_date = fields.Date(string='Issue Date', default=fields.Date.context_today, copy=False)
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class HrEmployee(models.Model):
							 | 
						|
								    _inherit = 'hr.employee'
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								    def _document_count(self):
							 | 
						|
								        for each in self:
							 | 
						|
								            document_ids = self.env['hr.employee.document'].search([('employee_ref', '=', each.id)])
							 | 
						|
								            each.document_count = len(document_ids)
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								    def document_view(self):
							 | 
						|
								        self.ensure_one()
							 | 
						|
								        domain = [
							 | 
						|
								            ('employee_ref', '=', self.id)]
							 | 
						|
								        return {
							 | 
						|
								            'name': _('Documents'),
							 | 
						|
								            'domain': domain,
							 | 
						|
								            'res_model': 'hr.employee.document',
							 | 
						|
								            'type': 'ir.actions.act_window',
							 | 
						|
								            'view_id': False,
							 | 
						|
								            'view_mode': 'tree,form',
							 | 
						|
								            'view_type': 'form',
							 | 
						|
								            'help': _('''<p class="oe_view_nocontent_create">
							 | 
						|
								                           Click to Create for New Documents
							 | 
						|
								                        </p>'''),
							 | 
						|
								            'limit': 80,
							 | 
						|
								            'context': "{'default_employee_ref': '%s'}" % self.id
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								    document_count = fields.Integer(compute='_document_count', string='# Documents')
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class HrEmployeeAttachment(models.Model):
							 | 
						|
								    _inherit = 'ir.attachment'
							 | 
						|
								
							 | 
						|
								    doc_attach_rel = fields.Many2many('hr.employee.document', 'doc_attachment_id', 'attach_id3', 'doc_id',
							 | 
						|
								                                      string="Attachment", invisible=1)
							 | 
						|
								
							 |