添加功能
This commit is contained in:
@@ -30,6 +30,12 @@ class PropertyMeterArchives(models.Model):
|
||||
remarks = fields.Text(string='备注')
|
||||
state = fields.Selection([('reading', '已抄'), ('unreading', '未抄')], string='抄表状态', default='unreading')
|
||||
|
||||
@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')
|
||||
def _compute_lessee_id(self):
|
||||
for record in self:
|
||||
@@ -38,18 +44,6 @@ class PropertyMeterArchives(models.Model):
|
||||
else:
|
||||
record.lessee_id = False
|
||||
|
||||
|
||||
def format_update(self):
|
||||
insurances_ids = self.env["property.meter.archives"].browse(
|
||||
self._context.get('active_ids', self._context.get('active_id')))
|
||||
for record in insurances_ids:
|
||||
value = record.unit_number
|
||||
if isinstance(value, str) and value.replace('.', '', 1).isdigit():
|
||||
unit_number = int(float(value))
|
||||
record.write({'unit_number': unit_number})
|
||||
record.write({'maximum_count': 99999,
|
||||
})
|
||||
|
||||
def open_record(self):
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
@@ -80,13 +74,6 @@ class PropertyMeterArchives(models.Model):
|
||||
for record in archives_ids:
|
||||
record.archives_state = 'stop'
|
||||
|
||||
def update_meter(self):
|
||||
meter_ids = self.env["property.meter.archives"].browse(self._context.get('active_ids', self._context.get('active_id')))
|
||||
for record in meter_ids:
|
||||
if record.lessee_id:
|
||||
record.archives_state = 'rent'
|
||||
else:
|
||||
record.archives_state = 'use'
|
||||
|
||||
@api.onchange('current_read', 'last_read')
|
||||
def _onchange_current_meter(self):
|
||||
@@ -197,7 +184,6 @@ class MeterArchivesLine(models.Model):
|
||||
def compute_meter_values(self):
|
||||
"""合并计算当前用量和上次用量"""
|
||||
for line in self:
|
||||
# 计算当前用量 (原 _compute_current_meter 逻辑)
|
||||
if line.current_read > line.last_read:
|
||||
line.current_meter = line.current_read - line.last_read
|
||||
else:
|
||||
|
||||
@@ -69,14 +69,6 @@ class PropertyMeterWater(models.Model):
|
||||
for record in archives_ids:
|
||||
record.water_state = 'stop'
|
||||
|
||||
def update_meter(self):
|
||||
meter_ids = self.env["property.meter.water"].browse(self._context.get('active_ids', self._context.get('active_id')))
|
||||
for record in meter_ids:
|
||||
if record.lessee_id:
|
||||
record.water_state = 'rent'
|
||||
else:
|
||||
record.water_state = 'use'
|
||||
|
||||
@api.onchange('yuthon_property_ids')
|
||||
def _onchange_property(self):
|
||||
if self.yuthon_property_ids:
|
||||
@@ -144,6 +136,12 @@ class MeterWaterLine(models.Model):
|
||||
employee_ids = fields.Many2many('hr.employee', string='抄表人')
|
||||
maximum_count = fields.Integer(string='最大位数')
|
||||
|
||||
@api.onchange('name')
|
||||
def _onchange_line_ids(self):
|
||||
if self.line_ids:
|
||||
for line in self.line_ids:
|
||||
line.name = self.name
|
||||
|
||||
@api.depends('line_loss', 'current_meter', 'unit')
|
||||
def _compute_receivables(self):
|
||||
for record in self:
|
||||
|
||||
@@ -167,18 +167,4 @@
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.action_property_meter_wizard()</field>
|
||||
</record>
|
||||
<record id="all_update_meter_archives" model="ir.actions.server">
|
||||
<field name="name">更新状态</field>
|
||||
<field name="model_id" ref="yuthon_property.model_property_meter_archives"/>
|
||||
<field name="binding_model_id" ref="yuthon_property.model_property_meter_archives"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.update_meter()</field>
|
||||
</record>
|
||||
<record id="all_format_update_meter" model="ir.actions.server">
|
||||
<field name="name">格式更新</field>
|
||||
<field name="model_id" ref="yuthon_property.model_property_meter_archives"/>
|
||||
<field name="binding_model_id" ref="yuthon_property.model_property_meter_archives"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.format_update()</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -168,11 +168,4 @@
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.action_property_water_wizard()</field>
|
||||
</record>
|
||||
<record id="all_update_meter" model="ir.actions.server">
|
||||
<field name="name">更新状态</field>
|
||||
<field name="model_id" ref="yuthon_property.model_property_meter_water"/>
|
||||
<field name="binding_model_id" ref="yuthon_property.model_property_meter_water"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.update_meter()</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -14,30 +14,52 @@ class ElectricWaterWizard(models.TransientModel):
|
||||
self.ensure_one()
|
||||
if not self.push_date:
|
||||
raise ValidationError('请选择推送日期')
|
||||
|
||||
push_year = self.push_date.year
|
||||
push_month = self.push_date.month
|
||||
|
||||
# 计算上个月的年份和月份
|
||||
if push_month == 1:
|
||||
last_month = 12
|
||||
last_year = push_year - 1
|
||||
else:
|
||||
last_month = push_month - 1
|
||||
last_year = push_year
|
||||
|
||||
# 处理电表推送
|
||||
if self.meter_ids:
|
||||
for meter in self.meter_ids:
|
||||
# 查找是否存在该推送日期的明细行
|
||||
# 查找上个月的记录
|
||||
last_month_line = meter.line_ids.filtered(
|
||||
lambda l: l.meter_date and
|
||||
l.meter_date.year == last_year and
|
||||
l.meter_date.month == last_month and
|
||||
l.unit_number == meter.unit_number
|
||||
)
|
||||
|
||||
existing_line = meter.line_ids.filtered(
|
||||
lambda l: l.meter_date and
|
||||
l.meter_date.year == push_year and
|
||||
l.meter_date.month == push_month
|
||||
l.meter_date.month == push_month and
|
||||
l.unit_number == meter.unit_number
|
||||
|
||||
)
|
||||
|
||||
if not existing_line:
|
||||
last_read = last_month_line.current_read if last_month_line else 0
|
||||
last_dosage = last_month_line.current_meter if last_month_line else 0
|
||||
|
||||
meter.line_ids.create({
|
||||
'archives_id': meter.id,
|
||||
'name': meter.name,
|
||||
'epitope_values': meter.epitope_values,
|
||||
'lessee_id': meter.lessee_id.id,
|
||||
'yuthon_property_ids': [(6, 0, meter.yuthon_property_ids.ids)],
|
||||
'last_read': meter.last_read,
|
||||
'current_read': meter.current_read,
|
||||
'last_dosage': meter.last_dosage,
|
||||
'last_read': last_read,
|
||||
'last_dosage': last_dosage,
|
||||
'current_meter': 0,
|
||||
'unit_number': meter.unit_number,
|
||||
'last_meter': last_month_line.meter_date,
|
||||
'gauge_magnification': meter.gauge_magnification,
|
||||
'last_reading_time': self.push_date,
|
||||
'meter_date': self.push_date,
|
||||
@@ -52,30 +74,31 @@ class ElectricWaterWizard(models.TransientModel):
|
||||
# 处理水表推送
|
||||
if self.water_ids:
|
||||
for water in self.water_ids:
|
||||
# 查找是否存在该推送日期的明细行
|
||||
# 查找上个月的记录
|
||||
last_month_line = water.line_ids.filtered(
|
||||
lambda l: l.meter_date and
|
||||
l.meter_date.year == last_year and
|
||||
l.meter_date.month == last_month
|
||||
)
|
||||
|
||||
existing_line = water.line_ids.filtered(
|
||||
lambda l: l.last_meter == self.push_date
|
||||
lambda l: l.meter_date and
|
||||
l.meter_date.year == push_year and
|
||||
l.meter_date.month == push_month
|
||||
)
|
||||
|
||||
if not existing_line:
|
||||
last_read = last_month_line.current_read if last_month_line else 0
|
||||
last_dosage = last_month_line.current_meter if last_month_line else 0
|
||||
|
||||
water.line_ids.create({
|
||||
'water_id': water.id,
|
||||
'name': water.name,
|
||||
'epitope_values': water.epitope_values,
|
||||
'lessee_id': water.lessee_id.id,
|
||||
'yuthon_property_ids': [(6, 0, water.yuthon_property_ids.ids)],
|
||||
'last_read': water.last_read,
|
||||
'current_read': water.current_read,
|
||||
'last_dosage': water.last_dosage,
|
||||
'last_read': last_read,
|
||||
'last_dosage': last_dosage,
|
||||
'current_meter': 0,
|
||||
'unit_number': water.unit_number,
|
||||
'gauge_magnification': water.gauge_magnification,
|
||||
'meter_date': self.push_date,
|
||||
'type': water.type,
|
||||
'start_time': water.start_time,
|
||||
'end_time': water.end_time,
|
||||
'water_state': water.water_state,
|
||||
'maximum_count': water.maximum_count,
|
||||
'employee_ids': [(6, 0, water.employee_ids.ids)],
|
||||
'last_meter': last_month_line.meter_date,
|
||||
'is_push': True
|
||||
})
|
||||
|
||||
|
||||
@@ -399,6 +399,8 @@ class PropertyLeaseContract(models.Model):
|
||||
'actual_start_time': contract.term_start_time,
|
||||
'actual_end_time': contract.term_end_time,
|
||||
'work_end': True})
|
||||
self._update_contract_lines(contract)
|
||||
|
||||
logs_to_update = self.env["soong.workflow.log"].search([
|
||||
("model", "=", self._name),
|
||||
("res_id", "=", contract.id),
|
||||
@@ -428,6 +430,9 @@ class PropertyLeaseContract(models.Model):
|
||||
'actual_start_time': self.term_start_time,
|
||||
'actual_end_time': self.term_end_time,
|
||||
})
|
||||
for contract in self:
|
||||
contract._update_contract_lines(contract)
|
||||
|
||||
|
||||
def open_record(self):
|
||||
return {
|
||||
@@ -456,23 +461,47 @@ class PropertyLeaseContract(models.Model):
|
||||
record.name = self._description
|
||||
|
||||
def update_property(self):
|
||||
existing_lines = self.env['property.contract.line'].search([])
|
||||
existing_lines.unlink()
|
||||
empty_contract_lines = self.env['property.contract.line'].search([('lease_contract_id', '=', False)])
|
||||
if empty_contract_lines:
|
||||
empty_contract_lines.unlink()
|
||||
contract_ids = self.env["property.lease.contract"].browse(
|
||||
self._context.get('active_ids', self._context.get('active_id')))
|
||||
for contract_id in contract_ids:
|
||||
for record in contract_id.lease_ids:
|
||||
record.address_id.write({'property_contract_ids': [(5, 0, 0)]})
|
||||
contract_list = []
|
||||
contract_list.append([0, 0,{
|
||||
'yuthon_property_id': record.address_id.id,
|
||||
'lease_contract_id': contract_id.id,
|
||||
'lessee_id': contract_id.lessee_id.id,
|
||||
'rent': contract_id.rent,
|
||||
'start_time': contract_id.actual_start_time,
|
||||
'end_date': contract_id.actual_end_time,
|
||||
}])
|
||||
record.address_id.write({'property_contract_ids': contract_list})
|
||||
|
||||
for contract in contract_ids:
|
||||
self._update_contract_lines(contract)
|
||||
|
||||
def _update_contract_lines(self, contract):
|
||||
"""
|
||||
处理单个合同的明细行更新
|
||||
:param contract: 物业租赁合同记录
|
||||
"""
|
||||
for record in contract.lease_ids:
|
||||
property_addr = record.address_id
|
||||
if not property_addr:
|
||||
continue
|
||||
existing_line = self.env['property.contract.line'].search([
|
||||
('yuthon_property_id', '=', property_addr.id),
|
||||
('lease_contract_id', '=', contract.id)
|
||||
], limit=1)
|
||||
|
||||
# 准备要写入的数据
|
||||
contract_data = {
|
||||
'yuthon_property_id': property_addr.id,
|
||||
'lease_contract_id': contract.id,
|
||||
'lessee_id': contract.lessee_id.id,
|
||||
'rent': contract.rent,
|
||||
'start_time': contract.actual_start_time,
|
||||
'end_date': contract.actual_end_time,
|
||||
}
|
||||
|
||||
if existing_line:
|
||||
# 如果存在则更新
|
||||
existing_line.write(contract_data)
|
||||
else:
|
||||
# 如果不存在则追加
|
||||
property_addr.write({
|
||||
'property_contract_ids': [(0, 0, contract_data)]
|
||||
})
|
||||
|
||||
@api.onchange('lessee_id')
|
||||
def _onchange_lessee_id(self):
|
||||
|
||||
@@ -87,7 +87,7 @@ class PropertyReconciliationWizard(models.Model):
|
||||
last_day_of_last_month = start_time.replace(day=1) - relativedelta(days=1)
|
||||
contract_receivables = self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '=', contract_id.id),
|
||||
('contract_id.lessor_id.name', '=', self.bank_id.your_own_unit),
|
||||
('is_reconciliation', '=', False),
|
||||
('due_date', '>=', first_day_of_last_month.strftime('%Y-%m-%d')),
|
||||
('due_date', '<=', last_day_of_last_month.strftime('%Y-%m-%d')),
|
||||
('management_type_id.name', '=', '租金')
|
||||
|
||||
@@ -44,7 +44,6 @@ class YuthonProperty(models.Model):
|
||||
if p.property_contract_ids and p.property_contract_ids.lease_contract_id.lessor_id else "",
|
||||
"承租方": p.lessee_id.name or "" if p.lessee_id else "",
|
||||
"出租地址": p.rental_address or "",
|
||||
"统一社会信用代码": p.credit_code or "",
|
||||
"联系人": p.contact or "",
|
||||
"出租用途": p.property_contract_ids.lease_contract_id.rental_purposes.name or ""
|
||||
if p.property_contract_ids and p.property_contract_ids.lease_contract_id.rental_purposes else "",
|
||||
@@ -56,7 +55,6 @@ class YuthonProperty(models.Model):
|
||||
"合同签订日期": p.contract_date.strftime("%Y-%m-%d") if p.contract_date else "",
|
||||
"合约开始时间": p.term_start_time.strftime("%Y-%m-%d") if p.term_start_time else "",
|
||||
"合约结束时间": p.term_end_time.strftime("%Y-%m-%d") if p.term_end_time else "",
|
||||
"合同期内租金变化": p.rent_changes or "",
|
||||
"单价": p.unit_price or 0.0,
|
||||
"月租金": p.monthly_amount or 0.0,
|
||||
"合同总金额": p.total_amount or 0.0,
|
||||
|
||||
Reference in New Issue
Block a user