Skip to Content
Menu
This question has been flagged
1914 Views

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
Discard
Related Posts Replies Views Activity
0
May 25
12
2
Jan 25
2493
1
Dec 24
6173
1
Nov 24
2624
1
Nov 24
1929