Skip to Content
Menú
This question has been flagged
2006 Vistes

I'm trying to apply some customize once stock.move done and make it run in background due to performance issue of validating picking so multi thread is solution. But I'm in trouble with updating data in the same row: 

def _action_done(self, cancel_backorder=False):

        res = super(StockMove, self)._action_done(cancel_backorder=cancel_backorder)

        if res:

            if res.filtered(lambda x: x.state == 'done'):

                threaded_calculation = threading.Thread(

                                target=self.sync_fulfillment_stats,

                                args=(res.filtered(lambda x: x.state == 'done').ids))

                threaded_calculation.setDaemon(True)

                threaded_calculation.start()

 

def sync_fulfillment_stats(self, move_ids):

        # sleeping time to make sure quantity done is already saved

        time2.sleep(3)

        with api.Environment.manage(), self.pool.cursor() as new_cr:

            self = self.with_env(self.env(cr=new_cr))


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

                [('id', 'in', move_ids)])

            for move in moves:

​move.sync = True   




Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de juny 25
1182
0
de maig 25
12
2
de gen. 25
2759
1
de des. 24
6413
1
de nov. 24
2869