Hello, I am trying to obtain the value of a date that appears in the chat record, I am trying to save it in a calculated field of type date, but I have not been able to find a way to obtain it, I am trying to do this in the stock.picking model and the specific date is a status of a transfer, for example "confirmed", I appreciate any help or guidance.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
Hi,
To obtain the value of a date associated with a
specific status in a stock.picking record and save it in a calculated
field of type date, you can achieve this using Odoo's computed fields
and searching through the stock.picking records based on their status.
Here's a general outline of how you can implement this:
Define a computed field in the stock.picking model to store the desired date value.
Use
the @api.depends decorator to specify the dependencies for the computed
field. In this case, it will depend on the status of the picking.
Implement
the logic inside the computed field method to search for records with
the desired status and retrieve the associated date value.
Here's an example implementation:from odoo import models, fields, api
class StockPicking(models.Model):
_inherit = 'stock.picking'
# Define a computed field to store the desired date value
status_date = fields.Date(string='Status Date', compute='_compute_status_date', store=True)
@api.depends('state')
def _compute_status_date(self):
for picking in self:
# You can customize this logic based on your specific requirements
if picking.state == 'confirmed':
# Search for related moves, for example
move = self.env['stock.move'].search([('picking_id', '=', picking.id)], limit=1)
if move:
picking.status_date = move.date # Assign the date value to the computed field
else:
picking.status_date = False # No move found, set the field value to False
else:
picking.status_date = False # Set the field value to False if the status is not 'confirmed'
Hope it helps
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
1
abr 24
|
2928 | ||
|
2
feb 24
|
3174 | ||
ODOO Studio Calculate
Resuelto
|
|
1
oct 18
|
4630 | |
|
3
feb 24
|
2600 | ||
|
3
ene 24
|
1983 |