changeset 551652b0f693 in modules/sale_shipment_cost:default
details: 
https://hg.tryton.org/modules/sale_shipment_cost?cmd=changeset;node=551652b0f693
description:
        Save shipments at once

        This is faster then writing on each iteration.

        issue9270
        review297671002
diffstat:

 sale.py |  19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diffs (45 lines):

diff -r 600b566eb4ec -r 551652b0f693 sale.py
--- a/sale.py   Mon May 04 12:28:32 2020 +0200
+++ b/sale.py   Sun May 10 12:00:47 2020 +0200
@@ -266,20 +266,21 @@
                         shipment.get_carrier_context()):
                     cost, currency_id = self.carrier.get_sale_price()
                 cost = round_price(cost)
-                Shipment.write([shipment], {
-                        'carrier': self.carrier.id,
-                        'cost': cost,
-                        'cost_currency': currency_id,
-                        })
+                shipment.carrier = self.carrier
+                shipment.cost = cost
+                shipment.cost_currency = currency_id
+        Shipment.save(shipments)
         return shipments
 
     def create_invoice(self):
         pool = Pool()
         Invoice = pool.get('account.invoice')
+        InvoiceLine = pool.get('account.invoice.line')
         Shipment = pool.get('stock.shipment.out')
 
         invoice = super(Sale, self).create_invoice()
         if invoice and self.shipment_cost_method == 'shipment':
+            invoice_lines = []
             for shipment in self.shipments:
                 if (shipment.state == 'done'
                         and shipment.carrier
@@ -289,10 +290,10 @@
                     if not invoice_line:
                         continue
                     invoice_line.invoice = invoice
-                    invoice_line.save()
-                    Shipment.write([shipment], {
-                            'cost_invoice_line': invoice_line.id,
-                            })
+                    invoice_lines.append(invoice_line)
+                    shipment.cost_invoice_line = invoice_line
+            InvoiceLine.save(invoice_lines)
+            Shipment.save(self.shipments)
             Invoice.update_taxes([invoice])
         return invoice
 

Reply via email to