diff --git a/yuthon_hr_attendance/controllers/__init__.py b/yuthon_hr_attendance/controllers/__init__.py index b6abc9650..769330494 100644 --- a/yuthon_hr_attendance/controllers/__init__.py +++ b/yuthon_hr_attendance/controllers/__init__.py @@ -2,5 +2,6 @@ from . import attendance_banner_route from . import portal +from . import applet_attendance diff --git a/yuthon_hr_attendance/controllers/applet_attendance.py b/yuthon_hr_attendance/controllers/applet_attendance.py new file mode 100644 index 000000000..af4d81b0f --- /dev/null +++ b/yuthon_hr_attendance/controllers/applet_attendance.py @@ -0,0 +1,52 @@ +from odoo.http import Controller, request, route +from odoo import models, fields, api, http, SUPERUSER_ID, _ +import logging +_logger = logging.getLogger(__name__) +# _logger.info("Connected to MQTT Broker") +class AppletAttendance(Controller): + + @route('/yuthon/att/today', methods=['POST'], type='json', auth='none', csrf=False) + def apple_yuthon_att_today(self): + """ + 小程序获取当前用户打卡信息 + :return: + """ + data = request.httprequest.json + user_id = request.env(user=SUPERUSER_ID)["res.user"].search([('wecom_id', '=', data.get('user_id'))]) + if not user_id: + return {"Msg": "获取失败,没有找到对应用户", 'data': False} + data_info = {'location': '', 'class': '行政班次', 'user_id': '', 'check_in': '', "check_out": '', 'state': '正常'} + today = fields.Date.context_today(self) + attendances = request.env['hr.attendance.detail'].search([ + ('employee_id', '=', user_id.employee_id.id), + ('checkin_time', '>=', today + ' 00:00:00'), + ('checkin_time', '<=', today + ' 23:59:59') + ], order='check_in asc') + if attendances: + first_attendance = attendances[0] + data_info['check_in'] = first_attendance.checkin_time + if len(attendances) > 1: + last_attendance = attendances[-1] + data_info['check_out'] = last_attendance.checkin_time + elif len(attendances) == 1: + data_info['check_out'] = False + return {"Msg": "获取成功", 'data': data_info} + + @route('/yuthon/att/record', methods=['POST'], type='json', auth='none', csrf=False) + def apple_yuthon_att_record(self): + """ + 小程序创建打卡记录 + :return: + """ + data = request.httprequest.json + user_name = data.get('user_id') + employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('user_id', '=', user_name.id)]) + if not employee_id: + return {"Msg": "获取失败,没有找到对应员工", 'data': False} + data_info = {} + self.env['hr.attendance.detail'].create({ + 'employee_id': employee_id.id, + 'checkin_time': data.get('checkin_time'), + }) + return {"Msg": "打卡成功", 'data': data_info} + diff --git a/yuthon_property/models/yuthon_property.py b/yuthon_property/models/yuthon_property.py index 859446766..fb4b9cc3a 100644 --- a/yuthon_property/models/yuthon_property.py +++ b/yuthon_property/models/yuthon_property.py @@ -98,13 +98,6 @@ class YuthonProperty(models.Model): else: record.first_letter = '' - @api.onchange('title_information_ids') - def _onchange_title_information_ids(self): - for rec in self: - if rec.title_information_ids: - latest_title_information = rec.title_information_ids[-1] - rec.title_deed = latest_title_information.title_certificate - @api.onchange('manage_information_ids', 'title_information_ids') def _onchange_information_ids(self): today = fields.Date.today() @@ -246,6 +239,7 @@ class YuthonProperty(models.Model): else: manage_id = False property_list.append([0, 0, {'property_id': record.id, + 'precinct_id': record.precinct_id.id, 'purpose_id': manage_id.purpose_id.id, 'information_line_id': manage_id.id}]) return { @@ -363,10 +357,15 @@ class YuthonProperty(models.Model): property_ids = self.env["yuthon.property"].browse( self._context.get('active_ids', self._context.get('active_id'))) for record in property_ids: + precinct_id = self.env["yuthon.precinct.message"].search([('employee_id.name', '=', record.admin_id.name)]) company_id = record.manage_information_ids[0].company_id.id if record.manage_information_ids else '' title_deed = record.title_information_ids[0].title_certificate if record.title_information_ids else '' record.company_id = company_id record.title_deed = title_deed + record.precinct_id = precinct_id.id if precinct_id else '' + if record.manage_information_ids: + record.manage_information_ids[0].precinct_id = precinct_id.id if precinct_id else '' + class YuthonPropertyWater(models.Model): _name = 'yuthon.property.water' @@ -417,7 +416,7 @@ class ManageInformationLine(models.Model): yuthon_property_id = fields.Many2one('yuthon.property', string="关联物业信息") purpose_id = fields.Many2one('yuthon.resource.purpose', string="管理类型") - precinct_id = fields.Many2one(related='yuthon_property_id.precinct_id',string="所属片区", readonly=False) + precinct_id = fields.Many2one('yuthon.precinct.message', string="所属片区", readonly=False) tenure_type = fields.Selection([('self', '自有'), ('agency', '代管')], string='权属类型') management_area = fields.Float(string="管理面积", digits=(16, 4)) rent_area = fields.Float(string="可租面积", digits=(16, 4)) diff --git a/yuthon_property/views/yuthon_property_views.xml b/yuthon_property/views/yuthon_property_views.xml index 367d086b8..9ccd3c3ed 100644 --- a/yuthon_property/views/yuthon_property_views.xml +++ b/yuthon_property/views/yuthon_property_views.xml @@ -128,7 +128,7 @@ - + diff --git a/yuthon_property_approval/models/property_management.py b/yuthon_property_approval/models/property_management.py index 748753ff2..5563fefbf 100644 --- a/yuthon_property_approval/models/property_management.py +++ b/yuthon_property_approval/models/property_management.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import models, fields, api, exceptions, _ +from datetime import timedelta class PropertyManagement(models.Model): @@ -33,6 +34,7 @@ class PropertyManagement(models.Model): admin_id_all = fields.Many2one('res.users', string="管理员") precinct_id = fields.Many2one('yuthon.precinct.message', string="所属片区") tenure_type = fields.Selection([('self', '自有'), ('agency', '代管')], string='权属类型') + start_time = fields.Date(string="生效日期", default=lambda self: fields.Date.today()) def _get_default_name_title(self): return self._description if self._description else self._name @@ -40,6 +42,11 @@ class PropertyManagement(models.Model): name_title = fields.Char(default=_get_default_name_title) document_ids = fields.Many2many('ir.attachment', string="附件") + @api.onchange('precinct_id') + def _onchange_precinct_id(self): + if self.precinct_id: + self.admin_id_all = self.precinct_id.employee_id.user_id.id + @api.onchange('is_issues') def _onchange_is_issues(self): if self.is_issues: @@ -93,7 +100,6 @@ class PropertyManagement(models.Model): # 直接从关联的上一条记录获取值(如果存在) prev_info = line.information_line_id - precinct_id1 = prev_info.precinct_id.id # 创建新的信息行记录,从prev_info获取缺失的值 info_line_vals = { 'yuthon_property_id': line.property_id.id, @@ -104,12 +110,11 @@ class PropertyManagement(models.Model): 'rent_area': prev_info.rent_area if prev_info else 0.0, 'admin_id': record.admin_id_all.id if record.admin_id_all else prev_info.admin_id.id, 'company_id': record.company_id.id if record.company_id else prev_info.company_id.id if prev_info else False, - 'start_time': fields.Date.today(), + 'start_time': record.start_time, } - + prev_info.end_date = record.start_time - timedelta(days=1) # 创建新记录 self.env['manage.information.line'].create(info_line_vals) - prev_info.precinct_id = precinct_id1 record.write({'is_line': True}) def put_property_management(self): diff --git a/yuthon_property_approval/views/property_management.xml b/yuthon_property_approval/views/property_management.xml index cadb0e327..4c1f0db85 100644 --- a/yuthon_property_approval/views/property_management.xml +++ b/yuthon_property_approval/views/property_management.xml @@ -53,6 +53,7 @@ + @@ -62,7 +63,7 @@ -