From 7adea18ba93dc67c871920787ae98e6af56915fc Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Thu, 30 Nov 2023 07:11:40 +0100 Subject: [PATCH] Add invoice report cache script #163626 --- after/invoice_report_cache.py | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 after/invoice_report_cache.py diff --git a/after/invoice_report_cache.py b/after/invoice_report_cache.py new file mode 100755 index 0000000..9ea048b --- /dev/null +++ b/after/invoice_report_cache.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +import os +import sys + +dbname = sys.argv[1] +config_file = sys.argv[2] +from trytond.config import config as CONFIG +CONFIG.update_etc(config_file) + +from trytond.pool import Pool +from trytond.transaction import Transaction +import logging +from trytond.tools import grouped_slice + +Pool.start() +pool = Pool(dbname) +pool.init() + +context = {} + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) +ch = logging.StreamHandler(sys.stdout) +ch.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +ch.setFormatter(formatter) +logger.addHandler(ch) + +with Transaction().start(dbname, 0, context=context): + Invoice = pool.get('account.invoice') + Company = pool.get('company.company') + + for company in Company.search([]): + with Transaction().set_context(company=company.id): + invoices = Invoice.search([ + ('invoice_report_format', '=', None), + ('state', 'in', ['paid', 'posted']), + ('type', '=', 'out'), + ('company', '=', company), + ]) + + for sub_invoices in grouped_slice(invoices): + for invoice in sub_invoices: + invoice.print_invoice() + + Transaction().commit() + + logger.info('Done')