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
- Účetnictví
- Sklad
- PoS
- Project
- MRP
This question has been flagged
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Přihlásit seRelated Posts | Odpovědi | Zobrazení | Aktivita | |
---|---|---|---|---|
|
1
dub 24
|
2938 | ||
|
2
úno 24
|
3184 | ||
ODOO Studio Calculate
Vyřešeno
|
|
1
říj 18
|
4632 | |
|
3
úno 24
|
2612 | ||
|
3
led 24
|
1984 |