diff --git a/yuthon_property/models/property_meter_archives.py b/yuthon_property/models/property_meter_archives.py index 10656dd19..beb3ccbfb 100644 --- a/yuthon_property/models/property_meter_archives.py +++ b/yuthon_property/models/property_meter_archives.py @@ -8,15 +8,16 @@ class PropertyMeterArchives(models.Model): _description = '电表库' name = fields.Char(string='仪表编号') - unit_number = fields.Char(string='单元编号') + unit_number = fields.Char(string='单元编号/用途') installation_location = fields.Char(string='安装位置') is_state = fields.Boolean(string='是否启用') type = fields.Selection([('public', '公共'), ('fees', '收费')], string='类型') gauge_magnification = fields.Integer(string='仪表倍率', default=1) - maximum_count = fields.Integer(string='标准用量', default=999999) - lessee_id = fields.Many2one(related='yuthon_property_id.lessee_id', string='承租方', store=True) + maximum_count = fields.Integer(string='最大位数') + lessee_id = fields.Many2one('property.tenant.information', string='承租方', store=True, compute='_compute_lessee_id') employee_ids = fields.Many2many('hr.employee', string='抄表人') - meter_type = fields.Selection([('electric', '电表'), ('water', '水表')], string='仪表类型') + epitope_values = fields.Char(string='表位置') + meter_type = fields.Selection([('electric', '电表'), ('water', '水表'), ('smart', '智能电表')], string='仪表类型') other = fields.Char(string='其他') meter_date = fields.Date(string='任务日期') last_dosage = fields.Float(string='上次用量') @@ -33,7 +34,15 @@ class PropertyMeterArchives(models.Model): receivables = fields.Float(string="应收", compute='_compute_receivables', store=True) last_reading_time = fields.Date(string="最后读数时间") standards_id = fields.Many2one('yuthon.electricity.setting', string='标准') - yuthon_property_id = fields.Many2one('yuthon.property', string='关联物业信息') + yuthon_property_ids = fields.Many2many('yuthon.property', string='物业信息') + + @api.depends('yuthon_property_ids') + def _compute_lessee_id(self): + for record in self: + if record.yuthon_property_ids: + record.lessee_id = record.yuthon_property_ids[0].lessee_id + else: + record.lessee_id = False @api.depends('line_loss', 'current_meter', 'unit') def _compute_receivables(self): @@ -52,6 +61,14 @@ class PropertyMeterArchives(models.Model): record.write({'maximum_count': 99999, }) + def open_record(self): + return { + 'type': 'ir.actions.act_window', + 'res_model': 'property.meter.archives', + 'res_id': self.id, + 'view_mode': 'form', + } + @api.depends('lessee_id') def _compute_archives_state(self): for record in self: @@ -95,19 +112,24 @@ class PropertyMeterArchives(models.Model): if record.current_read > record.last_read: record.current_meter = record.current_read - record.last_read else: - record.current_meter = record.maximum_count - record.last_read + record.current_read + if record.maximum_count > 0: + max_value = 10 ** record.maximum_count - 1 + record.current_meter = max_value - record.last_read + record.current_read + else: + record.current_meter = 0 - @api.onchange('yuthon_property_id') + @api.onchange('yuthon_property_ids') def _onchange_property(self): - if self.yuthon_property_id: + if self.yuthon_property_ids: meter_list = [] - property_id = self.env['yuthon.property'].search([('id', '=', self.yuthon_property_id.id)]) - property_id.is_electricity_meter = True - meter_list.append((0, 0, { - 'yuthon_property_id':property_id.id, - 'property_meter_archives_id':self.id.origin, - })) - property_id.energy_meter_ids = meter_list + for yuthon_property_id in self.yuthon_property_ids: + property_id = self.env['yuthon.property'].search([('id', '=', yuthon_property_id.origin.id)]) + property_id.is_meter = True + meter_list.append((0, 0, { + 'yuthon_property_id': property_id.id, + 'property_meter_water_id': self.id.origin, + })) + property_id.water_meter_ids = meter_list def action_property_meter_wizard(self): return { diff --git a/yuthon_property/models/property_meter_water.py b/yuthon_property/models/property_meter_water.py index 37f1f80c6..22b47945d 100644 --- a/yuthon_property/models/property_meter_water.py +++ b/yuthon_property/models/property_meter_water.py @@ -7,15 +7,16 @@ class PropertyMeterWater(models.Model): _description = '水表库' name = fields.Char(string='仪表编号') - unit_number = fields.Char(string='单元编号') + unit_number = fields.Char(string='单元编号/用途') installation_location = fields.Char(string='安装位置') is_state = fields.Boolean(string='是否启用') type = fields.Selection([('public', '公共'), ('fees', '收费')], string='类型') gauge_magnification = fields.Integer(string='仪表倍率', default=1) - maximum_count = fields.Integer(string='标准用量', default=99999) - lessee_id = fields.Many2one(related='yuthon_property_id.lessee_id', string='承租方', store=True) + maximum_count = fields.Integer(string='最大位数') + lessee_id = fields.Many2one('property.tenant.information', store=True, compute='_compute_lessee_id', string="承租方") employee_ids = fields.Many2many('hr.employee', string='抄表人') meter_type = fields.Selection([('electric', '电表'), ('water', '水表')], string='仪表类型') + epitope_values = fields.Char(string='表位置') other = fields.Char(string='其他') meter_date = fields.Date(string='任务日期') last_dosage = fields.Float(string='上次用量') @@ -32,7 +33,23 @@ class PropertyMeterWater(models.Model): last_reading_time = fields.Date(string="最后读数时间") water_state = fields.Selection([('stop', '停用'), ('use', '使用'), ('rent', '出租')], string='状态', compute='_compute_water_state', store=True) standards_id = fields.Many2one('yuthon.electricity.setting', string='标准') - yuthon_property_id = fields.Many2one('yuthon.property', string='关联物业信息') + yuthon_property_ids = fields.Many2many('yuthon.property', string='物业信息') + + def open_record(self): + return { + 'type': 'ir.actions.act_window', + 'res_model': 'property.meter.water', + 'res_id': self.id, + 'view_mode': 'form', + } + + @api.depends('yuthon_property_ids') + def _compute_lessee_id(self): + for record in self: + if record.yuthon_property_ids: + record.lessee_id = record.yuthon_property_ids[0].lessee_id + else: + record.lessee_id = False @api.depends('line_loss', 'current_meter', 'unit') def _compute_receivables(self): @@ -95,26 +112,31 @@ class PropertyMeterWater(models.Model): if record.current_read > record.last_read: record.current_meter = record.current_read - record.last_read else: - record.current_meter = record.maximum_count - record.last_read + record.current_read + if record.maximum_count > 0: + max_value = 10 ** record.maximum_count - 1 + record.current_meter = max_value - record.last_read + record.current_read + else: + record.current_meter = 0 - @api.onchange('yuthon_property_id') + @api.onchange('yuthon_property_ids') def _onchange_property(self): - if self.yuthon_property_id: + if self.yuthon_property_ids: meter_list = [] - property_id = self.env['yuthon.property'].search([('id', '=', self.yuthon_property_id.id)]) - property_id.is_meter = True - meter_list.append((0, 0, { - 'yuthon_property_id': property_id.id, - 'property_meter_water_id': self.id.origin, - })) - property_id.water_meter_ids = meter_list + for yuthon_property_id in self.yuthon_property_ids: + property_id = self.env['yuthon.property'].search([('id', '=', yuthon_property_id.id)]) + property_id.is_meter = True + meter_list.append((0, 0, { + 'yuthon_property_id': property_id.id, + 'property_meter_water_id': self.id.origin, + })) + property_id.water_meter_ids = meter_list def action_property_water_wizard(self): return { "type": "ir.actions.act_window", - "name": "批量导入物业电表", + "name": "批量导入物业水表", "res_model": "property.water.wizard", "view_mode": "form", "target": "new", diff --git a/yuthon_property/views/property_meter_archives_views.xml b/yuthon_property/views/property_meter_archives_views.xml index c9d3d4d4f..00af49e11 100644 --- a/yuthon_property/views/property_meter_archives_views.xml +++ b/yuthon_property/views/property_meter_archives_views.xml @@ -10,9 +10,11 @@