odoo-18-docker-compose/addons/epr/wizards/epr_reject_rfq_wizard.py
mtpc4s9 d993893bc3 Viết xong Wizard Reject RFQs
Điều chỉnh Wizard tạo PO
2026-01-03 14:07:59 +07:00

86 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.exceptions import UserError
class EprRejectRfqWizard(models.TransientModel):
"""
Wizard specifically for rejecting EPR RFQs.
It updates both the Approval Entry (history) and the RFQ record (status & reason).
"""
_name = 'epr.reject.rfq.wizard'
_description = 'EPR RFQ Reject Wizard'
# ==========================================================================
# FIELDS
# ==========================================================================
reason = fields.Text(
string="Rejection Reason",
required=True,
help="Please explain why you are rejecting this RFQ."
)
# ==========================================================================
# METHODS
# ==========================================================================
def action_confirm_reject(self):
"""
Process the rejection:
1. Find and update the user's pending approval entry.
2. Call the callback on the RFQ to update its state and store the reason.
"""
self.ensure_one()
# 1. Get Context Data
active_id = self.env.context.get('active_id')
active_model = self.env.context.get('active_model')
if not active_id or active_model != 'epr.rfq':
raise UserError(_("This wizard can only be used for EPR RFQs."))
rfq = self.env['epr.rfq'].browse(active_id)
# 2. Update Approval Entry (The Log)
# Search for a pending approval entry for this user and this RFQ
approval_entry = self.env['epr.approval.entry'].search([
('rfq_id', '=', rfq.id),
('required_user_ids', 'in', self.env.uid),
('status', '=', 'new')
], limit=1)
if approval_entry:
approval_entry.write({
'status': 'refused',
'rejection_reason': self.reason,
'actual_user_id': self.env.uid,
'approval_date': fields.Datetime.now()
})
# Note: Depending on your strictness, you might allow Admins to reject without an entry.
# Here we strictly enforce that an entry must exist.
if approval_entry:
approval_entry.write({
'status': 'refused',
'rejection_reason': self.reason,
'actual_user_id': self.env.uid,
'approval_date': fields.Datetime.now()
})
# 3. Update the RFQ Record (The Main Document)
# We pass the reason back to the RFQ model to store it permanently
rfq.action_handle_rejection(self.reason)
# 4. Feedback to User
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('RFQ Rejected'),
'message': _('The RFQ has been rejected and the reason has been recorded.'),
'type': 'warning',
'sticky': False,
'next': {'type': 'ir.actions.act_window_close'},
}
}