88 lines
3.6 KiB
Python
88 lines
3.6 KiB
Python
from odoo import models, fields, api, _, SUPERUSER_ID
|
|
from datetime import datetime, timedelta
|
|
from dateutil.relativedelta import relativedelta
|
|
from datetime import datetime, timedelta, date
|
|
|
|
|
|
class AccountsWizard(models.Model):
|
|
_name = 'accounts.wizard'
|
|
|
|
accounts_id = fields.Many2one('property.accounts.receivable', string='对账单')
|
|
|
|
def invalid(self):
|
|
receivable_log = (f'当前登录人{self.env.user.name}于{fields.Datetime.now()}将物业为 {self.accounts_id.property_name}的应收账单状态修改为作废')
|
|
for record in self.accounts_id:
|
|
original_log = record.receivable_log or ''
|
|
if original_log:
|
|
new_log = f"{original_log}\n{receivable_log}"
|
|
else:
|
|
new_log = receivable_log
|
|
return self.accounts_id.write({'is_invalid': True,
|
|
'receivable_log': new_log
|
|
})
|
|
|
|
# 激活
|
|
def suspend(self):
|
|
receivable_log = (
|
|
f'当前登录人{self.env.user.name}于{fields.Datetime.now()}将物业为 {self.accounts_id.property_name}的应收账单挂起')
|
|
for record in self.accounts_id:
|
|
original_log = record.receivable_log or ''
|
|
if original_log:
|
|
new_log = f"{original_log}\n{receivable_log}"
|
|
else:
|
|
new_log = receivable_log
|
|
return self.accounts_id.write({'is_suspend': False,'receivable_log': new_log})
|
|
|
|
# 挂起
|
|
def unsuspend(self):
|
|
receivable_log = (
|
|
f'当前登录人{self.env.user.name}于{fields.Datetime.now()}将物业为 {self.accounts_id.property_name}的应收账单取消挂起')
|
|
for record in self.accounts_id:
|
|
original_log = record.receivable_log or ''
|
|
if original_log:
|
|
new_log = f"{original_log}\n{receivable_log}"
|
|
else:
|
|
new_log = receivable_log
|
|
return self.accounts_id.write({'is_suspend': True,
|
|
'receivable_log':new_log
|
|
})
|
|
|
|
# 退回
|
|
def action_refuse(self):
|
|
model_type_data = {
|
|
'水费': 'property.water.list',
|
|
'电费': 'property.tariff.list',
|
|
'押金': 'property.deposit.list',
|
|
'租金': 'property.rent.list'
|
|
}
|
|
for rec in self.accounts_id:
|
|
model_type = model_type_data.get(rec.management_type_id.name)
|
|
if rec.management_type_id.name == '违约金':
|
|
rec.unlink()
|
|
continue
|
|
if model_type in ('meter.archives.line', 'meter.water.line'):
|
|
year = rec.due_date_end.year
|
|
month = rec.due_date_end.month
|
|
first_day = date(year, month, 1)
|
|
if month == 12:
|
|
next_month_first_day = date(year + 1, 1, 1)
|
|
else:
|
|
next_month_first_day = date(year, month + 1, 1)
|
|
last_day = next_month_first_day - timedelta(days=1)
|
|
model_id = self.env[model_type].search([
|
|
('contract_id', '=', rec.contract_id.id),
|
|
('meter_date', '>=', first_day),
|
|
('meter_date', '<=', last_day)
|
|
])
|
|
else:
|
|
last_day = rec.due_date + relativedelta(months=1) - timedelta(days=1)
|
|
model_id = self.env[model_type].search([
|
|
('contract_id', '=', rec.contract_id.id),
|
|
('due_date', '>=', rec.due_date),
|
|
('due_date', '<=', last_day)
|
|
])
|
|
|
|
if model_id:
|
|
model_id.write({'is_push': False})
|
|
rec.unlink()
|