Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1918 Visualizações

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
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
0
mai. 25
12
2
jan. 25
2501
1
dez. 24
6191
1
nov. 24
2645
1
nov. 24
1963