style: format code with black

This commit is contained in:
Ankush Menat
2022-03-28 18:52:46 +05:30
parent 21e00da3d6
commit 494bd9ef78
1395 changed files with 91704 additions and 62532 deletions

View File

@@ -7,6 +7,7 @@ from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from frappe.permissions import add_permission, update_permission_property
from erpnext.payroll.doctype.gratuity_rule.gratuity_rule import get_gratuity_rule
def setup(company=None, patch=True):
make_custom_fields()
add_print_formats()
@@ -14,145 +15,270 @@ def setup(company=None, patch=True):
add_permissions()
create_gratuity_rule()
def make_custom_fields():
is_zero_rated = dict(fieldname='is_zero_rated', label='Is Zero Rated',
fieldtype='Check', fetch_from='item_code.is_zero_rated', insert_after='description',
print_hide=1)
is_exempt = dict(fieldname='is_exempt', label='Is Exempt',
fieldtype='Check', fetch_from='item_code.is_exempt', insert_after='is_zero_rated',
print_hide=1)
is_zero_rated = dict(
fieldname="is_zero_rated",
label="Is Zero Rated",
fieldtype="Check",
fetch_from="item_code.is_zero_rated",
insert_after="description",
print_hide=1,
)
is_exempt = dict(
fieldname="is_exempt",
label="Is Exempt",
fieldtype="Check",
fetch_from="item_code.is_exempt",
insert_after="is_zero_rated",
print_hide=1,
)
invoice_fields = [
dict(fieldname='vat_section', label='VAT Details', fieldtype='Section Break',
insert_after='group_same_items', print_hide=1, collapsible=1),
dict(fieldname='permit_no', label='Permit Number',
fieldtype='Data', insert_after='vat_section', print_hide=1),
dict(
fieldname="vat_section",
label="VAT Details",
fieldtype="Section Break",
insert_after="group_same_items",
print_hide=1,
collapsible=1,
),
dict(
fieldname="permit_no",
label="Permit Number",
fieldtype="Data",
insert_after="vat_section",
print_hide=1,
),
]
purchase_invoice_fields = [
dict(fieldname='company_trn', label='Company TRN',
fieldtype='Read Only', insert_after='shipping_address',
fetch_from='company.tax_id', print_hide=1),
dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic',
fieldtype='Read Only', insert_after='supplier_name',
fetch_from='supplier.supplier_name_in_arabic', print_hide=1),
dict(fieldname='recoverable_standard_rated_expenses', print_hide=1, default='0',
label='Recoverable Standard Rated Expenses (AED)', insert_after='permit_no',
fieldtype='Currency', ),
dict(fieldname='reverse_charge', label='Reverse Charge Applicable',
fieldtype='Select', insert_after='recoverable_standard_rated_expenses', print_hide=1,
options='Y\nN', default='N'),
dict(fieldname='recoverable_reverse_charge', label='Recoverable Reverse Charge (Percentage)',
insert_after='reverse_charge', fieldtype='Percent', print_hide=1,
depends_on="eval:doc.reverse_charge=='Y'", default='100.000'),
]
dict(
fieldname="company_trn",
label="Company TRN",
fieldtype="Read Only",
insert_after="shipping_address",
fetch_from="company.tax_id",
print_hide=1,
),
dict(
fieldname="supplier_name_in_arabic",
label="Supplier Name in Arabic",
fieldtype="Read Only",
insert_after="supplier_name",
fetch_from="supplier.supplier_name_in_arabic",
print_hide=1,
),
dict(
fieldname="recoverable_standard_rated_expenses",
print_hide=1,
default="0",
label="Recoverable Standard Rated Expenses (AED)",
insert_after="permit_no",
fieldtype="Currency",
),
dict(
fieldname="reverse_charge",
label="Reverse Charge Applicable",
fieldtype="Select",
insert_after="recoverable_standard_rated_expenses",
print_hide=1,
options="Y\nN",
default="N",
),
dict(
fieldname="recoverable_reverse_charge",
label="Recoverable Reverse Charge (Percentage)",
insert_after="reverse_charge",
fieldtype="Percent",
print_hide=1,
depends_on="eval:doc.reverse_charge=='Y'",
default="100.000",
),
]
sales_invoice_fields = [
dict(fieldname='company_trn', label='Company TRN',
fieldtype='Read Only', insert_after='company_address',
fetch_from='company.tax_id', print_hide=1),
dict(fieldname='customer_name_in_arabic', label='Customer Name in Arabic',
fieldtype='Read Only', insert_after='customer_name',
fetch_from='customer.customer_name_in_arabic', print_hide=1),
dict(fieldname='vat_emirate', label='VAT Emirate', insert_after='permit_no', fieldtype='Select',
options='\nAbu Dhabi\nAjman\nDubai\nFujairah\nRas Al Khaimah\nSharjah\nUmm Al Quwain',
fetch_from='company_address.emirate'),
dict(fieldname='tourist_tax_return', label='Tax Refund provided to Tourists (AED)',
insert_after='vat_emirate', fieldtype='Currency', print_hide=1, default='0'),
]
dict(
fieldname="company_trn",
label="Company TRN",
fieldtype="Read Only",
insert_after="company_address",
fetch_from="company.tax_id",
print_hide=1,
),
dict(
fieldname="customer_name_in_arabic",
label="Customer Name in Arabic",
fieldtype="Read Only",
insert_after="customer_name",
fetch_from="customer.customer_name_in_arabic",
print_hide=1,
),
dict(
fieldname="vat_emirate",
label="VAT Emirate",
insert_after="permit_no",
fieldtype="Select",
options="\nAbu Dhabi\nAjman\nDubai\nFujairah\nRas Al Khaimah\nSharjah\nUmm Al Quwain",
fetch_from="company_address.emirate",
),
dict(
fieldname="tourist_tax_return",
label="Tax Refund provided to Tourists (AED)",
insert_after="vat_emirate",
fieldtype="Currency",
print_hide=1,
default="0",
),
]
invoice_item_fields = [
dict(fieldname='tax_code', label='Tax Code',
fieldtype='Read Only', fetch_from='item_code.tax_code', insert_after='description',
allow_on_submit=1, print_hide=1),
dict(fieldname='tax_rate', label='Tax Rate',
fieldtype='Float', insert_after='tax_code',
print_hide=1, hidden=1, read_only=1),
dict(fieldname='tax_amount', label='Tax Amount',
fieldtype='Currency', insert_after='tax_rate',
print_hide=1, hidden=1, read_only=1, options="currency"),
dict(fieldname='total_amount', label='Total Amount',
fieldtype='Currency', insert_after='tax_amount',
print_hide=1, hidden=1, read_only=1, options="currency"),
dict(
fieldname="tax_code",
label="Tax Code",
fieldtype="Read Only",
fetch_from="item_code.tax_code",
insert_after="description",
allow_on_submit=1,
print_hide=1,
),
dict(
fieldname="tax_rate",
label="Tax Rate",
fieldtype="Float",
insert_after="tax_code",
print_hide=1,
hidden=1,
read_only=1,
),
dict(
fieldname="tax_amount",
label="Tax Amount",
fieldtype="Currency",
insert_after="tax_rate",
print_hide=1,
hidden=1,
read_only=1,
options="currency",
),
dict(
fieldname="total_amount",
label="Total Amount",
fieldtype="Currency",
insert_after="tax_amount",
print_hide=1,
hidden=1,
read_only=1,
options="currency",
),
]
delivery_date_field = [
dict(fieldname='delivery_date', label='Delivery Date',
fieldtype='Date', insert_after='item_name', print_hide=1)
dict(
fieldname="delivery_date",
label="Delivery Date",
fieldtype="Date",
insert_after="item_name",
print_hide=1,
)
]
custom_fields = {
'Item': [
dict(fieldname='tax_code', label='Tax Code',
fieldtype='Data', insert_after='item_group'),
dict(fieldname='is_zero_rated', label='Is Zero Rated',
fieldtype='Check', insert_after='tax_code',
print_hide=1),
dict(fieldname='is_exempt', label='Is Exempt',
fieldtype='Check', insert_after='is_zero_rated',
print_hide=1)
"Item": [
dict(fieldname="tax_code", label="Tax Code", fieldtype="Data", insert_after="item_group"),
dict(
fieldname="is_zero_rated",
label="Is Zero Rated",
fieldtype="Check",
insert_after="tax_code",
print_hide=1,
),
dict(
fieldname="is_exempt",
label="Is Exempt",
fieldtype="Check",
insert_after="is_zero_rated",
print_hide=1,
),
],
'Customer': [
dict(fieldname='customer_name_in_arabic', label='Customer Name in Arabic',
fieldtype='Data', insert_after='customer_name'),
"Customer": [
dict(
fieldname="customer_name_in_arabic",
label="Customer Name in Arabic",
fieldtype="Data",
insert_after="customer_name",
),
],
'Supplier': [
dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic',
fieldtype='Data', insert_after='supplier_name'),
"Supplier": [
dict(
fieldname="supplier_name_in_arabic",
label="Supplier Name in Arabic",
fieldtype="Data",
insert_after="supplier_name",
),
],
'Address': [
dict(fieldname='emirate', label='Emirate', fieldtype='Select', insert_after='state',
options='\nAbu Dhabi\nAjman\nDubai\nFujairah\nRas Al Khaimah\nSharjah\nUmm Al Quwain')
"Address": [
dict(
fieldname="emirate",
label="Emirate",
fieldtype="Select",
insert_after="state",
options="\nAbu Dhabi\nAjman\nDubai\nFujairah\nRas Al Khaimah\nSharjah\nUmm Al Quwain",
)
],
'Purchase Invoice': purchase_invoice_fields + invoice_fields,
'Purchase Order': purchase_invoice_fields + invoice_fields,
'Purchase Receipt': purchase_invoice_fields + invoice_fields,
'Sales Invoice': sales_invoice_fields + invoice_fields,
'POS Invoice': sales_invoice_fields + invoice_fields,
'Sales Order': sales_invoice_fields + invoice_fields,
'Delivery Note': sales_invoice_fields + invoice_fields,
'Sales Invoice Item': invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt],
'POS Invoice Item': invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt],
'Purchase Invoice Item': invoice_item_fields,
'Sales Order Item': invoice_item_fields,
'Delivery Note Item': invoice_item_fields,
'Quotation Item': invoice_item_fields,
'Purchase Order Item': invoice_item_fields,
'Purchase Receipt Item': invoice_item_fields,
'Supplier Quotation Item': invoice_item_fields,
"Purchase Invoice": purchase_invoice_fields + invoice_fields,
"Purchase Order": purchase_invoice_fields + invoice_fields,
"Purchase Receipt": purchase_invoice_fields + invoice_fields,
"Sales Invoice": sales_invoice_fields + invoice_fields,
"POS Invoice": sales_invoice_fields + invoice_fields,
"Sales Order": sales_invoice_fields + invoice_fields,
"Delivery Note": sales_invoice_fields + invoice_fields,
"Sales Invoice Item": invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt],
"POS Invoice Item": invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt],
"Purchase Invoice Item": invoice_item_fields,
"Sales Order Item": invoice_item_fields,
"Delivery Note Item": invoice_item_fields,
"Quotation Item": invoice_item_fields,
"Purchase Order Item": invoice_item_fields,
"Purchase Receipt Item": invoice_item_fields,
"Supplier Quotation Item": invoice_item_fields,
}
create_custom_fields(custom_fields)
def add_print_formats():
frappe.reload_doc("regional", "print_format", "detailed_tax_invoice")
frappe.reload_doc("regional", "print_format", "simplified_tax_invoice")
frappe.reload_doc("regional", "print_format", "tax_invoice")
frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
name in('Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice') """)
frappe.db.sql(
""" update `tabPrint Format` set disabled = 0 where
name in('Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice') """
)
def add_custom_roles_for_reports():
"""Add Access Control to UAE VAT 201."""
if not frappe.db.get_value('Custom Role', dict(report='UAE VAT 201')):
frappe.get_doc(dict(
doctype='Custom Role',
report='UAE VAT 201',
roles= [
dict(role='Accounts User'),
dict(role='Accounts Manager'),
dict(role='Auditor')
]
)).insert()
if not frappe.db.get_value("Custom Role", dict(report="UAE VAT 201")):
frappe.get_doc(
dict(
doctype="Custom Role",
report="UAE VAT 201",
roles=[dict(role="Accounts User"), dict(role="Accounts Manager"), dict(role="Auditor")],
)
).insert()
def add_permissions():
"""Add Permissions for UAE VAT Settings and UAE VAT Account."""
for doctype in ('UAE VAT Settings', 'UAE VAT Account'):
add_permission(doctype, 'All', 0)
for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
for doctype in ("UAE VAT Settings", "UAE VAT Account"):
add_permission(doctype, "All", 0)
for role in ("Accounts Manager", "Accounts User", "System Manager"):
add_permission(doctype, role, 0)
update_permission_property(doctype, role, 0, 'write', 1)
update_permission_property(doctype, role, 0, 'create', 1)
update_permission_property(doctype, role, 0, "write", 1)
update_permission_property(doctype, role, 0, "create", 1)
def create_gratuity_rule():
rule_1 = rule_2 = rule_3 = None
@@ -160,7 +286,11 @@ def create_gratuity_rule():
# Rule Under Limited Contract
slabs = get_slab_for_limited_contract()
if not frappe.db.exists("Gratuity Rule", "Rule Under Limited Contract (UAE)"):
rule_1 = get_gratuity_rule("Rule Under Limited Contract (UAE)", slabs, calculate_gratuity_amount_based_on="Sum of all previous slabs")
rule_1 = get_gratuity_rule(
"Rule Under Limited Contract (UAE)",
slabs,
calculate_gratuity_amount_based_on="Sum of all previous slabs",
)
# Rule Under Unlimited Contract on termination
slabs = get_slab_for_unlimited_contract_on_termination()
@@ -172,7 +302,7 @@ def create_gratuity_rule():
if not frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on resignation (UAE)"):
rule_3 = get_gratuity_rule("Rule Under Unlimited Contract on resignation (UAE)", slabs)
#for applicable salary component user need to set this by its own
# for applicable salary component user need to set this by its own
if rule_1:
rule_1.flags.ignore_mandatory = True
rule_1.save()
@@ -185,61 +315,29 @@ def create_gratuity_rule():
def get_slab_for_limited_contract():
return [{
"from_year": 0,
"to_year":1,
"fraction_of_applicable_earnings": 0
},
{
"from_year": 1,
"to_year":5,
"fraction_of_applicable_earnings": 21/30
},
{
"from_year": 5,
"to_year":0,
"fraction_of_applicable_earnings": 1
}]
return [
{"from_year": 0, "to_year": 1, "fraction_of_applicable_earnings": 0},
{"from_year": 1, "to_year": 5, "fraction_of_applicable_earnings": 21 / 30},
{"from_year": 5, "to_year": 0, "fraction_of_applicable_earnings": 1},
]
def get_slab_for_unlimited_contract_on_termination():
return [{
"from_year": 0,
"to_year":1,
"fraction_of_applicable_earnings": 0
},
{
"from_year": 1,
"to_year":5,
"fraction_of_applicable_earnings": 21/30
},
{
"from_year": 5,
"to_year":0,
"fraction_of_applicable_earnings": 1
}]
return [
{"from_year": 0, "to_year": 1, "fraction_of_applicable_earnings": 0},
{"from_year": 1, "to_year": 5, "fraction_of_applicable_earnings": 21 / 30},
{"from_year": 5, "to_year": 0, "fraction_of_applicable_earnings": 1},
]
def get_slab_for_unlimited_contract_on_resignation():
fraction_1 = 1/3 * 21/30
fraction_2 = 2/3 * 21/30
fraction_3 = 21/30
fraction_1 = 1 / 3 * 21 / 30
fraction_2 = 2 / 3 * 21 / 30
fraction_3 = 21 / 30
return [{
"from_year": 0,
"to_year":1,
"fraction_of_applicable_earnings": 0
},
{
"from_year": 1,
"to_year":3,
"fraction_of_applicable_earnings": fraction_1
},
{
"from_year": 3,
"to_year":5,
"fraction_of_applicable_earnings": fraction_2
},
{
"from_year": 5,
"to_year":0,
"fraction_of_applicable_earnings": fraction_3
}]
return [
{"from_year": 0, "to_year": 1, "fraction_of_applicable_earnings": 0},
{"from_year": 1, "to_year": 3, "fraction_of_applicable_earnings": fraction_1},
{"from_year": 3, "to_year": 5, "fraction_of_applicable_earnings": fraction_2},
{"from_year": 5, "to_year": 0, "fraction_of_applicable_earnings": fraction_3},
]

View File

@@ -7,7 +7,8 @@ from erpnext.controllers.taxes_and_totals import get_itemised_tax
def update_itemised_tax_data(doc):
if not doc.taxes: return
if not doc.taxes:
return
itemised_tax = get_itemised_tax(doc.taxes)
@@ -24,40 +25,39 @@ def update_itemised_tax_data(doc):
for account, rate in item_tax_rate.items():
tax_rate += rate
elif row.item_code and itemised_tax.get(row.item_code):
tax_rate = sum([tax.get('tax_rate', 0) for d, tax in itemised_tax.get(row.item_code).items()])
tax_rate = sum([tax.get("tax_rate", 0) for d, tax in itemised_tax.get(row.item_code).items()])
meta = frappe.get_meta(row.doctype)
if meta.has_field('tax_rate'):
if meta.has_field("tax_rate"):
row.tax_rate = flt(tax_rate, row.precision("tax_rate"))
row.tax_amount = flt((row.net_amount * tax_rate) / 100, row.precision("net_amount"))
row.total_amount = flt((row.net_amount + row.tax_amount), row.precision("total_amount"))
def get_account_currency(account):
"""Helper function to get account currency."""
if not account:
return
def generator():
account_currency, company = frappe.get_cached_value(
"Account",
account,
["account_currency",
"company"]
"Account", account, ["account_currency", "company"]
)
if not account_currency:
account_currency = frappe.get_cached_value('Company', company, "default_currency")
account_currency = frappe.get_cached_value("Company", company, "default_currency")
return account_currency
return frappe.local_cache("account_currency", account, generator)
def get_tax_accounts(company):
"""Get the list of tax accounts for a specific company."""
tax_accounts_dict = frappe._dict()
tax_accounts_list = frappe.get_all("UAE VAT Account",
filters={"parent": company},
fields=["Account"]
)
tax_accounts_list = frappe.get_all(
"UAE VAT Account", filters={"parent": company}, fields=["Account"]
)
if not tax_accounts_list and not frappe.flags.in_test:
frappe.throw(_('Please set Vat Accounts for Company: "{0}" in UAE VAT Settings').format(company))
@@ -67,23 +67,24 @@ def get_tax_accounts(company):
return tax_accounts_dict
def update_grand_total_for_rcm(doc, method):
"""If the Reverse Charge is Applicable subtract the tax amount from the grand total and update in the form."""
country = frappe.get_cached_value('Company', doc.company, 'country')
country = frappe.get_cached_value("Company", doc.company, "country")
if country != 'United Arab Emirates':
if country != "United Arab Emirates":
return
if not doc.total_taxes_and_charges:
return
if doc.reverse_charge == 'Y':
if doc.reverse_charge == "Y":
tax_accounts = get_tax_accounts(doc.company)
base_vat_tax = 0
vat_tax = 0
for tax in doc.get('taxes'):
for tax in doc.get("taxes"):
if tax.category not in ("Total", "Valuation and Total"):
continue
@@ -98,6 +99,7 @@ def update_grand_total_for_rcm(doc, method):
update_totals(vat_tax, base_vat_tax, doc)
def update_totals(vat_tax, base_vat_tax, doc):
"""Update the grand total values in the form."""
doc.base_grand_total -= base_vat_tax
@@ -109,56 +111,67 @@ def update_totals(vat_tax, base_vat_tax, doc):
doc.outstanding_amount = doc.grand_total
else:
doc.rounded_total = round_based_on_smallest_currency_fraction(doc.grand_total,
doc.currency, doc.precision("rounded_total"))
doc.rounding_adjustment = flt(doc.rounded_total - doc.grand_total,
doc.precision("rounding_adjustment"))
doc.rounded_total = round_based_on_smallest_currency_fraction(
doc.grand_total, doc.currency, doc.precision("rounded_total")
)
doc.rounding_adjustment = flt(
doc.rounded_total - doc.grand_total, doc.precision("rounding_adjustment")
)
doc.outstanding_amount = doc.rounded_total or doc.grand_total
doc.in_words = money_in_words(doc.grand_total, doc.currency)
doc.base_in_words = money_in_words(doc.base_grand_total, erpnext.get_company_currency(doc.company))
doc.base_in_words = money_in_words(
doc.base_grand_total, erpnext.get_company_currency(doc.company)
)
doc.set_payment_schedule()
def make_regional_gl_entries(gl_entries, doc):
"""Hooked to make_regional_gl_entries in Purchase Invoice.It appends the region specific general ledger entries to the list of GL Entries."""
country = frappe.get_cached_value('Company', doc.company, 'country')
country = frappe.get_cached_value("Company", doc.company, "country")
if country != 'United Arab Emirates':
if country != "United Arab Emirates":
return gl_entries
if doc.reverse_charge == 'Y':
if doc.reverse_charge == "Y":
tax_accounts = get_tax_accounts(doc.company)
for tax in doc.get('taxes'):
for tax in doc.get("taxes"):
if tax.category not in ("Total", "Valuation and Total"):
continue
gl_entries = make_gl_entry(tax, gl_entries, doc, tax_accounts)
return gl_entries
def make_gl_entry(tax, gl_entries, doc, tax_accounts):
dr_or_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in tax_accounts:
if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in tax_accounts:
account_currency = get_account_currency(tax.account_head)
gl_entries.append(doc.get_gl_dict({
"account": tax.account_head,
"cost_center": tax.cost_center,
"posting_date": doc.posting_date,
"against": doc.supplier,
dr_or_cr: tax.base_tax_amount_after_discount_amount,
dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount \
if account_currency==doc.company_currency \
else tax.tax_amount_after_discount_amount
}, account_currency, item=tax
))
gl_entries.append(
doc.get_gl_dict(
{
"account": tax.account_head,
"cost_center": tax.cost_center,
"posting_date": doc.posting_date,
"against": doc.supplier,
dr_or_cr: tax.base_tax_amount_after_discount_amount,
dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount
if account_currency == doc.company_currency
else tax.tax_amount_after_discount_amount,
},
account_currency,
item=tax,
)
)
return gl_entries
def validate_returns(doc, method):
"""Standard Rated expenses should not be set when Reverse Charge Applicable is set."""
country = frappe.get_cached_value('Company', doc.company, 'country')
if country != 'United Arab Emirates':
country = frappe.get_cached_value("Company", doc.company, "country")
if country != "United Arab Emirates":
return
if doc.reverse_charge == 'Y' and flt(doc.recoverable_standard_rated_expenses) != 0:
frappe.throw(_(
"Recoverable Standard Rated expenses should not be set when Reverse Charge Applicable is Y"
))
if doc.reverse_charge == "Y" and flt(doc.recoverable_standard_rated_expenses) != 0:
frappe.throw(
_("Recoverable Standard Rated expenses should not be set when Reverse Charge Applicable is Y")
)