Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2261 Ansichten

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Juli 25
2345
2
Juli 25
7829
2
Juli 25
4221
2
Juli 25
4006
2
Juni 25
2600