Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: Products & Pricelists
Entity: product.product
Compute Method: _compute_write_date
| Inputs | Method | Outputs |
|---|---|---|
|
"""
First, the purpose of this computation is to update a product's
write_date whenever its template's write_date is updated. Indeed,
when a template's image is modified, updating its products'
write_date will invalidate the browser's cache for the products'
image, which may be the same as the template's. This guarantees UI
consistency.
Second, the field 'write_date' is automatically updated by the
framework when the product is modified. The recomputation of the
field supplements that behavior to keep the product's write_date
up-to-date with its template's write_date.
Third, the framework normally prevents us from updating write_date
because it is a "magic" field. However, the assignment inside the
compute method is not subject to this restriction. It therefore
works as intended :-)
"""
now = self.env.cr.now()
+ self.fetch(['write_date'])
for record in self:
- record.write_date = max(record.write_date or now, record.product_tmpl_id.write_date or now)
+ if not record.id:
+ record.write_date = record._origin.write_date
+ continue
+ record.write_date = max(
+ record.write_date or now, record.product_tmpl_id.write_date or now
+ )
|
|
