[ Update all POS order using python ]
I am trying to update the all POS order, but as I having around 50,000 record so when if any error occurs or stops execution forcefully. Then the number of records which executed must be updated but It was not storing the records when stops the script in middle. So please give me some solution for this...
Code I am using to update record ...
@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"
Answer 1
Just put commit after each update, then it won't roll back all those records which are committed.
@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"