From a7913b64f908d630370f1a8450ef13cfa28b01b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E6=9C=AA=E5=A4=AE?= <2996985766@qq.com> Date: Tue, 21 Oct 2025 21:11:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=8E=92=E5=BA=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- estate/models/estate_property.py | 16 ++++++------- .../models/hr_attendance_wechat.py | 24 ++++++++----------- .../models/property_meter_archives.py | 19 ++++++++------- .../models/property_meter_water.py | 12 +++++++++- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index cd0c3a84a..0fb178a95 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -82,12 +82,7 @@ class EstateProperty(models.Model): best_price = fields.Float( string="最佳报价", compute="_compute_best_price", store=True ) - create_date_month = fields.Char( - string="创建月份", - compute="_compute_create_date_month", - store=True, - index=True, - ) + create_date_month = fields.Char(string="创建月份", index=True, copy=False) # 房产预期价格必须严格为正数 _sql_constraints = [ ("check_expected_price", "CHECK(expected_price > 0)", "预期价格必须为正数"), @@ -187,9 +182,12 @@ class EstateProperty(models.Model): """拒绝报价""" return self.write({"state": "offer_received"}) - def _compute_create_date_month(self): - for rec in self: + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for rec in records: if rec.create_date: rec.create_date_month = rec.create_date.strftime("%Y-%m") else: - rec.create_date_month = False + rec.create_date_month = fields.Date.today().strftime("%Y-%m") + return records diff --git a/yuthon_hr_attendance/models/hr_attendance_wechat.py b/yuthon_hr_attendance/models/hr_attendance_wechat.py index 4e2450571..a4a45ab5b 100644 --- a/yuthon_hr_attendance/models/hr_attendance_wechat.py +++ b/yuthon_hr_attendance/models/hr_attendance_wechat.py @@ -11,19 +11,7 @@ class HrAttendance(models.Model): userid = fields.Char(string="userid") groupname = fields.Char(string="打卡规则名称") current_data = fields.Date(string="打卡日期", tracking=True) - current_data_month = fields.Char( - string="打卡日期(月份)", - compute="_compute_current_data_month", - store=True, - index=True, - ) - - def _compute_current_data_month(self): - for rec in self: - if rec.current_data: - rec.current_data_month = rec.current_data.strftime("%Y-%m") - else: - rec.current_data_month = False + current_data_month = fields.Char(string="打卡日期(月份)",index=True, copy=False) sch_check_in_time = fields.Datetime(string="上班正常时间") sch_check_out_time = fields.Datetime(string="下班正常时间") @@ -81,7 +69,15 @@ class HrAttendance(models.Model): "domain": [("hr_attendance_id", "=", self.id)], "context": {"hr_attendance_id": self.id}, } - + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for rec in records: + if rec.current_data: + rec.current_data_month = rec.current_data.strftime("%Y-%m") + else: + rec.current_data_month = fields.Date.today().strftime("%Y-%m") + return records @api.constrains("check_in", "check_out", "employee_id") def _check_validity(self): for attendance in self: diff --git a/yuthon_property/models/property_meter_archives.py b/yuthon_property/models/property_meter_archives.py index 5e8cd1125..f0aced931 100644 --- a/yuthon_property/models/property_meter_archives.py +++ b/yuthon_property/models/property_meter_archives.py @@ -214,14 +214,7 @@ class MeterArchivesLine(models.Model): initial_value = fields.Float(string="初始读数") last_read = fields.Float(string="上次读数", store=True, group_operator=None, compute="_compute_last") meter_date = fields.Date(string="任务日期") - meter_date_month = fields.Char(string="任务日期月份", compute="_compute_meter_date_month", store=True, index=True,) - - def _compute_meter_date_month(self): - for rec in self: - if rec.meter_date: - rec.meter_date_month = rec.meter_date.strftime("%Y-%m") - else: - rec.meter_date_month = False + meter_date_month = fields.Char(string="任务日期月份", index=True, copy=False) current_meter = fields.Float(string="本次用量", group_operator=None, compute="_compute_current_meter") current_read = fields.Float(string="本次读数", group_operator=None) @@ -239,6 +232,16 @@ class MeterArchivesLine(models.Model): maximum_count = fields.Integer(string="最大位数") is_push = fields.Boolean(string='推送', default=False) + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for rec in records: + if rec.meter_date: + rec.meter_date_month = rec.meter_date.strftime("%Y-%m") + else: + rec.meter_date_month = fields.Date.today().strftime("%Y-%m") + return records + @api.depends('last_read', 'current_read') def _compute_current_meter(self): for record in self: diff --git a/yuthon_property/models/property_meter_water.py b/yuthon_property/models/property_meter_water.py index 744ca250b..cc286e654 100644 --- a/yuthon_property/models/property_meter_water.py +++ b/yuthon_property/models/property_meter_water.py @@ -188,7 +188,7 @@ class MeterWaterLine(models.Model): last_dosage = fields.Float(string="上次用量", store=True, group_operator=None, compute="_compute_last") last_read = fields.Float(string="上次读数", group_operator=None, compute="_compute_last") meter_date = fields.Date(string="任务日期") - meter_date_month = fields.Char(string="任务日期月份", compute="_compute_meter_date_month", store=True, index=True) + meter_date_month = fields.Char(string="任务日期月份", index=True, copy=False) current_meter = fields.Float(string="本次用量", group_operator=None, compute="_compute_current_meter") current_read = fields.Float(string='本次读数', group_operator=None) unit_number = fields.Char(string='单元编号/用途') @@ -205,6 +205,16 @@ class MeterWaterLine(models.Model): maximum_count = fields.Integer(string='最大位数') is_push = fields.Boolean(string='推送', default=False) + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for rec in records: + if rec.meter_date: + rec.meter_date_month = rec.meter_date.strftime("%Y-%m") + else: + rec.meter_date_month = fields.Date.today().strftime("%Y-%m") + return records + @api.depends('last_read', 'current_read') def _compute_current_meter(self): for record in self: