Merge pull request #31337 from gavindsouza/get_fiscal_years-refactor
refactor: get_fiscal_years API
This commit is contained in:
commit
697fbe946a
1
.github/workflows/patch.yml
vendored
1
.github/workflows/patch.yml
vendored
@ -115,4 +115,5 @@ jobs:
|
|||||||
echo "Updating to latest version"
|
echo "Updating to latest version"
|
||||||
git -C "apps/frappe" checkout -q -f "${GITHUB_BASE_REF:-${GITHUB_REF##*/}}"
|
git -C "apps/frappe" checkout -q -f "${GITHUB_BASE_REF:-${GITHUB_REF##*/}}"
|
||||||
git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA"
|
git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA"
|
||||||
|
bench setup requirements --python
|
||||||
bench --site test_site migrate
|
bench --site test_site migrate
|
||||||
|
@ -9,7 +9,10 @@ import frappe
|
|||||||
import frappe.defaults
|
import frappe.defaults
|
||||||
from frappe import _, qb, throw
|
from frappe import _, qb, throw
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
|
from frappe.query_builder.utils import DocType
|
||||||
from frappe.utils import cint, cstr, flt, formatdate, get_number_format_info, getdate, now, nowdate
|
from frappe.utils import cint, cstr, flt, formatdate, get_number_format_info, getdate, now, nowdate
|
||||||
|
from pypika import Order
|
||||||
|
from pypika.terms import ExistsCriterion
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
|
|
||||||
@ -42,37 +45,32 @@ def get_fiscal_years(
|
|||||||
|
|
||||||
if not fiscal_years:
|
if not fiscal_years:
|
||||||
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
|
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
|
||||||
cond = ""
|
FY = DocType("Fiscal Year")
|
||||||
if fiscal_year:
|
|
||||||
cond += " and fy.name = {0}".format(frappe.db.escape(fiscal_year))
|
|
||||||
if company:
|
|
||||||
cond += """
|
|
||||||
and (not exists (select name
|
|
||||||
from `tabFiscal Year Company` fyc
|
|
||||||
where fyc.parent = fy.name)
|
|
||||||
or exists(select company
|
|
||||||
from `tabFiscal Year Company` fyc
|
|
||||||
where fyc.parent = fy.name
|
|
||||||
and fyc.company=%(company)s)
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
fiscal_years = frappe.db.sql(
|
query = (
|
||||||
"""
|
frappe.qb.from_(FY)
|
||||||
select
|
.select(FY.name, FY.year_start_date, FY.year_end_date)
|
||||||
fy.name, fy.year_start_date, fy.year_end_date
|
.where(FY.disabled == 0)
|
||||||
from
|
|
||||||
`tabFiscal Year` fy
|
|
||||||
where
|
|
||||||
disabled = 0 {0}
|
|
||||||
order by
|
|
||||||
fy.year_start_date desc""".format(
|
|
||||||
cond
|
|
||||||
),
|
|
||||||
{"company": company},
|
|
||||||
as_dict=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if fiscal_year:
|
||||||
|
query = query.where(FY.name == fiscal_year)
|
||||||
|
|
||||||
|
if company:
|
||||||
|
FYC = DocType("Fiscal Year Company")
|
||||||
|
query = query.where(
|
||||||
|
ExistsCriterion(frappe.qb.from_(FYC).select(FYC.name).where(FYC.parent == FY.name)).negate()
|
||||||
|
| ExistsCriterion(
|
||||||
|
frappe.qb.from_(FYC)
|
||||||
|
.select(FYC.company)
|
||||||
|
.where(FYC.parent == FY.name)
|
||||||
|
.where(FYC.company == company)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
query = query.orderby(FY.year_start_date, Order.desc)
|
||||||
|
fiscal_years = query.run(as_dict=True)
|
||||||
|
|
||||||
frappe.cache().hset("fiscal_years", company, fiscal_years)
|
frappe.cache().hset("fiscal_years", company, fiscal_years)
|
||||||
|
|
||||||
if not transaction_date and not fiscal_year:
|
if not transaction_date and not fiscal_year:
|
||||||
|
@ -10,7 +10,7 @@ from frappe.utils.data import fmt_money
|
|||||||
from frappe.utils.jinja import render_template
|
from frappe.utils.jinja import render_template
|
||||||
from frappe.utils.pdf import get_pdf
|
from frappe.utils.pdf import get_pdf
|
||||||
from frappe.utils.print_format import read_multi_pdf
|
from frappe.utils.print_format import read_multi_pdf
|
||||||
from PyPDF2 import PdfFileWriter
|
from PyPDF2 import PdfWriter
|
||||||
|
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ def irs_1099_print(filters):
|
|||||||
|
|
||||||
columns, data = execute(filters)
|
columns, data = execute(filters)
|
||||||
template = frappe.get_doc("Print Format", "IRS 1099 Form").html
|
template = frappe.get_doc("Print Format", "IRS 1099 Form").html
|
||||||
output = PdfFileWriter()
|
output = PdfWriter()
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
row["fiscal_year"] = fiscal_year
|
row["fiscal_year"] = fiscal_year
|
||||||
|
@ -59,7 +59,6 @@ class TestExotel(FrappeAPITestCase):
|
|||||||
f"/api/method/erpnext.erpnext_integrations.exotel_integration.{api_method}",
|
f"/api/method/erpnext.erpnext_integrations.exotel_integration.{api_method}",
|
||||||
data=frappe.as_json(data),
|
data=frappe.as_json(data),
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
as_tuple=True,
|
|
||||||
)
|
)
|
||||||
# restart db connection to get latest data
|
# restart db connection to get latest data
|
||||||
frappe.connect()
|
frappe.connect()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user