Hi,
Tracking is used to record each and every action or update of a particular field.
For example:
from odoo import models, fields
class SaleOrder(models.Model):
_inherit = 'sale.order'
expected_date = fields.Datetime(
string="Expected Date",
compute='_compute_expected_date',
store=False,
tracking=True,
help="Delivery date you can promise to the customer, computed from the minimum lead time of the order lines."
)
A log will be recorded with from and to values when the value of expected_date is changed.
If you want a custom log note (like posting a message in the chatter when the date changes), you can either:
-
Override the existing compute function (if appropriate), or
-
Create a custom write method to detect and log the change.
Example Code:
class SaleOrder(models.Model):
_inherit ='sale.order'
def _compute_expected_date(self):
res = super()._compute_expected_date()
self.message_post(body=_("The delivery date has changed the new date is - %s", res)
return res
This
will ensure that whenever the delivery/commitment date (expected_date)
is changed, the new date will be posted in the chatter.
Hope it helps