Community: Framework mailing list archives

expert-framework@mail.odoo.com

Re: How to get a new cursor on new api on Thread

by
Maxim Litnitskiy
- 09/24/2014 23:20:56
I guess yes because I can see the following code:

class procurement_compute(osv.osv_memory):
    _name = 'procurement.orderpoint.compute'
    _description = 'Compute Minimum Stock Rules'


    def _procure_calculation_orderpoint(self, cr, uid, ids, context=None):
        """
        @param self: The object pointer.
        @param cr: A database cursor
        @param uid: ID of the user currently logged in
        @param ids: List of IDs selected
        @param context: A standard dictionary
        """
        with Environment.manage():
            proc_obj = self.pool.get('procurement.order')
            #As this function is in a new thread, I need to open a new cursor, because the old one may be closed
            new_cr = self.pool.cursor()
            user_obj = self.pool.get('res.users')
            company_id = user_obj.browse(new_cr, uid, uid, context=context).company_id.id
            proc_obj._procure_orderpoint_confirm(new_cr, uid, use_new_cursor=new_cr.dbname, company_id = company_id, context=context)
            #close the new cursor
            new_cr.close()
            return {}

    def procure_calculation(self, cr, uid, ids, context=None):
        """
        @param self: The object pointer.
        @param cr: A database cursor
        @param uid: ID of the user currently logged in
        @param ids: List of IDs selected
        @param context: A standard dictionary
        """

        threaded_calculation = threading.Thread(target=self._procure_calculation_orderpoint, args=(cr, uid, ids, context))
        threaded_calculation.start()
        return {'type': 'ir.actions.act_window_close'}