تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
3403 أدوات العرض

Hello, I am trying to import sales data from an old platform into Odoo via http. There are quite a lot sales to be iterated and if same error occurs  while the import script is running, the sales I supposedly had created aren't save. They are only saved if the script finishes. The script can be summarized like the following:

class Sales(models.Model):

    _inherit = 'sale.order'

    @api.multi

    def import_order(self):

        sales = function_that_get_the_sales()

        for sale in sales:

            dict = function_that_get_the_sales_dict(sale)

            sale = self.env['sale.order'].create(dict)


If the above script is run successfully, all sales are saved. If it gets an error at some point, none is saved. Is there a way I can actually create the sale object on each iteration, in a way that if something happens I will have the ones I had previously iterated through saved?

الصورة الرمزية
إهمال
أفضل إجابة

Hi, make commit in each iteration:

self.env.cr.commit()
الصورة الرمزية
إهمال
الكاتب

That's what I was looking for, thanks!

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 15
5891
2
مارس 15
6952
3
سبتمبر 24
5458
0
فبراير 22
11336
1
مايو 15
5196