SuffolkLITLab / docassemble-AssemblyLine

Quickly go from a paper court form to a runnable, guided, step-by-step web application powered by Docassemble. Swap out branding and pre-built questions to meet your needs.
https://suffolklitlab.org/docassemble-AssemblyLine-documentation/
MIT License
42 stars 5 forks source link

Enhance ALDocumentBundle by adding an affordance to handle dynamic item counts #889

Open nonprofittechy opened 2 hours ago

nonprofittechy commented 2 hours ago

ALDocumentBundle envisions a static cap on the number of documents you produce, but something, this number is dynamic.

For example: in Illinois, if you have multiple jobs, each job needs to recorded on a separate PDF document with a fixed format. The number of documents you produce is contingent on the number of jobs and there is no cap.

  1. If you produce the bundle per-user, that's not a problem--just make the bundle an attribute of the user.
  2. But if you want a single bundle to produce documents for an unbounded list, currently, you need to manually handle the list's contents and use a manual reconsider or perhaps on update block to handle refreshing the bundle's contents when the list changes.

I'm not sure yet what affordance makes sense. People can handle this manually with Python code, but a simpler API for common use cases would be helpful.

ll-jgraszer commented 1 hour ago

The approach I'm using for this was to loop through the gathered list after the first element and enable the attachment(s) into a bundle:

objects:
  - employment[i].additional_employment: ALDocument.using(title="FA Additional Employment Business", filename="fa_additional_employment_business.pdf", has_addendum=False)
---
objects:
  - additional_employment_bundle: ALDocumentBundle.using(elements=[], title= "FA Additional Employment Bundle", filename="fa_additional_employment_business.pdf", has_addendum=False)
---
reconsider: True
code: |
  employment_to_bundle = []
  additional_employment_bundle.enabled = False

  for index, el in enumerate(employment):
    # No need for additional employment or business income unless employment.number_gathered() >= 1
    if index == 0:
      el.additional_employment.enabled = False
    else:
      el.additional_employment.enabled = True
      additional_employment_bundle.enabled = True
      employment_to_bundle.append(el.additional_employment)

  additional_employment_bundle.elements = employment_to_bundle
  complete_additional_employment = True
---
attachment:
  variable name: employment[i].additional_employment[j]
  name: additional_employment
  filename: additional_employment
  skip undefined: True
  editable: False
  pdf template file: fa_additional_employment_business.pdf
  fields:
      - "county": ${ case_county }
      - "case_number": ${ case_number }
      ...
      - "employed_yes": ${ employment[i].type == 'employed' }
      ...