accountant_cn
This commit is contained in:
131
accountant_cn/models/dn_audit_check.py
Normal file
131
accountant_cn/models/dn_audit_check.py
Normal file
@@ -0,0 +1,131 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Checks: the individual items an accountant works through.
|
||||
|
||||
A check is deliberately small. It records *what* has to be looked at, *how* it
|
||||
is recorded (cleared, not applicable, or with a comment), and who touched it.
|
||||
It does not try to evaluate anything by itself - an automated check that
|
||||
silently decides the books are fine is worse than no check at all, because it
|
||||
hides the judgement the reviewer was supposed to make.
|
||||
"""
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class DnAuditCheck(models.Model):
|
||||
_name = "dn.audit.check"
|
||||
_description = "Audit Check"
|
||||
# mail.thread so `tracking` on `result` is meaningful: the trail of who
|
||||
# cleared which check, and when, is the audit evidence this model exists to
|
||||
# produce. Without it `tracking=True` is silently ignored.
|
||||
_inherit = ["mail.thread"]
|
||||
_order = "return_id, sequence, id"
|
||||
|
||||
return_id = fields.Many2one(
|
||||
comodel_name="dn.audit.return",
|
||||
string="Working File",
|
||||
required=True,
|
||||
ondelete="cascade",
|
||||
index=True,
|
||||
)
|
||||
company_id = fields.Many2one(related="return_id.company_id", store=True, index=True)
|
||||
currency_id = fields.Many2one(related="return_id.currency_id", readonly=True)
|
||||
|
||||
name = fields.Char(string="Name", required=True, translate=True)
|
||||
sequence = fields.Integer(default=10)
|
||||
check_type = fields.Selection(
|
||||
selection=[
|
||||
("check", "Check"),
|
||||
("file", "Upload Document"),
|
||||
],
|
||||
string="Type",
|
||||
default="check",
|
||||
required=True,
|
||||
)
|
||||
description = fields.Html(string="Description", translate=True)
|
||||
template_id = fields.Many2one(
|
||||
comodel_name="dn.audit.check.template",
|
||||
string="Template",
|
||||
ondelete="set null",
|
||||
)
|
||||
cycle_id = fields.Many2one(
|
||||
comodel_name="dn.audit.cycle",
|
||||
string="Cycle",
|
||||
ondelete="set null",
|
||||
)
|
||||
|
||||
result = fields.Selection(
|
||||
selection=[
|
||||
("todo", "To Do"),
|
||||
("done", "Done"),
|
||||
("na", "Not Applicable"),
|
||||
("comment", "Commented"),
|
||||
],
|
||||
string="Result",
|
||||
default="todo",
|
||||
required=True,
|
||||
tracking=True,
|
||||
)
|
||||
comment = fields.Text(string="Comment")
|
||||
|
||||
user_id = fields.Many2one(
|
||||
comodel_name="res.users",
|
||||
string="Reviewed By",
|
||||
default=lambda self: self.env.user,
|
||||
)
|
||||
date_review = fields.Datetime(string="Reviewed On")
|
||||
|
||||
attachment_ids = fields.Many2many(
|
||||
comodel_name="ir.attachment",
|
||||
relation="dn_audit_check_attachment_rel",
|
||||
column1="check_id",
|
||||
column2="attachment_id",
|
||||
string="Documents",
|
||||
)
|
||||
attachment_count = fields.Integer(
|
||||
string="Documents Uploaded", compute="_compute_attachment_count")
|
||||
|
||||
# Surfaced on the check so the reviewer does not have to open the file to
|
||||
# know which period the check belongs to.
|
||||
date_from = fields.Date(related="return_id.date_from")
|
||||
date_to = fields.Date(related="return_id.date_to")
|
||||
|
||||
@api.depends("attachment_ids")
|
||||
def _compute_attachment_count(self):
|
||||
for record in self:
|
||||
record.attachment_count = len(record.attachment_ids)
|
||||
|
||||
@api.onchange("result")
|
||||
def _onchange_result(self):
|
||||
"""Stamp the reviewer and the moment the result changes.
|
||||
|
||||
Done in an onchange rather than in ``write`` so a bulk write from the
|
||||
kanban drag does not overwrite the timestamp with "whenever this was
|
||||
last saved"; the value only trails an explicit result change.
|
||||
"""
|
||||
if self.result != "todo":
|
||||
self.user_id = self.env.user
|
||||
self.date_review = fields.Datetime.now()
|
||||
|
||||
def action_set_result(self, result):
|
||||
self.write({
|
||||
"result": result,
|
||||
"user_id": self.env.user.id,
|
||||
"date_review": fields.Datetime.now(),
|
||||
})
|
||||
|
||||
def action_mark_done(self):
|
||||
self.action_set_result("done")
|
||||
|
||||
def action_mark_na(self):
|
||||
self.action_set_result("na")
|
||||
|
||||
def action_open(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
"name": self.name,
|
||||
"res_model": "dn.audit.check",
|
||||
"res_id": self.id,
|
||||
"view_mode": "form",
|
||||
"target": "current",
|
||||
}
|
||||
Reference in New Issue
Block a user