51 lines
2.3 KiB
Python
51 lines
2.3 KiB
Python
from odoo import models, fields, api, _, SUPERUSER_ID
|
|
from odoo.exceptions import UserError, ValidationError
|
|
from datetime import datetime, timedelta, date
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
class ActionRefuseWizard(models.TransientModel):
|
|
_name = 'action.refuse.wizard'
|
|
_description = '批量退回提醒弹窗'
|
|
|
|
receivable_ids = fields.Many2many('property.accounts.receivable', string='关联应收账单')
|
|
|
|
def confirm(self):
|
|
model_type_data = {
|
|
'水费': 'meter.water.line',
|
|
'电费': 'meter.archives.line',
|
|
'押金': 'property.deposit.list',
|
|
'租金': 'property.rent.list',
|
|
'管理费': 'property.management.list',
|
|
}
|
|
for rec in self.receivable_ids:
|
|
if rec.is_reconciliation == True:
|
|
continue
|
|
model_type = model_type_data.get(rec.management_type_id.name)
|
|
valid_management_types = list(model_type_data.values())
|
|
if model_type not in valid_management_types:
|
|
rec.unlink()
|
|
continue
|
|
if model_type in ('meter.archives.line', 'meter.water.line'):
|
|
if not rec.charging_range:
|
|
raise UserError("请输入计费区间, 按照应为'YYYY-MM-DD 到 YYYY-MM-DD格式")
|
|
charging_range = rec.charging_range.strip()
|
|
start_str, end_str = [x.strip() for x in charging_range.split("到")]
|
|
start_date = (datetime.strptime(end_str, "%Y-%m-%d").date()).replace(day=1)
|
|
end_date = datetime.strptime(end_str, "%Y-%m-%d").date()
|
|
model_id = self.env[model_type].search([
|
|
('contract_id', '=', rec.contract_id.id),
|
|
('meter_date', '>=', start_date),
|
|
('meter_date', '<=', end_date)
|
|
])
|
|
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() |