changeset 26d1c350a774 in modules/account_invoice:default
details: 
https://hg.tryton.org/modules/account_invoice?cmd=changeset&node=26d1c350a774
description:
        Use task to print invoice on posting

        issue11233
        review395461003
diffstat:

 invoice.py |  15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diffs (40 lines):

diff -r ac674a252a05 -r 26d1c350a774 invoice.py
--- a/invoice.py        Sun Mar 06 13:43:50 2022 +0100
+++ b/invoice.py        Sun Mar 06 18:22:06 2022 +0100
@@ -1454,14 +1454,16 @@
         if to_write:
             cls.write(*to_write)
 
-    def print_invoice(self):
+    @dualmethod
+    def print_invoice(cls, invoices):
         '''
         Generate invoice report and store it in invoice_report field.
         '''
-        if self.invoice_report_cache:
-            return
         InvoiceReport = Pool().get('account.invoice', type='report')
-        InvoiceReport.execute([self.id], {})
+        for invoice in invoices:
+            if invoice.invoice_report_cache:
+                return
+            InvoiceReport.execute([invoice.id], {})
 
     def _credit(self, **values):
         '''
@@ -1600,11 +1602,14 @@
         cls.save(invoices)
         Move.post([i.move for i in invoices if i.move.state != 'posted'])
         reconciled = []
+        to_print = []
         for invoice in invoices:
             if invoice.type == 'out':
-                invoice.print_invoice()
+                to_print.append(invoice)
             if invoice.reconciled:
                 reconciled.append(invoice)
+        if to_print:
+            cls.__queue__.print_invoice(to_print)
         if reconciled:
             cls.__queue__.process(reconciled)
 

Reply via email to