Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Open] Feature: Automated Moneyplex Export #3

Merged
merged 6 commits into from
Sep 5, 2023

Conversation

roquegv
Copy link
Collaborator

@roquegv roquegv commented Aug 31, 2023

issue #2

What is included:

  • New fields added
    Captura de pantalla de 2023-08-31 11-12-19
  • Add button in Payment Request's listview
    Captura de pantalla de 2023-08-31 11-35-42
  • Fetch data as JSON after pressing the button:
    Kazam_screencast_00073
  • Download the Excel (.xlsx) file:
    Kazam_screencast_00076
  • Set für_moneyplex_exportiert to 1 when exporting
    Kazam_screencast_00077
  • Create Payments Entries when exporting:
    Kazam_screencast_00078
  • Disable the sending of email when submitting the Payment Request.

@roquegv
Copy link
Collaborator Author

roquegv commented Aug 31, 2023

Having problems downloading a .xlsx file.

Tested two different approaches.

  1. Using Pandas
    filename = "output.xlsx"
    filepath = "{}/private/files/{}".format(frappe.utils.get_site_path(), filename)
    df = pandas.DataFrame(result)
    df.to_excel(filepath, index=False)

    frappe.local.response.filename = filename
    filecontent = open(filepath, "rb").read()
    frappe.local.response.filecontent = filecontent
    frappe.local.response.type = "download"

where result is a list of dictionaries.

  1. Using openpyxl library (this is similar to what the export function in report view does):
workbook = openpyxl.Workbook()
    worksheet = workbook.active

    # Write header row
    header_row = list(result[0].keys())
    worksheet.append(header_row)

    # Write result rows
    for item in result:
        worksheet.append(list(item.values()))

    # Save the Excel file
    xlsx_file = BytesIO()
    workbook.save(xlsx_file)

    frappe.response["filename"] = filename
    frappe.response["filecontent"] = xlsx_file.getvalue()
    frappe.response["type"] = "binary"

In both cases I get this message in the browser console:

Unable to handle failed response [request.js:324:12](http://mysite.localhost:8000/apps/frappe/frappe/public/js/frappe/request.js)
console.trace() TypeError: xhr is undefined
    200 request.js:127
    call request.js:318
    jQuery 6
    call request.js:251
    call request.js:103
    frappe.listview_settings["Payment Request"].onload/< payment_request__custom_list_js:3
    jQuery 8
    add_button page.js:728
    frappe.listview_settings["Payment Request"].onload payment_request__custom_list_js:2
    setup_view list_view.js:263
    promise callback*frappe.run_serially/< dom.js:258
    run_serially dom.js:256
    init base_list.js:31
    show base_list.js:10
    promise callback*frappe.run_serially/< dom.js:258
    run_serially dom.js:256
    show base_list.js:9
    show list_view.js:43
    ListView list_view.js:26
    make list_factory.js:36
    callback model.js:179
    callback request.js:83
    200 request.js:127
    call request.js:269
    jQuery 6
    call request.js:251
    call request.js:103
    with_doctype model.js:153
    make list_factory.js:12
    show factory.js:24
    show list_factory.js:53
    render_page router.js:212
    render router.js:191
    route router.js:112
    set_route desk.js:149
    startup desk.js:60
    init desk.js:29
    start_app desk.js:13
    <anonymous> desk.js:24
    jQuery 8
[request.js:325:12](http://mysite.localhost:8000/apps/frappe/frappe/public/js/frappe/request.js)
    call request.js:325
    jQuery 6
    call request.js:251
    call request.js:103
    frappe.listview_settings["Payment Request"].onload/< payment_request__custom_list_js:3
    jQuery 8
    add_button page.js:728
    frappe.listview_settings["Payment Request"].onload payment_request__custom_list_js:2
    setup_view list_view.js:263
    (Asíncrono: promise callback)
    run_serially dom.js:258
    run_serially dom.js:256
    init base_list.js:31
    show base_list.js:10
    (Asíncrono: promise callback)
    run_serially dom.js:258
    run_serially dom.js:256
    show base_list.js:9
    show list_view.js:43
    ListView list_view.js:26
    make list_factory.js:36
    callback model.js:179
    callback request.js:83
    200 request.js:127
    call request.js:269
    jQuery 6
    call request.js:251
    call request.js:103
    with_doctype model.js:153
    make list_factory.js:12
    show factory.js:24
    show list_factory.js:53
    render_page router.js:212
    render router.js:191
    route router.js:112
    set_route desk.js:149
    startup desk.js:60
    init desk.js:29
    start_app desk.js:13
    <anonymous> desk.js:24
    jQuery 8

Solution

It was not possible to download the file using the frappe.response object. The way I solved this is to send the full file URL to the client, and from there download the file.

@roquegv
Copy link
Collaborator Author

roquegv commented Sep 1, 2023

Disable the sending of email when submitting the Payment Request.

This is not done yet, but I've seen that if the payment_gateway is not set then no email will be send. See this line in the code: send_mail = self.payment_gateway_validation() if self.payment_gateway else None

@roquegv
Copy link
Collaborator Author

roquegv commented Sep 1, 2023

There is a problem when fetching the values for party_iban and party_bic because they need to be fetched from the party_bank_account which is not set yet at the time of creation. One way to set these values is to change another value in the form (for example valuta) and save the form, that will make the trick.

I was trying to solve this by code but no luck until now. I created a Client Script for Payment Request form:

frappe.ui.form.on('Payment Request', {
	after_save(frm) {
	    console.log(frm.doc.party_iban)
		if (frm.doc.party_iban === null || frm.doc.party_iban === undefined){
		    var valuta = frm.doc.valuta
		    frm.set_value("valuta", "")
		    frm.set_value("valuta", valuta)
		    frm.save()
		}
	}
})

But it does not work.
Will try another approach.

@wojosc wojosc mentioned this pull request Sep 5, 2023
@marcus-wiegand marcus-wiegand merged commit 2d8dae3 into master Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants