Skip to content

Commit

Permalink
refactor: move custom fields to a separate file (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored Sep 28, 2024
1 parent 33688cf commit 72a7c9f
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 174 deletions.
1 change: 0 additions & 1 deletion erpnext_germany/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# German company register courts
REGISTER_COURTS = [
"", # empty string to be able to select nothing
"Aachen",
"Altenburg",
"Amberg",
Expand Down
177 changes: 177 additions & 0 deletions erpnext_germany/custom_fields.py
Original file line number Diff line number Diff line change
@@ -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
170 changes: 0 additions & 170 deletions erpnext_germany/hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from . import __version__ as app_version
from .constants import REGISTER_COURTS

app_name = "erpnext_germany"
app_title = "ERPNext Germany"
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions erpnext_germany/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion erpnext_germany/uninstall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import frappe
from .custom_fields import get_custom_fields


def before_uninstall():
Expand All @@ -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,)

Expand Down

0 comments on commit 72a7c9f

Please sign in to comment.