accountant_cn
This commit is contained in:
1
accountant_cn/tests/__init__.py
Normal file
1
accountant_cn/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_dn_audit_return
|
||||
145
accountant_cn/tests/test_dn_audit_return.py
Normal file
145
accountant_cn/tests/test_dn_audit_return.py
Normal file
@@ -0,0 +1,145 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import fields
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import TransactionCase, tagged
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestAuditWorkingFiles(TransactionCase):
|
||||
"""The workflow rules that the Review > Audit > Working Files screen relies on.
|
||||
|
||||
These are the invariants that a refactor would silently break: the
|
||||
completion guard, the meaning of "n/a" in the counters, template loading
|
||||
being idempotent, and cycles actually filtering what gets stamped on.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.Return = cls.env["dn.audit.return"]
|
||||
cls.Check = cls.env["dn.audit.check"]
|
||||
cls.CheckTemplate = cls.env["dn.audit.check.template"]
|
||||
cls.bank = cls.env.ref("accountant_cn.cycle_bank")
|
||||
cls.payroll = cls.env.ref("accountant_cn.cycle_payroll")
|
||||
today = fields.Date.context_today(cls.env.user)
|
||||
cls.today = today
|
||||
|
||||
def _make_file(self, **kwargs):
|
||||
values = {
|
||||
"name": "2026-10 Close",
|
||||
"date_from": self.today.replace(day=1),
|
||||
"date_to": self.today,
|
||||
"date_deadline": fields.Date.add(self.today, days=5),
|
||||
}
|
||||
values.update(kwargs)
|
||||
return self.Return.create(values)
|
||||
|
||||
def test_template_load_is_idempotent(self):
|
||||
"""Pressing "Load templates" twice must not duplicate the checks.
|
||||
|
||||
The button is the only way checks get onto a file, so a duplicate on
|
||||
the second press would double the review workload of every period.
|
||||
"""
|
||||
wf = self._make_file(cycle_ids=[(6, 0, self.bank.ids)])
|
||||
wf.action_load_templates()
|
||||
first = len(wf.check_ids)
|
||||
self.assertTrue(first, "Bank templates should have created checks")
|
||||
|
||||
wf.action_load_templates()
|
||||
self.assertEqual(
|
||||
len(wf.check_ids), first,
|
||||
"Loading templates twice must not add the checks again")
|
||||
|
||||
def test_cycles_filter_templates(self):
|
||||
"""A file filed only under Payroll must not inherit the Bank checks."""
|
||||
wf = self._make_file(cycle_ids=[(6, 0, self.payroll.ids)])
|
||||
wf.action_load_templates()
|
||||
bank_templates = self.CheckTemplate.search([("cycle_id", "=", self.bank.id)])
|
||||
self.assertTrue(bank_templates, "The test needs at least one bank template")
|
||||
self.assertFalse(
|
||||
wf.check_ids.filtered(lambda c: c.template_id in bank_templates),
|
||||
"Bank checks leaked into a payroll-only file")
|
||||
|
||||
def test_completion_guard_blocks_unresolved_checks(self):
|
||||
"""A file with a to-do check cannot be signed off."""
|
||||
wf = self._make_file(cycle_ids=[(6, 0, self.bank.ids)])
|
||||
wf.action_load_templates()
|
||||
with self.assertRaises(UserError):
|
||||
wf.action_mark_done()
|
||||
self.assertEqual(wf.review_state, "ongoing")
|
||||
self.assertFalse(wf.is_completed)
|
||||
|
||||
def test_not_applicable_counts_as_resolved(self):
|
||||
"""``na`` must clear the issue counter, or a file stays red forever.
|
||||
|
||||
A check that does not apply to the period has been dealt with; treating
|
||||
it as outstanding would make it impossible to ever complete the file
|
||||
without lying about the result.
|
||||
"""
|
||||
wf = self._make_file()
|
||||
check = self.Check.create({
|
||||
"return_id": wf.id,
|
||||
"name": "Not applicable this period",
|
||||
"check_type": "check",
|
||||
})
|
||||
self.assertEqual(wf.unresolved_check_count, 1)
|
||||
self.assertEqual(wf.progress, 0.0)
|
||||
|
||||
check.action_mark_na()
|
||||
self.assertEqual(wf.unresolved_check_count, 0)
|
||||
self.assertEqual(wf.progress, 100.0)
|
||||
self.assertEqual(wf.resolved_check_count, 1)
|
||||
|
||||
def test_completion_after_resolving_everything(self):
|
||||
wf = self._make_file(cycle_ids=[(6, 0, self.bank.ids)])
|
||||
wf.action_load_templates()
|
||||
for check in wf.check_ids:
|
||||
check.action_mark_done()
|
||||
self.assertEqual(wf.unresolved_check_count, 0)
|
||||
|
||||
wf.action_mark_done()
|
||||
self.assertEqual(wf.review_state, "done")
|
||||
self.assertTrue(wf.is_completed)
|
||||
|
||||
def test_pause_and_resume_keep_the_checks(self):
|
||||
"""Pausing is a statement about intent, not about the work done."""
|
||||
wf = self._make_file(cycle_ids=[(6, 0, self.bank.ids)])
|
||||
wf.action_load_templates()
|
||||
before = len(wf.check_ids)
|
||||
|
||||
wf.action_pause()
|
||||
self.assertEqual(wf.review_state, "paused")
|
||||
wf.action_resume()
|
||||
self.assertEqual(wf.review_state, "ongoing")
|
||||
self.assertEqual(len(wf.check_ids), before)
|
||||
|
||||
def test_end_date_cannot_precede_start_date(self):
|
||||
wf = self._make_file()
|
||||
with self.assertRaises(UserError):
|
||||
wf.write({"date_to": fields.Date.subtract(wf.date_from, days=1)})
|
||||
|
||||
def test_late_flag_ignores_completed_files(self):
|
||||
"""A finished period is never "late", however old its deadline is."""
|
||||
wf = self._make_file(
|
||||
date_deadline=fields.Date.subtract(self.today, days=10))
|
||||
self.assertTrue(wf.is_late)
|
||||
self.assertEqual(wf.days_to_deadline, -10)
|
||||
|
||||
wf.action_mark_done()
|
||||
self.assertFalse(
|
||||
wf.is_late,
|
||||
"A completed file must not keep showing as late on the kanban")
|
||||
|
||||
def test_date_from_suggests_a_period_name(self):
|
||||
"""An empty name is filled from the start date; a typed one is kept."""
|
||||
wf = self.Return.new({"date_from": self.today.replace(day=1)})
|
||||
wf._onchange_date_from()
|
||||
self.assertTrue(wf.name, "The period name should be suggested")
|
||||
self.assertIn(str(self.today.year), wf.name)
|
||||
|
||||
named = self.Return.new({
|
||||
"name": "Custom name",
|
||||
"date_from": self.today.replace(day=1),
|
||||
})
|
||||
named._onchange_date_from()
|
||||
self.assertEqual(named.name, "Custom name")
|
||||
Reference in New Issue
Block a user