|
|
|
@@ -6,69 +6,93 @@ from odoo.exceptions import UserError, ValidationError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PropertyMeterArchives(models.Model):
|
|
|
|
|
_name = 'property.meter.archives'
|
|
|
|
|
_description = '电表库'
|
|
|
|
|
_order = 'number asc'
|
|
|
|
|
_name = "property.meter.archives"
|
|
|
|
|
_description = "电表库"
|
|
|
|
|
_order = "number asc"
|
|
|
|
|
|
|
|
|
|
name = fields.Char(string='仪表编号')
|
|
|
|
|
unit_number = fields.Char(string='单元编号/用途')
|
|
|
|
|
number = fields.Integer(related='epitope_values_id.sequence', string="序号", store=True)
|
|
|
|
|
sequence1 = fields.Integer(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='最大位数')
|
|
|
|
|
lessee_id = fields.Many2one('property.tenant.information', string='承租方', store=True, compute='_compute_lessee_id')
|
|
|
|
|
employee_ids = fields.Many2many('hr.employee', string='抄表人')
|
|
|
|
|
epitope_values = fields.Char(string='表位置')
|
|
|
|
|
epitope_values_id = fields.Many2one('yuthon.epitope.values', string='表位置')
|
|
|
|
|
other = fields.Char(string='其他')
|
|
|
|
|
unit = fields.Float(string='当月单价')
|
|
|
|
|
archives_state = fields.Selection([('stop', '停用'), ('use', '正常'), ('rent', '出租')], string='状态', compute='_compute_archives_state', store=True, default='use')
|
|
|
|
|
name = fields.Char(string="仪表编号")
|
|
|
|
|
unit_number = fields.Char(string="单元编号/用途")
|
|
|
|
|
number = fields.Integer(
|
|
|
|
|
related="epitope_values_id.sequence", string="序号", store=True
|
|
|
|
|
)
|
|
|
|
|
sequence1 = fields.Integer(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="最大位数")
|
|
|
|
|
lessee_id = fields.Many2one(
|
|
|
|
|
"property.tenant.information",
|
|
|
|
|
string="承租方",
|
|
|
|
|
store=True,
|
|
|
|
|
compute="_compute_lessee_id",
|
|
|
|
|
)
|
|
|
|
|
employee_ids = fields.Many2many("hr.employee", string="抄表人")
|
|
|
|
|
epitope_values = fields.Char(string="表位置")
|
|
|
|
|
epitope_values_id = fields.Many2one("yuthon.epitope.values", string="表位置")
|
|
|
|
|
other = fields.Char(string="其他")
|
|
|
|
|
unit = fields.Float(string="当月单价")
|
|
|
|
|
archives_state = fields.Selection(
|
|
|
|
|
[("stop", "停用"), ("use", "正常"), ("rent", "出租")],
|
|
|
|
|
string="状态",
|
|
|
|
|
compute="_compute_archives_state",
|
|
|
|
|
store=True,
|
|
|
|
|
default="use",
|
|
|
|
|
)
|
|
|
|
|
start_time = fields.Date(string="安装日期")
|
|
|
|
|
end_time = fields.Date(string="拆除日期")
|
|
|
|
|
line_loss = fields.Float(string="线损", default=0.02)
|
|
|
|
|
standards_id = fields.Many2one('yuthon.electricity.setting', string='标准')
|
|
|
|
|
yuthon_property_ids = fields.Many2many('yuthon.property', string='物业信息')
|
|
|
|
|
line_ids = fields.One2many('meter.archives.line', 'archives_id', string='明细行')
|
|
|
|
|
remarks = fields.Text(string='备注')
|
|
|
|
|
state = fields.Selection([('reading', '已抄'), ('unreading', '未抄')], string='抄表状态', default='unreading')
|
|
|
|
|
standards_id = fields.Many2one("yuthon.electricity.setting", string="标准")
|
|
|
|
|
yuthon_property_ids = fields.Many2many("yuthon.property", string="物业信息")
|
|
|
|
|
line_ids = fields.One2many("meter.archives.line", "archives_id", string="明细行")
|
|
|
|
|
remarks = fields.Text(string="备注")
|
|
|
|
|
state = fields.Selection(
|
|
|
|
|
[("reading", "已抄"), ("unreading", "未抄")],
|
|
|
|
|
string="抄表状态",
|
|
|
|
|
default="unreading",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# @api.model_create_multi 多条创建
|
|
|
|
|
@api.model
|
|
|
|
|
def create(self, vals):
|
|
|
|
|
record = super().create(vals)
|
|
|
|
|
if 'name' in vals and vals['name']:
|
|
|
|
|
existing_records = self.search([('name', '=', vals['name'])])
|
|
|
|
|
if "name" in vals and vals["name"]:
|
|
|
|
|
existing_records = self.search([("name", "=", vals["name"])])
|
|
|
|
|
if existing_records:
|
|
|
|
|
raise ValidationError(f"仪表编号 '{vals['name']}' 已存在,请使用其他编号!")
|
|
|
|
|
record.archives_state = 'rent' if record.lessee_id else 'use'
|
|
|
|
|
raise ValidationError(
|
|
|
|
|
f"仪表编号 '{vals['name']}' 已存在,请使用其他编号!"
|
|
|
|
|
)
|
|
|
|
|
record.archives_state = "rent" if record.lessee_id else "use"
|
|
|
|
|
return record
|
|
|
|
|
|
|
|
|
|
def update_epitope_values(self):
|
|
|
|
|
meter_ids = self.env["property.meter.archives"].browse(
|
|
|
|
|
self._context.get('active_ids', self._context.get('active_id'))
|
|
|
|
|
self._context.get("active_ids", self._context.get("active_id"))
|
|
|
|
|
)
|
|
|
|
|
for meter in meter_ids:
|
|
|
|
|
for property in meter.yuthon_property_ids:
|
|
|
|
|
existing_energy = self.env['yuthon.property.energy'].search([
|
|
|
|
|
('yuthon_property_id', '=', property.id),
|
|
|
|
|
('property_meter_archives_id', '=', meter.id)
|
|
|
|
|
], limit=1)
|
|
|
|
|
existing_energy = self.env["yuthon.property.energy"].search(
|
|
|
|
|
[
|
|
|
|
|
("yuthon_property_id", "=", property.id),
|
|
|
|
|
("property_meter_archives_id", "=", meter.id),
|
|
|
|
|
],
|
|
|
|
|
limit=1,
|
|
|
|
|
)
|
|
|
|
|
if not existing_energy:
|
|
|
|
|
self.env['yuthon.property.energy'].create({
|
|
|
|
|
'property_meter_archives_id': meter.id,
|
|
|
|
|
'yuthon_property_id': property.id,
|
|
|
|
|
})
|
|
|
|
|
self.env["yuthon.property.energy"].create(
|
|
|
|
|
{
|
|
|
|
|
"property_meter_archives_id": meter.id,
|
|
|
|
|
"yuthon_property_id": property.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@api.onchange('name')
|
|
|
|
|
@api.onchange("name")
|
|
|
|
|
def _onchange_line_ids(self):
|
|
|
|
|
if self.line_ids:
|
|
|
|
|
for line in self.line_ids:
|
|
|
|
|
line.name = self.name
|
|
|
|
|
|
|
|
|
|
@api.depends('yuthon_property_ids.lessee_id')
|
|
|
|
|
@api.depends("yuthon_property_ids.lessee_id")
|
|
|
|
|
def _compute_lessee_id(self):
|
|
|
|
|
for record in self:
|
|
|
|
|
if record.yuthon_property_ids:
|
|
|
|
@@ -78,27 +102,26 @@ class PropertyMeterArchives(models.Model):
|
|
|
|
|
|
|
|
|
|
def open_record(self):
|
|
|
|
|
return {
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'res_model': 'property.meter.archives',
|
|
|
|
|
'res_id': self.id,
|
|
|
|
|
'view_mode': 'form',
|
|
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
|
"res_model": "property.meter.archives",
|
|
|
|
|
"res_id": self.id,
|
|
|
|
|
"view_mode": "form",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@api.depends('lessee_id')
|
|
|
|
|
@api.depends("lessee_id")
|
|
|
|
|
def _compute_archives_state(self):
|
|
|
|
|
for record in self:
|
|
|
|
|
if record.lessee_id:
|
|
|
|
|
record.archives_state = 'rent'
|
|
|
|
|
record.archives_state = "rent"
|
|
|
|
|
else:
|
|
|
|
|
record.archives_state = 'use'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
record.archives_state = "use"
|
|
|
|
|
|
|
|
|
|
def button_archives_state(self):
|
|
|
|
|
archives_ids = self.env["property.meter.archives"].browse(self._context.get('active_ids', self._context.get('active_id')))
|
|
|
|
|
archives_ids = self.env["property.meter.archives"].browse(
|
|
|
|
|
self._context.get("active_ids", self._context.get("active_id"))
|
|
|
|
|
)
|
|
|
|
|
for record in archives_ids:
|
|
|
|
|
record.archives_state = 'stop'
|
|
|
|
|
|
|
|
|
|
record.archives_state = "stop"
|
|
|
|
|
|
|
|
|
|
# @api.onchange('current_read', 'last_read')
|
|
|
|
|
# def _onchange_current_meter(self):
|
|
|
|
@@ -112,18 +135,17 @@ class PropertyMeterArchives(models.Model):
|
|
|
|
|
# else:
|
|
|
|
|
# record.current_meter = 0
|
|
|
|
|
|
|
|
|
|
@api.onchange('yuthon_property_ids')
|
|
|
|
|
@api.onchange("yuthon_property_ids")
|
|
|
|
|
def _onchange_property(self):
|
|
|
|
|
if not self.line_ids:
|
|
|
|
|
return
|
|
|
|
|
sync_vals = {}
|
|
|
|
|
if self.yuthon_property_ids:
|
|
|
|
|
sync_vals['yuthon_property_ids'] = [(6, 0, self.yuthon_property_ids.ids)]
|
|
|
|
|
sync_vals["yuthon_property_ids"] = [(6, 0, self.yuthon_property_ids.ids)]
|
|
|
|
|
if sync_vals:
|
|
|
|
|
self.line_ids.write(sync_vals)
|
|
|
|
|
self.update_epitope_values()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def action_property_meter_wizard(self):
|
|
|
|
|
return {
|
|
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
@@ -134,96 +156,160 @@ class PropertyMeterArchives(models.Model):
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def reading_publish(self):
|
|
|
|
|
menu_id = self.env['ir.ui.menu'].search([('name', '=', '水表抄表')])
|
|
|
|
|
reading_ids = self.env["property.meter.archives"].browse(self._context.get('active_ids', self._context.get('active_id')))
|
|
|
|
|
menu_id = self.env["ir.ui.menu"].search([("name", "=", "水表抄表")])
|
|
|
|
|
reading_ids = self.env["property.meter.archives"].browse(
|
|
|
|
|
self._context.get("active_ids", self._context.get("active_id"))
|
|
|
|
|
)
|
|
|
|
|
for record in reading_ids:
|
|
|
|
|
for employee_id in record.employee_ids:
|
|
|
|
|
url = f'https://oa.thtzjt.com/web#id={self.id}&cids=2&action={menu_id.action.id}&model=property.meter.archives&view_type=list&menu_id={menu_id.id}'
|
|
|
|
|
we_id = self.env['hr.employee'].search([('id', '=', employee_id)]).wecom_userid
|
|
|
|
|
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='notice', user_id=we_id,
|
|
|
|
|
title="通知公告",
|
|
|
|
|
description="您有抄表待处理,请及时处理",
|
|
|
|
|
url=url, btntxt="详细信息")
|
|
|
|
|
url = f"https://oa.thtzjt.com/web#id={self.id}&cids=2&action={menu_id.action.id}&model=property.meter.archives&view_type=list&menu_id={menu_id.id}"
|
|
|
|
|
we_id = (
|
|
|
|
|
self.env["hr.employee"]
|
|
|
|
|
.search([("id", "=", employee_id)])
|
|
|
|
|
.wecom_userid
|
|
|
|
|
)
|
|
|
|
|
self.sudo().env["wecom.apps"].sync_send_message_textcard(
|
|
|
|
|
category="notice",
|
|
|
|
|
user_id=we_id,
|
|
|
|
|
title="通知公告",
|
|
|
|
|
description="您有抄表待处理,请及时处理",
|
|
|
|
|
url=url,
|
|
|
|
|
btntxt="详细信息",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def batch_reading_push(self):
|
|
|
|
|
active_ids = self._context.get('active_ids', [])
|
|
|
|
|
active_ids = self._context.get("active_ids", [])
|
|
|
|
|
return {
|
|
|
|
|
'name': '电水表推送',
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'res_model': 'electric.water.wizard',
|
|
|
|
|
'view_mode': 'form',
|
|
|
|
|
'view_type': 'form',
|
|
|
|
|
'target': 'new',
|
|
|
|
|
'context': {
|
|
|
|
|
'default_meter_ids': [(6, 0, active_ids)]
|
|
|
|
|
}
|
|
|
|
|
"name": "电水表推送",
|
|
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
|
"res_model": "electric.water.wizard",
|
|
|
|
|
"view_mode": "form",
|
|
|
|
|
"view_type": "form",
|
|
|
|
|
"target": "new",
|
|
|
|
|
"context": {"default_meter_ids": [(6, 0, active_ids)]},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MeterArchivesLine(models.Model):
|
|
|
|
|
_name = 'meter.archives.line'
|
|
|
|
|
_description = '电表库明细行'
|
|
|
|
|
_order = 'number asc, sequence asc'
|
|
|
|
|
_name = "meter.archives.line"
|
|
|
|
|
_description = "电表库明细行"
|
|
|
|
|
_order = "number asc, sequence asc"
|
|
|
|
|
|
|
|
|
|
archives_id = fields.Many2one('property.meter.archives', string='电表库', required=True, ondelete='cascade')
|
|
|
|
|
archives_id = fields.Many2one(
|
|
|
|
|
"property.meter.archives", string="电表库", required=True, ondelete="cascade"
|
|
|
|
|
)
|
|
|
|
|
# name = fields.Char(string='仪表编号')
|
|
|
|
|
number = fields.Integer(related='epitope_values_id.sequence', string="序号", store=True)
|
|
|
|
|
sequence = fields.Integer(related='archives_id.sequence1', string="表序号", store=True)
|
|
|
|
|
epitope_values_id = fields.Many2one('yuthon.epitope.values', string='表位置')
|
|
|
|
|
lessee_id = fields.Many2one('property.tenant.information', string='承租方')
|
|
|
|
|
yuthon_property_ids = fields.Many2many('yuthon.property', string='物业信息')
|
|
|
|
|
last_meter = fields.Date(string='上次抄表日期', compute="_compute_last")
|
|
|
|
|
last_dosage = fields.Float(string='上次用量', store=True, group_operator=None, compute="_compute_last")
|
|
|
|
|
last_read = fields.Float(string='上次读数', store=True, group_operator=None, compute="_compute_last")
|
|
|
|
|
meter_date = fields.Date(string='任务日期')
|
|
|
|
|
number = fields.Integer(
|
|
|
|
|
related="epitope_values_id.sequence", string="序号", store=True
|
|
|
|
|
)
|
|
|
|
|
sequence = fields.Integer(
|
|
|
|
|
related="archives_id.sequence1", string="表序号", store=True
|
|
|
|
|
)
|
|
|
|
|
epitope_values_id = fields.Many2one("yuthon.epitope.values", string="表位置")
|
|
|
|
|
lessee_id = fields.Many2one("property.tenant.information", string="承租方")
|
|
|
|
|
yuthon_property_ids = fields.Many2many("yuthon.property", string="物业信息")
|
|
|
|
|
last_meter = fields.Date(string="上次抄表日期", compute="_compute_last")
|
|
|
|
|
last_dosage = fields.Float(
|
|
|
|
|
string="上次用量", store=True, group_operator=None, compute="_compute_last"
|
|
|
|
|
)
|
|
|
|
|
last_read = fields.Float(
|
|
|
|
|
string="上次读数", store=True, group_operator=None, compute="_compute_last"
|
|
|
|
|
)
|
|
|
|
|
meter_date = fields.Date(string="任务日期")
|
|
|
|
|
|
|
|
|
|
current_meter = fields.Float(string='本次用量', store=True, group_operator=None)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
current_read = fields.Float(string='本次读数', group_operator=None)
|
|
|
|
|
unit_number = fields.Char(string='单元编号/用途')
|
|
|
|
|
gauge_magnification = fields.Integer(string='仪表倍率', readonly=True, default=1, group_operator=None)
|
|
|
|
|
current_meter = fields.Float(string="本次用量", store=True, group_operator=None)
|
|
|
|
|
|
|
|
|
|
current_read = fields.Float(string="本次读数", group_operator=None)
|
|
|
|
|
unit_number = fields.Char(string="单元编号/用途")
|
|
|
|
|
gauge_magnification = fields.Integer(
|
|
|
|
|
string="仪表倍率", readonly=True, default=1, group_operator=None
|
|
|
|
|
)
|
|
|
|
|
last_reading_time = fields.Date(string="最后读数时间")
|
|
|
|
|
receivables = fields.Float(string="应收", compute='_compute_receivables', store=True, group_operator=None)
|
|
|
|
|
unit = fields.Float(string='当月单价', group_operator=None, igits=(6, 4))
|
|
|
|
|
receivables = fields.Float(
|
|
|
|
|
string="应收", compute="_compute_receivables", store=True, group_operator=None
|
|
|
|
|
)
|
|
|
|
|
unit = fields.Float(string="当月单价", group_operator=None, igits=(6, 4))
|
|
|
|
|
line_loss = fields.Float(string="线损", default=0.02)
|
|
|
|
|
type = fields.Selection([('public', '公共'), ('fees', '收费')], string='类型')
|
|
|
|
|
type = fields.Selection([("public", "公共"), ("fees", "收费")], string="类型")
|
|
|
|
|
start_time = fields.Date(string="安装日期")
|
|
|
|
|
end_time = fields.Date(string="拆除日期")
|
|
|
|
|
employee_ids = fields.Many2many('hr.employee', string='抄表人')
|
|
|
|
|
remarks = fields.Text(string='备注')
|
|
|
|
|
archives_state = fields.Selection([('stop', '停用'), ('use', '正常'), ('rent', '出租')], string='状态',
|
|
|
|
|
default='use')
|
|
|
|
|
state = fields.Selection([('reading', '已抄'), ('unreading', '未抄')], string='抄表状态', default='unreading')
|
|
|
|
|
maximum_count = fields.Integer(string='最大位数')
|
|
|
|
|
employee_ids = fields.Many2many("hr.employee", string="抄表人")
|
|
|
|
|
remarks = fields.Text(string="备注")
|
|
|
|
|
archives_state = fields.Selection(
|
|
|
|
|
[("stop", "停用"), ("use", "正常"), ("rent", "出租")],
|
|
|
|
|
string="状态",
|
|
|
|
|
default="use",
|
|
|
|
|
)
|
|
|
|
|
state = fields.Selection(
|
|
|
|
|
[("reading", "已抄"), ("unreading", "未抄")],
|
|
|
|
|
string="抄表状态",
|
|
|
|
|
default="unreading",
|
|
|
|
|
)
|
|
|
|
|
maximum_count = fields.Integer(string="最大位数")
|
|
|
|
|
|
|
|
|
|
@api.depends('line_loss', 'current_meter', 'unit')
|
|
|
|
|
@api.depends("line_loss", "current_meter", "unit")
|
|
|
|
|
def _compute_receivables(self):
|
|
|
|
|
for record in self:
|
|
|
|
|
if record.line_loss and record.current_meter and record.unit:
|
|
|
|
|
record.receivables = record.current_meter * record.unit * (1 + record.line_loss) * record.gauge_magnification
|
|
|
|
|
record.receivables = (
|
|
|
|
|
record.current_meter
|
|
|
|
|
* record.unit
|
|
|
|
|
* (1 + record.line_loss)
|
|
|
|
|
* record.gauge_magnification
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def update_meter(self):
|
|
|
|
|
current_year = datetime.now().year
|
|
|
|
|
target_date = datetime(current_year, 9, 1).date()
|
|
|
|
|
domain = [
|
|
|
|
|
('state', '=', 'unreading'), # 只处理未抄的记录
|
|
|
|
|
('meter_date', '<', target_date) # 任务日期在9月之前
|
|
|
|
|
("state", "=", "unreading"), # 只处理未抄的记录
|
|
|
|
|
("meter_date", "<", target_date), # 任务日期在9月之前
|
|
|
|
|
]
|
|
|
|
|
active_ids = self._context.get('active_ids', self._context.get('active_id'))
|
|
|
|
|
active_ids = self._context.get("active_ids", self._context.get("active_id"))
|
|
|
|
|
if active_ids:
|
|
|
|
|
domain.append(('id', 'in', active_ids))
|
|
|
|
|
unread_meter_lines = self.env['meter.archives.line'].search(domain)
|
|
|
|
|
domain.append(("id", "in", active_ids))
|
|
|
|
|
unread_meter_lines = self.env["meter.archives.line"].search(domain)
|
|
|
|
|
if unread_meter_lines:
|
|
|
|
|
unread_meter_lines.write({'state': 'reading'})
|
|
|
|
|
unread_meter_lines.write({"state": "reading"})
|
|
|
|
|
|
|
|
|
|
@api.depends('archives_id', 'last_dosage', 'last_read', 'last_meter', 'current_meter', 'current_read', 'maximum_count')
|
|
|
|
|
@api.depends(
|
|
|
|
|
"archives_id",
|
|
|
|
|
"last_dosage",
|
|
|
|
|
"last_read",
|
|
|
|
|
"last_meter",
|
|
|
|
|
"current_meter",
|
|
|
|
|
"current_read",
|
|
|
|
|
"maximum_count",
|
|
|
|
|
)
|
|
|
|
|
def _compute_last(self):
|
|
|
|
|
"""
|
|
|
|
|
上次用量,读数,超标日期
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
for i in self:
|
|
|
|
|
last_id = self.env['meter.archives.line'].search([('meter_date', '<', i.meter_date), ('archives_id', '=', i.archives_id.id)]).sorted('meter_date')
|
|
|
|
|
last_id = (
|
|
|
|
|
self.env["meter.archives.line"]
|
|
|
|
|
.search(
|
|
|
|
|
[
|
|
|
|
|
("meter_date", "<", i.meter_date),
|
|
|
|
|
("archives_id", "=", i.archives_id.id),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
.sorted("meter_date")
|
|
|
|
|
)
|
|
|
|
|
if last_id:
|
|
|
|
|
i.last_dosage = last_id[-1].current_meter
|
|
|
|
|
i.last_read = last_id[-1].current_read
|
|
|
|
@@ -233,7 +319,7 @@ class MeterArchivesLine(models.Model):
|
|
|
|
|
else:
|
|
|
|
|
if i.current_read != 0:
|
|
|
|
|
if i.maximum_count > 0:
|
|
|
|
|
max_value = 10 ** i.maximum_count - 1
|
|
|
|
|
max_value = 10**i.maximum_count - 1
|
|
|
|
|
i.current_meter = max_value - i.last_read + i.current_read
|
|
|
|
|
else:
|
|
|
|
|
i.current_meter = 0
|
|
|
|
@@ -245,7 +331,7 @@ class MeterArchivesLine(models.Model):
|
|
|
|
|
i.last_meter = i.meter_date
|
|
|
|
|
i.current_meter = 0
|
|
|
|
|
|
|
|
|
|
@api.onchange('yuthon_property_ids')
|
|
|
|
|
@api.onchange("yuthon_property_ids")
|
|
|
|
|
def onchange_lessee_id(self):
|
|
|
|
|
for record in self:
|
|
|
|
|
if record.yuthon_property_ids:
|
|
|
|
@@ -255,6 +341,7 @@ class MeterArchivesLine(models.Model):
|
|
|
|
|
|
|
|
|
|
def update_date(self):
|
|
|
|
|
meter_ids = self.env["meter.archives.line"].browse(
|
|
|
|
|
self._context.get('active_ids', self._context.get('active_id')))
|
|
|
|
|
self._context.get("active_ids", self._context.get("active_id"))
|
|
|
|
|
)
|
|
|
|
|
for record in meter_ids:
|
|
|
|
|
record.onchange_lessee_id()
|
|
|
|
|