summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAdrian Torres <adt@odoo.com>2019-03-21 15:38:11 +0000
committerAdrian Torres <adt@odoo.com>2019-03-22 12:08:35 +0000
commit353474fba2f9687c99b0c664639ba9936fea904d (patch)
tree94f8c8453a1f44f416b3cb35c085f7f54af535e0 /addons
parentf15a19d127f9238dadc7cb4c2cdac92230b2f288 (diff)
[FIX] sale: do create of sale.order.line in batch
With this patch, `sale.order.line` records can now be created in batch, this means that operations such as: - SO copy - SO create + commands - SO import will benefit from this patch in terms of performance. E.g. For a SO of 2k lines, duplicating the SO takes: Before patch: 1515s After patch: 171s Creating an SO with SOL as o2m commands: Before patch: 181s After patch: 43s closes odoo/odoo#32040 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/sale/models/sale.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index c73944cd777..6c698a35169 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -1046,20 +1046,23 @@ class SaleOrderLine(models.Model):
res[field] = line._fields[field].convert_to_write(line[field], line)
return res
- @api.model
- def create(self, values):
- if values.get('display_type', self.default_get(['display_type'])['display_type']):
- values.update(product_id=False, price_unit=0, product_uom_qty=0, product_uom=False, customer_lead=0)
-
- values.update(self._prepare_add_missing_fields(values))
- line = super(SaleOrderLine, self).create(values)
- if line.product_id and line.order_id.state == 'sale':
- msg = _("Extra line with %s ") % (line.product_id.display_name,)
- line.order_id.message_post(body=msg)
- # create an analytic account if at least an expense product
- if line.product_id.expense_policy not in [False, 'no'] and not self.order_id.analytic_account_id:
- self.order_id._create_analytic_account()
- return line
+ @api.model_create_multi
+ def create(self, vals_list):
+ for values in vals_list:
+ if values.get('display_type', self.default_get(['display_type'])['display_type']):
+ values.update(product_id=False, price_unit=0, product_uom_qty=0, product_uom=False, customer_lead=0)
+
+ values.update(self._prepare_add_missing_fields(values))
+
+ lines = super().create(vals_list)
+ for line in lines:
+ if line.product_id and line.order_id.state == 'sale':
+ msg = _("Extra line with %s ") % (line.product_id.display_name,)
+ line.order_id.message_post(body=msg)
+ # create an analytic account if at least an expense product
+ if line.product_id.expense_policy not in [False, 'no'] and not line.order_id.analytic_account_id:
+ line.order_id._create_analytic_account()
+ return lines
_sql_constraints = [
('accountable_required_fields',