Merge pull request #23843 from frappe/datev_check_fiscal_year

feat: validate fiscal year
This commit is contained in:
rohitwaghchaure 2020-11-09 12:33:15 +05:30 committed by GitHub
commit 94bfa6a659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View File

@ -104,7 +104,7 @@ def get_header(filters, csv_class):
# L = Tax client number (Mandantennummer) # L = Tax client number (Mandantennummer)
datev_settings.get('client_number', '00000'), datev_settings.get('client_number', '00000'),
# M = Start of the fiscal year (Wirtschaftsjahresbeginn) # 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) # N = Length of account numbers (Sachkontenlänge)
datev_settings.get('account_number_length', '4'), datev_settings.get('account_number_length', '4'),
# O = Transaction batch start date (YYYYMMDD) # O = Transaction batch start date (YYYYMMDD)

View File

@ -13,6 +13,7 @@ import json
import frappe import frappe
from frappe import _ from frappe import _
from six import string_types 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_csv import download_csv_files_as_zip, get_datev_csv
from erpnext.regional.germany.utils.datev.datev_constants import Transactions, DebtorsCreditors, AccountNames from erpnext.regional.germany.utils.datev.datev_constants import Transactions, DebtorsCreditors, AccountNames
@ -98,21 +99,33 @@ def execute(filters=None):
def validate(filters): def validate(filters):
"""Make sure all mandatory filters and settings are present.""" """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.')) 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.')) 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.')) frappe.throw(_('<b>To Date</b> is a mandatory filter.'))
validate_fiscal_year(from_date, to_date, company)
try: try:
frappe.get_doc('DATEV Settings', filters.get('company')) frappe.get_doc('DATEV Settings', filters.get('company'))
except frappe.DoesNotExistError: except frappe.DoesNotExistError:
frappe.throw(_('Please create <b>DATEV Settings</b> for Company <b>{}</b>.').format(filters.get('company'))) 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): def get_transactions(filters, as_dict=1):
""" """
Get a list of accounting entries. Get a list of accounting entries.
@ -317,9 +330,13 @@ def download_datev_csv(filters):
filters = json.loads(filters) filters = json.loads(filters)
validate(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 # 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 '') filters['skr'] = '04' if 'SKR04' in coa else ('03' if 'SKR03' in coa else '')
transactions = get_transactions(filters) transactions = get_transactions(filters)