2017-12-12 09:10:52 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
2020-09-28 09:08:45 +00:00
|
|
|
from frappe.permissions import add_permission, update_permission_property
|
2017-12-12 09:10:52 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2017-12-12 09:10:52 +00:00
|
|
|
def setup(company=None, patch=True):
|
|
|
|
make_custom_fields()
|
|
|
|
add_print_formats()
|
2020-09-25 08:54:57 +00:00
|
|
|
add_custom_roles_for_reports()
|
2020-09-28 09:08:45 +00:00
|
|
|
add_permissions()
|
2017-12-12 09:10:52 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2017-12-12 09:10:52 +00:00
|
|
|
def make_custom_fields():
|
2020-09-25 07:43:38 +00:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2017-12-12 09:10:52 +00:00
|
|
|
invoice_fields = [
|
|
|
|
dict(
|
|
|
|
fieldname="vat_section",
|
|
|
|
label="VAT Details",
|
|
|
|
fieldtype="Section Break",
|
2022-09-28 13:26:29 +00:00
|
|
|
insert_after="language",
|
2018-07-03 04:58:20 +00:00
|
|
|
print_hide=1,
|
|
|
|
collapsible=1,
|
|
|
|
),
|
2017-12-12 09:10:52 +00:00
|
|
|
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",
|
2019-03-08 13:07:34 +00:00
|
|
|
fetch_from="company.tax_id",
|
|
|
|
print_hide=1,
|
|
|
|
),
|
2017-12-12 09:10:52 +00:00
|
|
|
dict(
|
|
|
|
fieldname="supplier_name_in_arabic",
|
|
|
|
label="Supplier Name in Arabic",
|
|
|
|
fieldtype="Read Only",
|
|
|
|
insert_after="supplier_name",
|
2020-09-24 07:51:23 +00:00
|
|
|
fetch_from="supplier.supplier_name_in_arabic",
|
2020-11-16 12:06:27 +00:00
|
|
|
print_hide=1,
|
|
|
|
),
|
|
|
|
dict(
|
|
|
|
fieldname="recoverable_standard_rated_expenses",
|
2017-12-28 08:50:13 +00:00
|
|
|
print_hide=1,
|
2020-11-16 12:06:27 +00:00
|
|
|
default="0",
|
|
|
|
label="Recoverable Standard Rated Expenses (AED)",
|
|
|
|
insert_after="permit_no",
|
|
|
|
fieldtype="Currency",
|
|
|
|
),
|
2020-09-24 07:51:23 +00:00
|
|
|
dict(
|
|
|
|
fieldname="reverse_charge",
|
|
|
|
label="Reverse Charge Applicable",
|
2020-10-19 12:28:50 +00:00
|
|
|
fieldtype="Select",
|
|
|
|
insert_after="recoverable_standard_rated_expenses",
|
|
|
|
print_hide=1,
|
2020-09-24 07:51:23 +00:00
|
|
|
options="Y\nN",
|
|
|
|
default="N",
|
|
|
|
),
|
2020-10-19 12:28:50 +00:00
|
|
|
dict(
|
|
|
|
fieldname="recoverable_reverse_charge",
|
|
|
|
label="Recoverable Reverse Charge (Percentage)",
|
2020-09-24 13:11:43 +00:00
|
|
|
insert_after="reverse_charge",
|
|
|
|
fieldtype="Percent",
|
|
|
|
print_hide=1,
|
|
|
|
depends_on="eval:doc.reverse_charge=='Y'",
|
|
|
|
default="100.000",
|
|
|
|
),
|
2017-12-12 09:10:52 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
sales_invoice_fields = [
|
|
|
|
dict(
|
|
|
|
fieldname="company_trn",
|
|
|
|
label="Company TRN",
|
|
|
|
fieldtype="Read Only",
|
|
|
|
insert_after="company_address",
|
2019-03-08 13:07:34 +00:00
|
|
|
fetch_from="company.tax_id",
|
|
|
|
print_hide=1,
|
|
|
|
),
|
2017-12-12 09:10:52 +00:00
|
|
|
dict(
|
|
|
|
fieldname="customer_name_in_arabic",
|
|
|
|
label="Customer Name in Arabic",
|
|
|
|
fieldtype="Read Only",
|
|
|
|
insert_after="customer_name",
|
2019-03-08 13:07:34 +00:00
|
|
|
fetch_from="customer.customer_name_in_arabic",
|
|
|
|
print_hide=1,
|
|
|
|
),
|
2020-10-28 04:58:25 +00:00
|
|
|
dict(
|
|
|
|
fieldname="vat_emirate",
|
|
|
|
label="VAT Emirate",
|
|
|
|
insert_after="permit_no",
|
|
|
|
fieldtype="Select",
|
2020-11-16 07:28:38 +00:00
|
|
|
options="\nAbu Dhabi\nAjman\nDubai\nFujairah\nRas Al Khaimah\nSharjah\nUmm Al Quwain",
|
|
|
|
fetch_from="company_address.emirate",
|
|
|
|
),
|
2020-09-24 07:51:23 +00:00
|
|
|
dict(
|
|
|
|
fieldname="tourist_tax_return",
|
|
|
|
label="Tax Refund provided to Tourists (AED)",
|
2020-10-28 04:58:25 +00:00
|
|
|
insert_after="vat_emirate",
|
|
|
|
fieldtype="Currency",
|
|
|
|
print_hide=1,
|
|
|
|
default="0",
|
|
|
|
),
|
2017-12-12 09:10:52 +00:00
|
|
|
]
|
|
|
|
|
2017-12-28 08:50:13 +00:00
|
|
|
invoice_item_fields = [
|
|
|
|
dict(
|
|
|
|
fieldname="tax_code",
|
|
|
|
label="Tax Code",
|
2019-03-08 13:07:34 +00:00
|
|
|
fieldtype="Read Only",
|
|
|
|
fetch_from="item_code.tax_code",
|
|
|
|
insert_after="description",
|
2017-12-28 08:50:13 +00:00
|
|
|
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",
|
|
|
|
),
|
2017-12-28 13:12:22 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
delivery_date_field = [
|
2017-12-28 08:50:13 +00:00
|
|
|
dict(
|
|
|
|
fieldname="delivery_date",
|
|
|
|
label="Delivery Date",
|
2017-12-28 13:12:22 +00:00
|
|
|
fieldtype="Date",
|
|
|
|
insert_after="item_name",
|
|
|
|
print_hide=1,
|
|
|
|
)
|
2017-12-28 08:50:13 +00:00
|
|
|
]
|
2017-12-12 09:10:52 +00:00
|
|
|
|
|
|
|
custom_fields = {
|
|
|
|
"Item": [
|
|
|
|
dict(fieldname="tax_code", label="Tax Code", fieldtype="Data", insert_after="item_group"),
|
2020-09-25 07:43:38 +00:00
|
|
|
dict(
|
|
|
|
fieldname="is_zero_rated",
|
|
|
|
label="Is Zero Rated",
|
|
|
|
fieldtype="Check",
|
|
|
|
insert_after="tax_code",
|
|
|
|
print_hide=1,
|
|
|
|
),
|
2020-10-20 11:05:28 +00:00
|
|
|
dict(
|
|
|
|
fieldname="is_exempt",
|
|
|
|
label="Is Exempt",
|
2020-09-25 07:43:38 +00:00
|
|
|
fieldtype="Check",
|
|
|
|
insert_after="is_zero_rated",
|
|
|
|
print_hide=1,
|
2022-03-28 13:22:46 +00:00
|
|
|
),
|
2017-12-12 09:10:52 +00:00
|
|
|
],
|
|
|
|
"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",
|
|
|
|
),
|
|
|
|
],
|
2020-11-16 07:28:38 +00:00
|
|
|
"Address": [
|
|
|
|
dict(
|
|
|
|
fieldname="emirate",
|
|
|
|
label="Emirate",
|
|
|
|
fieldtype="Select",
|
|
|
|
insert_after="state",
|
2020-11-16 12:06:27 +00:00
|
|
|
options="\nAbu Dhabi\nAjman\nDubai\nFujairah\nRas Al Khaimah\nSharjah\nUmm Al Quwain",
|
|
|
|
)
|
2020-11-16 07:28:38 +00:00
|
|
|
],
|
2017-12-12 09:10:52 +00:00
|
|
|
"Purchase Invoice": purchase_invoice_fields + invoice_fields,
|
2017-12-28 13:12:22 +00:00
|
|
|
"Purchase Order": purchase_invoice_fields + invoice_fields,
|
|
|
|
"Purchase Receipt": purchase_invoice_fields + invoice_fields,
|
2017-12-12 09:10:52 +00:00
|
|
|
"Sales Invoice": sales_invoice_fields + invoice_fields,
|
2021-01-28 12:28:55 +00:00
|
|
|
"POS Invoice": sales_invoice_fields + invoice_fields,
|
2017-12-28 13:12:22 +00:00
|
|
|
"Sales Order": sales_invoice_fields + invoice_fields,
|
|
|
|
"Delivery Note": sales_invoice_fields + invoice_fields,
|
2020-09-25 07:43:38 +00:00
|
|
|
"Sales Invoice Item": invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt],
|
2021-01-28 12:28:55 +00:00
|
|
|
"POS Invoice Item": invoice_item_fields + delivery_date_field + [is_zero_rated, is_exempt],
|
2017-12-28 13:12:22 +00:00
|
|
|
"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,
|
2017-12-12 09:10:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 14:45:15 +00:00
|
|
|
create_custom_fields(custom_fields, ignore_validate=True)
|
2017-12-12 09:10:52 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2017-12-12 09:10:52 +00:00
|
|
|
def add_print_formats():
|
|
|
|
frappe.reload_doc("regional", "print_format", "detailed_tax_invoice")
|
|
|
|
frappe.reload_doc("regional", "print_format", "simplified_tax_invoice")
|
2017-12-28 08:50:13 +00:00
|
|
|
frappe.reload_doc("regional", "print_format", "tax_invoice")
|
2017-12-16 05:23:53 +00:00
|
|
|
|
|
|
|
frappe.db.sql(
|
|
|
|
""" update `tabPrint Format` set disabled = 0 where
|
2017-12-28 08:50:13 +00:00
|
|
|
name in('Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice') """
|
|
|
|
)
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-09-25 08:54:57 +00:00
|
|
|
|
|
|
|
def add_custom_roles_for_reports():
|
2020-10-14 06:51:36 +00:00
|
|
|
"""Add Access Control to UAE VAT 201."""
|
|
|
|
if not frappe.db.get_value("Custom Role", dict(report="UAE VAT 201")):
|
2020-09-25 08:54:57 +00:00
|
|
|
frappe.get_doc(
|
|
|
|
dict(
|
|
|
|
doctype="Custom Role",
|
2020-10-14 06:51:36 +00:00
|
|
|
report="UAE VAT 201",
|
2020-09-25 08:54:57 +00:00
|
|
|
roles=[dict(role="Accounts User"), dict(role="Accounts Manager"), dict(role="Auditor")],
|
|
|
|
)
|
2020-09-28 09:08:45 +00:00
|
|
|
).insert()
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-09-28 09:08:45 +00:00
|
|
|
|
|
|
|
def add_permissions():
|
2020-09-30 06:45:07 +00:00
|
|
|
"""Add Permissions for UAE VAT Settings and UAE VAT Account."""
|
2020-09-30 16:21:00 +00:00
|
|
|
for doctype in ("UAE VAT Settings", "UAE VAT Account"):
|
2020-09-28 09:08:45 +00:00
|
|
|
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)
|