Skip to content

Commit

Permalink
Merge pull request #8 from beingeek/develop
Browse files Browse the repository at this point in the history
change request
  • Loading branch information
wojosc authored Nov 1, 2023
2 parents e34a69d + a0596ed commit 6c3f0fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
15 changes: 7 additions & 8 deletions german_accounting/events/extended_tax_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ def validate_tax_category_fields(doc, method=None):
goods_amt_sum = 0.0
services_amt_sum = 0.0

def get_parent_and_descendants_list(item_group):
def get_parent_and_descendants_item_group_list(item_group):
item_groups = [item_group]
descendants_item_group = get_descendants_of("Item Group", item_group)
if descendants_item_group:
item_groups = item_groups + descendants_item_group

return item_groups
return item_groups + descendants_item_group if descendants_item_group else item_groups

goods_item_group = frappe.get_cached_value('German Accounting Settings', None, 'goods_item_group')
service_item_group = frappe.get_cached_value('German Accounting Settings', None, 'service_item_group')
Expand All @@ -22,15 +19,17 @@ def get_parent_and_descendants_list(item_group):
if not service_item_group:
frappe.throw('Please set Service Item Group in German Accounting Settings')

goods_item_group_list = get_parent_and_descendants_item_group_list(goods_item_group)
services_item_group_list = get_parent_and_descendants_item_group_list(service_item_group)
# Here we go through the item table and count the amounts for the two categories
for item in doc.get("items"):
if item.item_group in get_parent_and_descendants_list(goods_item_group):
if item.item_group in goods_item_group_list:
goods_amt_sum += flt(item.amount)
elif item.item_group in get_parent_and_descendants_list(service_item_group):
elif item.item_group in services_item_group_list:
services_amt_sum += flt(item.amount)

# Test which amount is higher...
if goods_amt_sum >= services_amt_sum:
doc.item_group = goods_item_group
else:
doc.item_group = service_item_group
doc.item_group = service_item_group
22 changes: 1 addition & 21 deletions german_accounting/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,13 @@ def get_custom_fields():
"fieldname": "item_group",
"fieldtype": "Data",
"read_only": 1,
"translatable": 1,
"translatable": 0,
"insert_after": "imat_section",
"description": "This field will be filled by either 'Goods' or 'Services' depending on the result that is calculated in the item table."
},
{
"label": "VAT ID",
"fieldname": "vatid",
"fieldtype": "Data",
"read_only": 1,
"translatable": 1,
"insert_after": "item_group",
"fetch_from": "customer_address.vatid",
"description": "This can be a validation in the backround that will check if the `vatid` field in Customer/Address is set."
}
]

address_custom_field = [
{
"label": "VAT ID",
"fieldname": "vatid",
"fieldtype": "Data",
"insert_after": "fax"
}
]

return {
"Address": address_custom_field,
"Quotation": custom_fields_transaction,
"Sales Order": custom_fields_transaction,
"Sales Invoice": custom_fields_transaction
Expand Down

0 comments on commit 6c3f0fe

Please sign in to comment.