Skip to content

Commit

Permalink
Added overwrite param (can be overridden by api.json)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrRSatzteil committed Jun 2, 2024
1 parent 5d54a05 commit a3d42e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 6 additions & 3 deletions mayanmindee/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

@app.route("/general/<int:document_id>", methods=["GET", "POST"])
def trigger_general(document_id):
q.enqueue(process_standard, document_id, "ProofOfAddressV1")
overwrite = request.args.get('overwrite', default=False, type=bool)
q.enqueue(process_standard, document_id, "ProofOfAddressV1", overwrite)
return "OK"

@app.route("/invoice/<int:document_id>", methods=["GET", "POST"])
def trigger_invoice(document_id):
q.enqueue(process_standard, document_id, "InvoiceV4")
overwrite = request.args.get('overwrite', default=False, type=bool)
q.enqueue(process_standard, document_id, "InvoiceV4", overwrite)
return "OK"

@app.route("/custom/<api_name>/<int:document_id>", methods=["GET", "POST"])
def trigger_custom(api_name, document_id):
synchronous = request.args.get('synchronous', default=False, type=bool)
q.enqueue(process_custom, document_id, api_name, synchronous)
overwrite = request.args.get('overwrite', default=False, type=bool)
q.enqueue(process_custom, document_id, api_name, synchronous, overwrite)
return "OK"
12 changes: 8 additions & 4 deletions mayanmindee/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def getattritem(obj, attr: str) -> Any:
obj = operator.attrgetter(steps[-1].lstrip("."))(obj)
return obj

def process_standard(document_id: int, document_type: str) -> None:
def process_standard(document_id: int, document_type: str, overwrite: bool) -> None:
apis = load_config(document_type, "standard")

m = get_mayan()
Expand Down Expand Up @@ -204,12 +204,14 @@ def process_standard(document_id: int, document_type: str) -> None:
result, parsed_doc, metadata_mapping[1]["postprocess"]
)
if result:
if (metadata_mapping[1]["overwrite"]):
overwrite = metadata_mapping[1]["overwrite"];
add_metadata(
m,
document,
metadata_mapping[0],
result,
metadata_mapping[1]["overwrite"],
overwrite
)
result = None

Expand All @@ -232,7 +234,7 @@ def process_standard(document_id: int, document_type: str) -> None:
add_tags(m, document, tags)


def process_custom(document_id: int, document_type: str, synchronous: False) -> None:
def process_custom(document_id: int, document_type: str, synchronous: False, overwrite: bool) -> None:
apis = load_config(document_type, "custom")

account_name = apis[document_type]["account"]
Expand Down Expand Up @@ -283,12 +285,14 @@ def process_custom(document_id: int, document_type: str, synchronous: False) ->
result, parsed_doc, metadata_mapping[1]["postprocess"]
)
if result:
if metadata_mapping[1]["overwrite"]:
overwrite = metadata_mapping[1]["overwrite"]
add_metadata(
m,
document,
metadata_mapping[0],
result,
metadata_mapping[1]["overwrite"],
overwrite
)
result = None

Expand Down

0 comments on commit a3d42e2

Please sign in to comment.