使用 python 更新所有 POS 订单

Update all POS order using python

我正在尝试更新所有 POS 订单,但由于我有大约 50,000 条记录,所以如果发生任何错误或强制停止执行。然后必须更新执行的记录数,但是在中间停止脚本时它没有存储记录。 所以请给我一些解决方案...

我用来更新记录的代码...

@api.multi
def update_all_amount(self):
    for order in self.search([('copy_amount_total', '=', 0)]):
        self._cr.execute("""update pos_order set copy_amount_total=%s where id = %s"""\
                       % (str(order.amount_total), str(order.id)))
            # print "\nupdated amount --- >", order.copy_amount_total, 
    print "success"

只需在每次更新后提交,那么它不会回滚所有已提交的记录。

@api.multi
def update_all_amount(self):
    for order in self.search([('copy_amount_total', '=', 0)]):
        self._cr.execute("""update pos_order set copy_amount_total=%s where id = %s"""\
                       % (str(order.amount_total), str(order.id)))
            # print "\nupdated amount --- >", order.copy_amount_total, 
        self._cr.commit()
    print "success"