[MERGE] *: create records in batch

Ensure main Odoo models supports batch record creation.

* `purchase.order.line` supports multi creation in `purchase`, but not anymore when `purchase_stock` is installed.
* `sale.order.line` supports multi creation in `sale`, but not anymore when `sale_purchase` is installed.
* `crm.lead` doesn't support batch creation atm, but it doesn't cost anything to support it.

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

closes odoo/odoo#50468

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Odoo's Mergebot
2020-05-04 18:28:53 +02:00
committed by GitHub
3 changed files with 16 additions and 16 deletions
+5 -5
View File
@@ -374,12 +374,12 @@ class Lead(models.Model):
self._table, ['create_date', 'team_id'])
return res
@api.model
def create(self, vals):
lead = super(Lead, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
leads = super().create(vals_list)
# Compute new probability for each lead separately
lead._update_probability()
return lead
leads._update_probability()
return leads
def write(self, vals):
# stage change:
+5 -6
View File
@@ -304,12 +304,11 @@ class PurchaseOrderLine(models.Model):
total += move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom)
line.qty_received = total
@api.model
def create(self, values):
line = super(PurchaseOrderLine, self).create(values)
if line.order_id.state == 'purchase':
line._create_or_update_picking()
return line
@api.model_create_multi
def create(self, vals_list):
lines = super(PurchaseOrderLine, self).create(vals_list)
lines.filtered(lambda l: l.order_id.state == 'purchase')._create_or_update_picking()
return lines
def write(self, values):
for line in self.filtered(lambda l: not l.display_type):
+6 -5
View File
@@ -109,13 +109,14 @@ class SaleOrderLine(models.Model):
# CRUD
# --------------------------
@api.model
@api.model_create_multi
def create(self, values):
line = super(SaleOrderLine, self).create(values)
lines = super(SaleOrderLine, self).create(values)
# Do not generate purchase when expense SO line since the product is already delivered
if line.state == 'sale' and not line.is_expense:
line.sudo()._purchase_service_generation()
return line
lines.filtered(
lambda line: line.state == 'sale' and not line.is_expense
)._purchase_service_generation()
return lines
def write(self, values):
increased_lines = None