You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.8 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from odoo import api, models, fields
from odoo.exceptions import ValidationError
class ReportInquiryWizard(models.TransientModel):
"""报表查询向导"""
_name = 'report.inquiry.wizard'
_description = '报表查询向导'
def _default_fiscalyear_id(self):
fiscalyears = self.env['fr.account.fiscalyear'].search([
('state', '=', 'activated'), ('company_id', '=', self.company_id.id)])
if len(fiscalyears) > 1:
return fiscalyears[-1]
else:
return fiscalyears
# 基础字段
report_type = fields.Selection([
('assets_liability', '资产负债表'),
('profit', '利润表'),
('cash_flow', '现金流量表'),
('owner', '所有者权益变动表'),
], string='报表类型', required=True)
# 关系字段
fiscalyear_id = fields.Many2one('fr.account.fiscalyear', string='会计年度', default=_default_fiscalyear_id, required=True)
period_id = fields.Many2one('fr.account.period', string='会计期间', required=True)
report_id = fields.Many2one('account.ledger.report', string='报表模板', required=True, ondelete='cascade')
# 关联字段
period_state = fields.Selection(related='period_id.state', string='期间状态')
company_id = fields.Many2one('res.company', string='公司', default=lambda self: self.env.company.id)
def confirm(self):
"""单实例方法:结转期间对应的损益科目总账
:return: 更新后的当前视图
"""
self.ensure_one()
return {
'type': 'ir.actions.client',
'tag': 'ledger_report',
'target': 'current',
# 'name': self.report_id.name + '' + self.period_id.name,
'context': {'report_id': self.report_id.id, 'period_id': self.period_id.id}
}
@api.onchange('report_type')
def _change_report_id(self):
"""自动获取报表"""
if self.report_type:
default_report_id = self.env.context.get('default_report_id', [])
report = self.env['account.ledger.report'].browse(default_report_id)
if report.report_type == self.report_type:
self.report_id = report
else:
self.report_id = self.env['account.ledger.report'].search(
[('report_type', '=', self.report_type)], order='id desc', limit=1)
@api.onchange('fiscalyear_id')
def _change_period_id(self):
"""自动获取首个未结账期间"""
if self.fiscalyear_id:
periods = self.fiscalyear_id.period_ids.filtered(lambda period: period.state != 'unuse')
if periods:
self.period_id = periods[0]