From e1f2102441f297bfb34e9b44a5a9f1d11397db1e Mon Sep 17 00:00:00 2001 From: CristianoMafraJunior Date: Mon, 11 Nov 2024 10:01:03 -0300 Subject: [PATCH] Add generation CLI Damdfe --- brazilfiscalreport/cli.py | 41 +++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/brazilfiscalreport/cli.py b/brazilfiscalreport/cli.py index ba69337..2764be0 100644 --- a/brazilfiscalreport/cli.py +++ b/brazilfiscalreport/cli.py @@ -141,5 +141,46 @@ def generate_dacte(xml): click.echo(f"DACTE generated successfully: {output_path}") +@cli.command("damdfe") +@click.argument("xml", type=click.Path(exists=True)) +def generate_damdfe(xml): + try: + from brazilfiscalreport import damdfe + except ImportError: + click.echo( + "Error: The brazilfiscalreport package " + "or its damdfe module is not installed." + ) + return + + config_data = load_config() + logo = config_data.get("LOGO") + top = config_data.get("TOP_MARGIN", 5) + right = config_data.get("RIGHT_MARGIN", 5) + bottom = config_data.get("BOTTOM_MARGIN", 5) + left = config_data.get("LEFT_MARGIN", 5) + + xml_path = Path(xml).resolve() + output_path = Path.cwd() / xml_path.stem + output_path = output_path.with_suffix(".pdf") + logo_path = Path(logo).resolve() if logo else None + + if logo_path and not logo_path.exists(): + click.echo("Logo file not found, proceeding without logo.") + logo_path = None + + with open(xml_path, encoding="utf-8") as xml_file: + xml_content = xml_file.read() + + config = damdfe.DamdfeConfig( + margins=damdfe.Margins(top=top, right=right, bottom=bottom, left=left), + logo=logo_path, + ) + + damdfe_instance = damdfe.Damdfe(xml=xml_content, config=config) + damdfe_instance.output(output_path) + click.echo(f"DAMDFE generated successfully: {output_path}") + + if __name__ == "__main__": cli() diff --git a/pyproject.toml b/pyproject.toml index 0524ae8..eaf4878 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dependencies = [ # DACTE specific dependencies [project.optional-dependencies] -dacte = [ +dacte-damdfe = [ "qrcode", ] cli = [