Merge pull request #23843 from frappe/datev_check_fiscal_year
feat: validate fiscal year
This commit is contained in:
commit
94bfa6a659
@ -104,7 +104,7 @@ def get_header(filters, csv_class):
|
||||
# L = Tax client number (Mandantennummer)
|
||||
datev_settings.get('client_number', '00000'),
|
||||
# M = Start of the fiscal year (Wirtschaftsjahresbeginn)
|
||||
frappe.utils.formatdate(frappe.defaults.get_user_default('year_start_date'), 'yyyyMMdd'),
|
||||
frappe.utils.formatdate(filters.get('fiscal_year_start'), 'yyyyMMdd'),
|
||||
# N = Length of account numbers (Sachkontenlänge)
|
||||
datev_settings.get('account_number_length', '4'),
|
||||
# O = Transaction batch start date (YYYYMMDD)
|
||||
|
@ -13,6 +13,7 @@ import json
|
||||
import frappe
|
||||
from frappe import _
|
||||
from six import string_types
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
from erpnext.regional.germany.utils.datev.datev_csv import download_csv_files_as_zip, get_datev_csv
|
||||
from erpnext.regional.germany.utils.datev.datev_constants import Transactions, DebtorsCreditors, AccountNames
|
||||
|
||||
@ -98,21 +99,33 @@ def execute(filters=None):
|
||||
|
||||
def validate(filters):
|
||||
"""Make sure all mandatory filters and settings are present."""
|
||||
if not filters.get('company'):
|
||||
company = filters.get('company')
|
||||
if not company:
|
||||
frappe.throw(_('<b>Company</b> is a mandatory filter.'))
|
||||
|
||||
if not filters.get('from_date'):
|
||||
from_date = filters.get('from_date')
|
||||
if not from_date:
|
||||
frappe.throw(_('<b>From Date</b> is a mandatory filter.'))
|
||||
|
||||
if not filters.get('to_date'):
|
||||
to_date = filters.get('to_date')
|
||||
if not to_date:
|
||||
frappe.throw(_('<b>To Date</b> is a mandatory filter.'))
|
||||
|
||||
validate_fiscal_year(from_date, to_date, company)
|
||||
|
||||
try:
|
||||
frappe.get_doc('DATEV Settings', filters.get('company'))
|
||||
except frappe.DoesNotExistError:
|
||||
frappe.throw(_('Please create <b>DATEV Settings</b> for Company <b>{}</b>.').format(filters.get('company')))
|
||||
|
||||
|
||||
def validate_fiscal_year(from_date, to_date, company):
|
||||
from_fiscal_year = get_fiscal_year(date=from_date, company=company)
|
||||
to_fiscal_year = get_fiscal_year(date=to_date, company=company)
|
||||
if from_fiscal_year != to_fiscal_year:
|
||||
frappe.throw(_('Dates {} and {} are not in the same fiscal year.').format(from_date, to_date))
|
||||
|
||||
|
||||
def get_transactions(filters, as_dict=1):
|
||||
"""
|
||||
Get a list of accounting entries.
|
||||
@ -317,9 +330,13 @@ def download_datev_csv(filters):
|
||||
filters = json.loads(filters)
|
||||
|
||||
validate(filters)
|
||||
company = filters.get('company')
|
||||
|
||||
fiscal_year = get_fiscal_year(date=filters.get('from_date'), company=company)
|
||||
filters['fiscal_year_start'] = fiscal_year[1]
|
||||
|
||||
# set chart of accounts used
|
||||
coa = frappe.get_value('Company', filters.get('company'), 'chart_of_accounts')
|
||||
coa = frappe.get_value('Company', company, 'chart_of_accounts')
|
||||
filters['skr'] = '04' if 'SKR04' in coa else ('03' if 'SKR03' in coa else '')
|
||||
|
||||
transactions = get_transactions(filters)
|
||||
|
Loading…
x
Reference in New Issue
Block a user