Skip to content

Commit 2ebcd7d

Browse files
committed
Initial
1 parent cb3db20 commit 2ebcd7d

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

satdigitalinvoice/gui_functions.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import hashlib
23
import logging
34
import os
45
import shutil
@@ -416,22 +417,43 @@ def sum_payments(payments):
416417
return amounts
417418

418419

420+
def sha256_hash(data):
421+
hash_object = hashlib.sha1(data.encode())
422+
hex_dig = hash_object.hexdigest()
423+
return hex_dig
424+
419425
def generate_pdf_template(template_name, fields, target=None, css_string=None):
420426
template = facturacion_environment.get_template(template_name)
421427
md5_document = template.render(
422428
fields
423429
)
430+
hex_dig = sha256_hash(md5_document)
431+
432+
hash_mark = """
433+
@page {
434+
@bottom-left{
435+
content: "sha1: [[hash]]";
436+
font:8px Verdana,sans-serif;
437+
}
438+
}
439+
""".replace("[[hash]]", hex_dig)
440+
424441
html = markdown(md5_document)
425442
pdf = HTML(string=html).write_pdf(
426443
target=target,
427444
stylesheets=[
428445
os.path.join(SOURCE_DIRECTORY, "markdown_styles", "markdown6.css"),
429446
CSS(
430-
string=css_string or '@page { width: Letter; margin: 1.6cm 1.6cm 1.6cm 1.6cm; }'
447+
string=css_string
448+
),
449+
CSS(
450+
string=hash_mark
431451
)
432452
]
433453
)
434-
return pdf
454+
with open(target + ".sha1_" + hex_dig[-8:] + ".txt", "w") as f:
455+
f.write(md5_document)
456+
435457

436458

437459
def mf_pago_fmt(cfdi):

satdigitalinvoice/markdown_styles/markdown6.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
font:13px Verdana,sans-serif;
55
}
66
}
7+
@page { width: Letter; margin: 1.6cm 1.6cm 1.6cm 1.6cm; }
8+
79
/* Main CSS from the Markdown Viewer Extension */
810
body,h1{
911
color:#000

satdigitalinvoice/schemas/cliente.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ properties:
6161
type: string
6262
Domicilio:
6363
type: string
64+
Poder:
65+
type: string
6466
additionalProperties: false
6567
Corredores:
6668
type: array

0 commit comments

Comments
 (0)