跳至內容
選單
此問題已被標幟
1 回覆
1563 瀏覽次數

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.

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
4月 24
3168
2
2月 24
3447
1
10月 18
4805
3
2月 24
2803
3
1月 24
2277