İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
1516 Görünümler

Hi I would like to automate the task of when a sales orders Delivery date/commitment date is changed that this  new date is quoted in the chatter.

The delivery date has changed the new date is - (15/04/2024)

I have manged to get it to work in the automate tab however I would like the actual date quoted and I do not know what the required script for this is.

Many thanks in advanced.

Avatar
Vazgeç
En İyi Yanıt

I believe you are looking for parameter tracking="True" on Field definition 

birth_date = fields.Date(string='Birth date', tracking=True)

 But to able to use this you also need to inherit your modul from mail.thread

class NameOfTheClass(models.Model)
_inherit = ['mail.thread', 'another.model']


Avatar
Vazgeç
En İyi Yanıt

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:

  1. Override the existing compute function (if appropriate), or
  2. 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

Avatar
Vazgeç