diff --git a/erpnext_germany/constants.py b/erpnext_germany/constants.py index aedae57..1a5581f 100644 --- a/erpnext_germany/constants.py +++ b/erpnext_germany/constants.py @@ -1,6 +1,5 @@ # German company register courts REGISTER_COURTS = [ - "", # empty string to be able to select nothing "Aachen", "Altenburg", "Amberg", diff --git a/erpnext_germany/custom_fields.py b/erpnext_germany/custom_fields.py new file mode 100644 index 0000000..58bc65b --- /dev/null +++ b/erpnext_germany/custom_fields.py @@ -0,0 +1,177 @@ +from .constants import REGISTER_COURTS + + +def _(message: str) -> str: + return message + + +def get_register_fields(insert_after: str): + return [ + { + "fieldtype": "Section Break", + "fieldname": "register_sb_1", + "label": _("Register Information"), + "insert_after": insert_after, + "collapsible": 1, + }, + { + "fieldtype": "Select", + "fieldname": "register_type", + "label": _("Register Type"), + "insert_after": "register_sb_1", + "options": "\nHRA\nHRB\nGnR\nPR\nVR", + "translatable": 0, + }, + { + "fieldtype": "Column Break", + "fieldname": "register_cb_1", + "insert_after": "register_type", + }, + { + "fieldtype": "Data", + "fieldname": "register_number", + "label": _("Register Number"), + "insert_after": "register_cb_1", + "translatable": 0, + }, + { + "fieldtype": "Column Break", + "fieldname": "register_cb_2", + "insert_after": "register_number", + }, + { + "fieldtype": "Select", + "fieldname": "register_court", + "label": _("Register Court"), + "insert_after": "register_cb_2", + "options": "\n".join([""] + REGISTER_COURTS), # empty string to be able to select nothing + "translatable": 0, + }, + ] + + +def get_custom_fields(): + custom_fields = { + "Company": [] + get_register_fields(insert_after="address_html"), + "Customer": [] + get_register_fields(insert_after="companies"), + "Supplier": [] + get_register_fields(insert_after="companies"), + "Employee": [ + { + "fieldtype": "Link", + "fieldname": "nationality", + "label": _("Nationality"), + "options": "Country", + "insert_after": "date_of_joining", + }, + { + "fieldtype": "Check", + "fieldname": "is_severely_disabled", + "label": _("Is Severely Disabled"), + "insert_after": "nationality", + }, + { + "fieldtype": "Float", + "fieldname": "working_hours_per_week", + "label": _("Working Hours Per Week"), + "insert_after": "attendance_device_id", + }, + # -- BEGIN TAXES SECTION -- + { + "fieldtype": "Section Break", + "fieldname": "employee_taxes_sb", + "label": _("Taxes"), + "insert_after": "default_shift", + "collapsible": 1, + }, + { + "fieldtype": "Data", + "fieldname": "tax_id", + "label": _("Tax ID"), + "insert_after": "employee_taxes_sb", + "translatable": 0, + }, + { + "fieldtype": "Data", + "fieldname": "tax_office", + "label": _("Tax Office"), + "insert_after": "tax_id", + "translatable": 0, + }, + { + "fieldtype": "Data", + "fieldname": "tax_office_number", + "label": _("Tax Office Number"), + "insert_after": "tax_office", + "translatable": 0, + }, + { + "fieldtype": "Column Break", + "fieldname": "employee_taxes_cb", + "insert_after": "tax_office_number", + }, + { + "fieldtype": "Select", + "fieldname": "tax_bracket", + "label": _("Tax Bracket"), + "options": "\nI\nII\nIII\nIV\nV\nVI", + "insert_after": "employee_taxes_cb", + "translatable": 0, + }, + { + "fieldtype": "Int", + "fieldname": "children_eligible_for_tax_credits", + "label": _("Children Eligible for Tax Credits"), + "insert_after": "tax_bracket", + }, + { + "fieldtype": "Link", + "fieldname": "religious_denomination", + "label": _("Religious Denomination"), + "options": "Religious Denomination", + "insert_after": "children_eligible_for_tax_credits", + }, + # -- END TAXES SECTION -- + { + "fieldtype": "Check", + "fieldname": "has_children", + "label": _("Has Children"), + "insert_after": "health_insurance_no", + }, + { + "fieldtype": "Check", + "fieldname": "has_other_employments", + "label": _("Has Other Employments"), + "insert_after": "external_work_history", + }, + { + "fieldtype": "Select", + "fieldname": "highest_school_qualification", + "label": _("Highest School Qualification"), + "options": "\nOhne Schulabschluss\nHaupt-/Volksschulabschluss\nMitttlere Reife\n(Fach-)Abitur", + "insert_after": "education", + "translatable": 0, + }, + ], + ("Quotation", "Sales Order", "Sales Invoice"): [ + { + "label": _("Tax Exemption Reason"), + "fieldtype": "Small Text", + "fieldname": "tax_exemption_reason", + "fetch_from": "taxes_and_charges.tax_exemption_reason", + "depends_on": "tax_exemption_reason", + "insert_after": "taxes_and_charges", + "translatable": 0, + } + ], + "Sales Taxes and Charges Template": [ + { + "label": _("Tax Exemption Reason"), + "fieldtype": "Small Text", + "fieldname": "tax_exemption_reason", + "insert_after": "tax_category", + "translatable": 0, + } + ], + } + + return custom_fields diff --git a/erpnext_germany/hooks.py b/erpnext_germany/hooks.py index 7bc51d8..22ec975 100644 --- a/erpnext_germany/hooks.py +++ b/erpnext_germany/hooks.py @@ -1,5 +1,4 @@ from . import __version__ as app_version -from .constants import REGISTER_COURTS app_name = "erpnext_germany" app_title = "ERPNext Germany" @@ -197,175 +196,6 @@ # "erpnext_germany.auth.validate" # ] - -def get_register_fields(insert_after: str): - return [ - { - "fieldtype": "Section Break", - "fieldname": "register_sb_1", - "label": "Register Information", - "insert_after": insert_after, - "collapsible": 1, - }, - { - "fieldtype": "Select", - "fieldname": "register_type", - "label": "Register Type", - "insert_after": "register_sb_1", - "options": "\nHRA\nHRB\nGnR\nPR\nVR", - "translatable": 0, - }, - { - "fieldtype": "Column Break", - "fieldname": "register_cb_1", - "insert_after": "register_type", - }, - { - "fieldtype": "Data", - "fieldname": "register_number", - "label": "Register Number", - "insert_after": "register_cb_1", - "translatable": 0, - }, - { - "fieldtype": "Column Break", - "fieldname": "register_cb_2", - "insert_after": "register_number", - }, - { - "fieldtype": "Select", - "fieldname": "register_court", - "label": "Register Court", - "insert_after": "register_cb_2", - "options": "\n".join(REGISTER_COURTS), - "translatable": 0, - }, - ] - - -germany_custom_fields = { - "Company": [] + get_register_fields(insert_after="address_html"), - "Customer": [] + get_register_fields(insert_after="companies"), - "Supplier": [] + get_register_fields(insert_after="companies"), - "Employee": [ - { - "fieldtype": "Link", - "fieldname": "nationality", - "label": "Nationality", - "options": "Country", - "insert_after": "date_of_joining", - }, - { - "fieldtype": "Check", - "fieldname": "is_severely_disabled", - "label": "Is Severely Disabled", - "insert_after": "nationality", - }, - { - "fieldtype": "Float", - "fieldname": "working_hours_per_week", - "label": "Working Hours Per Week", - "insert_after": "attendance_device_id", - }, - # -- BEGIN TAXES SECTION -- - { - "fieldtype": "Section Break", - "fieldname": "employee_taxes_sb", - "label": "Taxes", - "insert_after": "default_shift", - "collapsible": 1, - }, - { - "fieldtype": "Data", - "fieldname": "tax_id", - "label": "Tax ID", - "insert_after": "employee_taxes_sb", - "translatable": 0, - }, - { - "fieldtype": "Data", - "fieldname": "tax_office", - "label": "Tax Office", - "insert_after": "tax_id", - "translatable": 0, - }, - { - "fieldtype": "Data", - "fieldname": "tax_office_number", - "label": "Tax Office Number", - "insert_after": "tax_office", - "translatable": 0, - }, - { - "fieldtype": "Column Break", - "fieldname": "employee_taxes_cb", - "insert_after": "tax_office_number", - }, - { - "fieldtype": "Select", - "fieldname": "tax_bracket", - "label": "Tax Bracket", - "options": "\nI\nII\nIII\nIV\nV\nVI", - "insert_after": "employee_taxes_cb", - "translatable": 0, - }, - { - "fieldtype": "Int", - "fieldname": "children_eligible_for_tax_credits", - "label": "Children Eligible for Tax Credits", - "insert_after": "tax_bracket", - }, - { - "fieldtype": "Link", - "fieldname": "religious_denomination", - "label": "Religious Denomination", - "options": "Religious Denomination", - "insert_after": "children_eligible_for_tax_credits", - }, - # -- END TAXES SECTION -- - { - "fieldtype": "Check", - "fieldname": "has_children", - "label": "Has Children", - "insert_after": "health_insurance_no", - }, - { - "fieldtype": "Check", - "fieldname": "has_other_employments", - "label": "Has Other Employments", - "insert_after": "external_work_history", - }, - { - "fieldtype": "Select", - "fieldname": "highest_school_qualification", - "label": "Highest School Qualification", - "options": "\nOhne Schulabschluss\nHaupt-/Volksschulabschluss\nMitttlere Reife\n(Fach-)Abitur", - "insert_after": "education", - "translatable": 0, - }, - ], - ("Quotation", "Sales Order", "Sales Invoice"): [ - { - "label": "Tax Exemption Reason", - "fieldtype": "Small Text", - "fieldname": "tax_exemption_reason", - "fetch_from": "taxes_and_charges.tax_exemption_reason", - "depends_on": "tax_exemption_reason", - "insert_after": "taxes_and_charges", - "translatable": 0, - } - ], - "Sales Taxes and Charges Template": [ - { - "label": "Tax Exemption Reason", - "fieldtype": "Small Text", - "fieldname": "tax_exemption_reason", - "insert_after": "tax_category", - "translatable": 0, - } - ], -} - germany_property_setters = { "Employee": [ ("salary_currency", "default", "EUR", "Small Text"), diff --git a/erpnext_germany/install.py b/erpnext_germany/install.py index aedc8ed..b3bdf33 100644 --- a/erpnext_germany/install.py +++ b/erpnext_germany/install.py @@ -3,11 +3,11 @@ import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from frappe.custom.doctype.property_setter.property_setter import make_property_setter +from .custom_fields import get_custom_fields def after_install(): - custom_fields = frappe.get_hooks("germany_custom_fields") - create_custom_fields(custom_fields) + create_custom_fields(get_custom_fields()) make_property_setters() import_data() insert_custom_records() diff --git a/erpnext_germany/uninstall.py b/erpnext_germany/uninstall.py index 6ba5a73..c92747f 100644 --- a/erpnext_germany/uninstall.py +++ b/erpnext_germany/uninstall.py @@ -1,4 +1,5 @@ import frappe +from .custom_fields import get_custom_fields def before_uninstall(): @@ -9,7 +10,7 @@ def before_uninstall(): def remove_custom_fields(): print("* removing custom fields...") - for doctypes, custom_fields in frappe.get_hooks("germany_custom_fields").items(): + for doctypes, custom_fields in get_custom_fields().items(): if isinstance(doctypes, str): doctypes = (doctypes,)