blob: b180fad64933fc54d7a049323dba23632b2961f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
import logging
_logger = logging.getLogger(__name__)
class SalesOrderReject(models.Model):
_name = 'sales.order.reject'
sale_order_id = fields.Many2one('sale.order', string='Sale Order')
product_id = fields.Many2one('product.product', string='Product')
qty_reject = fields.Float(string='Qty')
reason_reject = fields.Char(string='Reason Reject')
def write(self, vals):
# Check if reason_reject is being updated
if 'reason_reject' in vals:
for record in self:
old_reason = record.reason_reject
new_reason = vals['reason_reject']
# Only post a message if the reason actually changed
if old_reason != new_reason:
now = fields.Datetime.now()
# Create the log note for the updated reason
log_note = (f"<li>Product '{record.product_id.name}' rejection reason updated:</li>"
f"<li>From: {old_reason}</li>"
f"<li>To: {new_reason}</li>"
f"<li>Updated on: {now.strftime('%d-%m-%Y')} at {now.strftime('%H:%M:%S')}</li>")
# Post ke lognote
if record.sale_order_id:
record.sale_order_id.message_post(
body=log_note,
author_id=self.env.user.partner_id.id,
)
# Call the original write method
return super(SalesOrderReject, self).write(vals)
|