Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
1729 Vizualizări

Hi can someone help me please with a automated action to check if my field is over or under current date based on the result set field status

Situation:
model = stock.move

x_so_dispatch_date = date field

x_status = select field


so_x_dispatch_date if after now set x_status late

this condition to be only evaluated for moves not done 


thank you

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

You can try this code


Let us assume the field property is the given format


x_so_dispatch_date = fields.Date(string="Dispatch Date")

x_status = fields.Selection([('on_time', 'On Time'), ('late', 'Late')], string="Status")


then add the method like


@api.model

    def update_move_status(self):

        # Find moves that are not done and have a dispatch date after the current date

        late_moves = self.env['stock.move'].search([

            ('state', '!=', 'done'),

            ('x_so_dispatch_date', '>', fields.Date.today())

        ])


        # Update the status for late moves

        for move in late_moves:

            move.x_status = 'late'


        # Update the status for on-time moves

        on_time_moves = self.env['stock.move'].search([

            ('state', '!=', 'done'),

            ('x_so_dispatch_date', '        ])

        for move in on_time_moves:

            move.x_status = 'on_time'


Hope it helps

Imagine profil
Abandonează
Autor Cel mai bun răspuns

After fixing some indents errors and filed mismatchs i get the  "forbidden opcode(s) in 'lambda': STORE_ATTR" error on action save 
any idea why?

thank you 

Imagine profil
Abandonează
Cel mai bun răspuns

class StockMove(models.Model):

    _inherit = 'stock.move'


    x_so_dispatch_date = fields.Date(string='Dispatch Date')

    x_status = fields.Selection([

        ('on_time', 'On Time'),

        ('late', 'Late'),

    ], string='Status', compute='_compute_status', store=True)


    def _compute_status(self):

        for move in self:

            if move.state != 'done' and move.x_so_dispatch_date:

                if move.x_so_dispatch_date > fields.Date.today():

                    move.x_status = 'on_time'

                else:

                    move.x_status = 'late'

            else:

                move.x_status = False


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
sept. 23
1642
5
iul. 20
5615
0
mar. 17
2788
1
sept. 24
1051
0
oct. 21
1683