68 lines
3.0 KiB
Python
68 lines
3.0 KiB
Python
from email.policy import default
|
|
from dateutil.relativedelta import relativedelta
|
|
from odoo import models, fields, api, _, SUPERUSER_ID
|
|
from odoo.exceptions import ValidationError, UserError
|
|
import calendar
|
|
import xlrd
|
|
import base64
|
|
import datetime
|
|
from datetime import datetime, timedelta, date
|
|
import pandas as pd
|
|
|
|
|
|
class PrintPaymentWizard(models.Model):
|
|
_name = 'print.payment.wizard'
|
|
_description = '打印物业缴费通知单'
|
|
|
|
contract_ids = fields.Many2many('property.lease.contract', string="合同")
|
|
select_month = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
|
|
('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
|
|
('9', '九月'), ('10', '十月'), ('11', '十一月'),
|
|
('12', '十二月')], string='选择月份',
|
|
default=lambda self: str(datetime.now().month))
|
|
select_year = fields.Selection(selection=[(str(i), str(i)) for i in range(2024, 2060)], string='选择年份',
|
|
default=lambda self: str(datetime.now().year))
|
|
|
|
@api.model
|
|
def _get_date_range(self):
|
|
year = int(self.select_year)
|
|
month = int(self.select_month)
|
|
start_date = date(year, month, 1)
|
|
end_date = date(year, month, 1) + relativedelta(months=1) - relativedelta(days=1)
|
|
return start_date, end_date
|
|
|
|
def confirm(self):
|
|
"""确认按钮:筛选数据并触发打印"""
|
|
self.ensure_one()
|
|
today = date.today()
|
|
start_date = today.replace(day=1)
|
|
end_date = start_date + relativedelta(months=1) - relativedelta(days=1)
|
|
for contract_id in self.contract_ids:
|
|
receivable_report_ids = []
|
|
existing_notice = self.env['property.payment.notice'].search([
|
|
('contract_id', '=', contract_id.id),
|
|
('print_date', '>=', start_date),
|
|
('print_date', '<=', end_date)
|
|
], limit=1)
|
|
if not existing_notice:
|
|
self.env['property.payment.notice'].create({
|
|
'contract_id': contract_id.id,
|
|
'print_date': today,
|
|
'is_print': True,
|
|
})
|
|
start_date, end_date = self._get_date_range()
|
|
receivable_lines = contract_id.receivable_ids.filtered(
|
|
lambda line: start_date <= line.due_date <= end_date
|
|
)
|
|
if receivable_lines:
|
|
receivable_report_ids.extend(receivable_lines.ids)
|
|
if receivable_report_ids:
|
|
contract_id.receivable_report_ids = [(6, 0, receivable_report_ids)]
|
|
contract_id.total_amount = sum(line.original_amount for line in receivable_lines )
|
|
|
|
contract_id.print_date = today
|
|
|
|
report_ref = self.env['ir.actions.report'].search([
|
|
('report_name', '=', 'yuthon_property_approval.report_contract_accounts_receivable')])
|
|
|
|
return report_ref.report_action(self.contract_ids) |