Files
project_v19/xf_doc_approval_custom/models/document_approver.py
T
2026-07-01 14:41:49 +07:00

94 lines
3.5 KiB
Python

from odoo import api, fields, models
_KH_DIGITS = str.maketrans('0123456789', '០១២៣៤៥៦៧៨៩')
_KH_MONTHS = [
'មករា', 'កុម្ភៈ', 'មីនា', 'មេសា', 'ឧសភា', 'មិថុនា',
'កក្កដា', 'សីហា', 'កញ្ញា', 'តុលា', 'វិច្ឆិកា', 'ធ្នូ',
]
class DocApprovalDocumentApproverCustom(models.Model):
_inherit = 'xf.doc.approval.document.approver'
role = fields.Selection(
string='តួនាទី',
selection=[
('reviewer', 'អ្នកពិនិត្យ និងផ្តល់យោបល់'),
('approver', 'អ្នកអនុម័ត'),
],
default='approver',
)
state = fields.Selection(
selection=[
('to approve', 'មិនទាន់ពិនិត្យ'),
('pending', 'រង់ចាំ'),
('approved', 'បានអនុម័ត'),
('rejected', 'បានបដិសេធ'),
],
)
sent_date = fields.Datetime(
string='Review Date',
readonly=True,
)
sent_date_kh = fields.Char(
string='កាលបរិច្ឆេទ',
compute='_compute_sent_date_kh',
)
@api.depends('sent_date')
def _compute_sent_date_kh(self):
for rec in self:
if rec.sent_date:
dt = fields.Datetime.context_timestamp(rec, rec.sent_date)
day = str(dt.day).translate(_KH_DIGITS)
month = _KH_MONTHS[dt.month - 1]
year = str(dt.year).translate(_KH_DIGITS)
hour = str(dt.hour).translate(_KH_DIGITS)
minute = str(dt.minute).zfill(2).translate(_KH_DIGITS)
rec.sent_date_kh = f'{day} {month} {year} {hour}:{minute}'
else:
rec.sent_date_kh = False
round = fields.Integer(
string='Round',
default=1,
readonly=True,
)
notes_display = fields.Text(
string='Notes (Visible)',
compute='_compute_notes_display',
)
@api.depends('notes', 'step', 'document_package_id.approver_ids.step',
'document_package_id.approver_ids.user_id')
def _compute_notes_display(self):
current_uid = self.env.uid
is_admin = self.env.user._is_admin()
for record in self:
if is_admin:
record.notes_display = record.notes
continue
package = record.document_package_id
# Find the current user's highest step in this document
my_approvers = package.approver_ids.filtered(
lambda a: a.user_id.id == current_uid
)
if not my_approvers:
# Initiator or non-approver: see all notes
record.notes_display = record.notes
else:
my_max_step = max(my_approvers.mapped('step'))
# Show this row's note only if its step <= my step
if record.step <= my_max_step:
record.notes_display = record.notes
else:
record.notes_display = False
def action_approve(self):
self.filtered(lambda a: not a.sent_date).write({'sent_date': fields.Datetime.now()})
return super().action_approve()
def action_reject(self):
self.filtered(lambda a: not a.sent_date).write({'sent_date': fields.Datetime.now()})
return super().action_reject()