Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
exclude: 'node_modules|.git'
default_stages: [commit]
default_stages: [pre-commit]
fail_fast: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
files: 'check_run.*'
Expand All @@ -20,58 +20,56 @@ repos:
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ['--py310-plus']

- repo: https://github.com/frappe/black
- repo: https://github.com/agritheory/black
rev: 951ccf4d5bb0d692b457a5ebc4215d755618eb68
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: prettier
types_or: [javascript]
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
check_run/public/dist/.*|
.*node_modules.*|
.*boilerplate.*|
check_run/www/website_script.js|
check_run/templates/includes/.*|
check_run/public/js/lib/.*
)$
- id: autoflake
args: [--remove-all-unused-imports, --in-place]

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear']

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.14.1
hooks:
- id: mypy
exclude: ^tests/
args: [--ignore-missing-imports]

- repo: local
- repo: https://github.com/agritheory/test_utils
rev: v0.17.0
hooks:
- id: update_pre_commit_config
- id: validate_copyright
files: '\.(js|ts|py|md)$'
args: ['--app', 'check_run']
- id: validate_customizations
always_run: true
name: .github/validate_customizations.py
entry: python .github/validate_customizations.py
language: system
types: [python]
# - id: validate_python_dependencies

- repo: local
hooks:
- id: prettier
name: prettier
entry: npx prettier . --write --ignore-path .prettierignore
language: node

ci:
autoupdate_schedule: weekly
Expand Down
45 changes: 45 additions & 0 deletions check_run/check_run/doctype/check_run/check_run.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ frappe.ui.form.on('Check Run', {
e.stopPropagation()
})
}
change_amount_label(frm)
settings_button(frm)
permit_first_user(frm)
get_defaults(frm)
set_queries(frm)
if (frm.doc.docstatus == 1 && frm.doc.sepa_file_generated == 0 && frm.pay_to_account_currency == 'EUR') {
downloadsepa(frm)
} else if (frm.doc.sepa_file_generated == 1 && frm.doc.docstatus == 1 && frm.pay_to_account_currency == 'EUR') {
gen_sepa_xml(frm)
}
frappe.realtime.off('reload')
frappe.realtime.on('reload', message => {
frm.reload_doc()
Expand Down Expand Up @@ -448,3 +454,42 @@ function check_settings(frm) {
})
}
}

function gen_sepa_xml(frm) {
frappe.xcall('check_run.check_run.doctype.check_run.check_run.get_authorized_role', { doc: frm.doc }).then(r => {
if (frappe.user.has_role(r)) {
downloadsepa(frm)
}
})
}

function downloadsepa(frm) {
frm.add_custom_button('Download SEPA', () => {
frappe.xcall('check_run.check_run.doctype.check_run.gen_sepa_xml.gen_sepa_xml_file', { doc: frm.doc }).then(r => {
downloadXML('payments.xml', r)
cur_frm.refresh()
})
})
}

function downloadXML(filename, content) {
var element = document.createElement('a')
element.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(content))
element.setAttribute('download', filename)
element.style.display = 'none'
document.body.appendChild(element)
element.click()
document.body.removeChild(element)
}

function change_amount_label(frm) {
frappe
.xcall('check_run.check_run.doctype.check_run.check_run.get_default_currency', { company: frm.doc.company })
.then(r => {
if (r) {
if (r != frm.pay_to_account_currency) {
cur_frm.fields_dict.amount_check_run.set_label('Estimated Amount in Check Run')
}
}
})
}
10 changes: 9 additions & 1 deletion check_run/check_run/doctype/check_run/check_run.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"transactions",
"print_count",
"status",
"ach_file_generated"
"ach_file_generated",
"sepa_file_generated"
],
"fields": [
{
Expand Down Expand Up @@ -165,6 +166,13 @@
"fieldtype": "Check",
"hidden": 1,
"label": "Ach File Generated"
},
{
"allow_on_submit": 1,
"default": "0",
"fieldname": "sepa_file_generated",
"fieldtype": "Check",
"hidden": 1
}
],
"is_submittable": 1,
Expand Down
16 changes: 16 additions & 0 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,19 @@ def get_authorized_role_for_ach(doc):
"role_allowed_to_download_ach_file_multiple_times",
)
return role


@frappe.whitelist()
def get_authorized_role(doc):
doc = frappe._dict(json.loads(doc)) if isinstance(doc, str) else doc
role = frappe.db.get_value(
"Check Run Settings",
{"pay_to_account": doc.pay_to_account, "bank_account": doc.bank_account},
"sepa_authorized_role",
)
return role


@frappe.whitelist()
def get_default_currency(company):
return frappe.db.get_value("Company", company, "default_currency")
Loading