Skip to content

Commit

Permalink
Add generation CLI Damdfe
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianoMafraJunior committed Nov 11, 2024
1 parent 71430d4 commit e1f2102
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions brazilfiscalreport/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies = [

# DACTE specific dependencies
[project.optional-dependencies]
dacte = [
dacte-damdfe = [
"qrcode",
]
cli = [
Expand Down

0 comments on commit e1f2102

Please sign in to comment.