diff --git a/lib/invoice/cli.py b/lib/invoice/cli.py index 4871363..93407c6 100644 --- a/lib/invoice/cli.py +++ b/lib/invoice/cli.py @@ -128,36 +128,37 @@ class Application: tmp_pdf_file = os.path.join(tmp_path, "{}.pdf".format(invoice._name)) pdf_file = os.path.join(output_path, "{}.pdf".format(invoice._name)) - if generate and (not os.path.exists(pdf_file) or - os.path.getmtime(invoice._path) > os.path.getmtime(pdf_file)): - issuer = self.db.companies[self.my_company] - customer = self.db.companies[invoice.company_name] - - invoice_data = invoice.data() - issuer_data = issuer.data() - customer_data = customer.data() - - log.debug("Invoice: {}".format(invoice_data._data)) - log.debug("Issuer: {}".format(issuer_data._data)) - log.debug("Customer: {}".format(customer_data._data)) - - log.debug("Creating TeX invoice...") - self._check_path(self.tmp_path) - result = tempita.Template(open(tex_template).read()).substitute( - invoice=invoice_data, issuer=issuer_data, customer=customer_data) - open(tex_file, "w").write(str(result)) - assert(os.path.exists(tex_file)) - - log.debug("Creating PDF invoice...") - if subprocess.call((self.tex_program, "{}.tex".format(invoice._name)), cwd=tmp_path) != 0: - raise GenerationError("PDF generation failed.") - assert(os.path.exists(tmp_pdf_file)) - - log.debug("Moving PDF file to the output directory...") - self._check_path(output_path) - os.rename(tmp_pdf_file, pdf_file) - else: - log.info("PDF file is up to date.") + if generate: + if(not os.path.exists(pdf_file) or + os.path.getmtime(invoice._path) > os.path.getmtime(pdf_file)): + issuer = self.db.companies[self.my_company] + customer = self.db.companies[invoice.company_name] + + invoice_data = invoice.data() + issuer_data = issuer.data() + customer_data = customer.data() + + log.debug("Invoice: {}".format(invoice_data._data)) + log.debug("Issuer: {}".format(issuer_data._data)) + log.debug("Customer: {}".format(customer_data._data)) + + log.debug("Creating TeX invoice...") + self._check_path(self.tmp_path) + result = tempita.Template(open(tex_template).read()).substitute( + invoice=invoice_data, issuer=issuer_data, customer=customer_data) + open(tex_file, "w").write(str(result)) + assert(os.path.exists(tex_file)) + + log.debug("Creating PDF invoice...") + if subprocess.call((self.tex_program, "{}.tex".format(invoice._name)), cwd=tmp_path) != 0: + raise GenerationError("PDF generation failed.") + assert(os.path.exists(tmp_pdf_file)) + + log.debug("Moving PDF file to the output directory...") + self._check_path(output_path) + os.rename(tmp_pdf_file, pdf_file) + else: + log.info("PDF file is up to date.") assert(os.path.exists(pdf_file)) log.debug("Running PDF viewer...")