跳至内容
菜单
此问题已终结
2259 查看

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   




形象
丢弃
相关帖文 回复 查看 活动
1
7月 25
2345
2
7月 25
7828
2
7月 25
4221
2
7月 25
4006
2
6月 25
2600