blob: d2ef6f3f178f2210cde615ac7953938d9b0d0691 [file] [log] [blame]
rohitwaghchaure4e17fae2017-12-12 14:40:52 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
Ahmadcb0c2d12021-08-26 07:35:59 +05004import frappe
5from frappe.permissions import add_permission, update_permission_property
Ahmadcb0c2d12021-08-26 07:35:59 +05006from erpnext.regional.saudi_arabia.wizard.operations.setup_ksa_vat_setting import create_ksa_vat_setting
Deepesh Gargc81d4732021-11-08 17:14:03 +05307from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
rohitwaghchaure4e17fae2017-12-12 14:40:52 +05308
9def setup(company=None, patch=True):
rohitwaghchaure4e17fae2017-12-12 14:40:52 +053010 add_print_formats()
Ahmadcb0c2d12021-08-26 07:35:59 +050011 add_permissions()
ahmadpak2a5beec2021-10-30 17:18:45 +030012 make_custom_fields()
Ahmadcb0c2d12021-08-26 07:35:59 +050013
Dany Robertbb3119c2021-12-07 11:05:41 +000014def add_print_formats():
Dany Roberta0aeace2021-12-07 12:39:39 +000015 frappe.reload_doc("regional", "print_format", "detailed_tax_invoice", force=True)
16 frappe.reload_doc("regional", "print_format", "simplified_tax_invoice", force=True)
17 frappe.reload_doc("regional", "print_format", "tax_invoice", force=True)
18 frappe.reload_doc("regional", "print_format", "ksa_vat_invoice", force=True)
19 frappe.reload_doc("regional", "print_format", "ksa_pos_invoice", force=True)
Dany Robertbb3119c2021-12-07 11:05:41 +000020
Dany Robertca850942021-12-08 07:52:06 +053021 for d in ('Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice', 'KSA VAT Invoice', 'KSA POS Invoice'):
22 frappe.db.set_value("Print Format", d, "disabled", 0)
Dany Robertbb3119c2021-12-07 11:05:41 +000023
Ahmadcb0c2d12021-08-26 07:35:59 +050024def add_permissions():
25 """Add Permissions for KSA VAT Setting."""
26 add_permission('KSA VAT Setting', 'All', 0)
27 for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
28 add_permission('KSA VAT Setting', role, 0)
29 update_permission_property('KSA VAT Setting', role, 0, 'write', 1)
30 update_permission_property('KSA VAT Setting', role, 0, 'create', 1)
31
32 """Enable KSA VAT Report"""
33 frappe.db.set_value('Report', 'KSA VAT', 'disabled', 0)
Ahmad87380d02021-09-06 23:36:55 +050034
ahmadpak2a5beec2021-10-30 17:18:45 +030035def make_custom_fields():
36 """Create Custom fields
37 - QR code Image file
38 - Company Name in Arabic
39 - Address in Arabic
40 """
Dany Robert00b2ded2022-01-06 18:42:56 +053041 is_zero_rated = dict(fieldname='is_zero_rated', label='Is Zero Rated',
42 fieldtype='Check', fetch_from='item_code.is_zero_rated', insert_after='description',
43 print_hide=1)
Dany Robert63a4c1d2022-01-06 18:48:02 +053044
Dany Robert00b2ded2022-01-06 18:42:56 +053045 is_exempt = dict(fieldname='is_exempt', label='Is Exempt',
46 fieldtype='Check', fetch_from='item_code.is_exempt', insert_after='is_zero_rated',
47 print_hide=1)
48
49 purchase_invoice_fields = [
50 dict(fieldname='company_trn', label='Company TRN',
51 fieldtype='Read Only', insert_after='shipping_address',
52 fetch_from='company.tax_id', print_hide=1),
53 dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic',
54 fieldtype='Read Only', insert_after='supplier_name',
55 fetch_from='supplier.supplier_name_in_arabic', print_hide=1)
56 ]
57
58 sales_invoice_fields = [
59 dict(fieldname='company_trn', label='Company TRN',
60 fieldtype='Read Only', insert_after='company_address',
61 fetch_from='company.tax_id', print_hide=1),
62 dict(fieldname='customer_name_in_arabic', label='Customer Name in Arabic',
63 fieldtype='Read Only', insert_after='customer_name',
64 fetch_from='customer.customer_name_in_arabic', print_hide=1),
65 dict(fieldname='ksa_einv_qr', label='KSA E-Invoicing QR',
66 fieldtype='Attach Image', read_only=1, no_copy=1, hidden=1)
67 ]
68
Deepesh Gargc81d4732021-11-08 17:14:03 +053069 custom_fields = {
Dany Robert00b2ded2022-01-06 18:42:56 +053070 'Item': [is_zero_rated, is_exempt],
71 'Customer': [
72 dict(fieldname='customer_name_in_arabic', label='Customer Name in Arabic',
73 fieldtype='Data', insert_after='customer_name'),
Deepesh Gargc81d4732021-11-08 17:14:03 +053074 ],
Dany Robert00b2ded2022-01-06 18:42:56 +053075 'Supplier': [
76 dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic',
77 fieldtype='Data', insert_after='supplier_name'),
Dany Robertd06c4b52021-12-07 12:29:59 +053078 ],
Dany Robert00b2ded2022-01-06 18:42:56 +053079 'Purchase Invoice': purchase_invoice_fields,
80 'Purchase Order': purchase_invoice_fields,
81 'Purchase Receipt': purchase_invoice_fields,
82 'Sales Invoice': sales_invoice_fields,
83 'POS Invoice': sales_invoice_fields,
84 'Sales Order': sales_invoice_fields,
85 'Delivery Note': sales_invoice_fields,
86 'Sales Invoice Item': [is_zero_rated, is_exempt],
87 'POS Invoice Item': [is_zero_rated, is_exempt],
88 'Purchase Invoice Item': [is_zero_rated, is_exempt],
89 'Sales Order Item': [is_zero_rated, is_exempt],
90 'Delivery Note Item': [is_zero_rated, is_exempt],
91 'Quotation Item': [is_zero_rated, is_exempt],
92 'Purchase Order Item': [is_zero_rated, is_exempt],
93 'Purchase Receipt Item': [is_zero_rated, is_exempt],
94 'Supplier Quotation Item': [is_zero_rated, is_exempt],
Deepesh Gargc81d4732021-11-08 17:14:03 +053095 'Address': [
Dany Robert00b2ded2022-01-06 18:42:56 +053096 dict(fieldname='address_in_arabic', label='Address in Arabic',
97 fieldtype='Data',insert_after='address_line2')
Deepesh Gargc81d4732021-11-08 17:14:03 +053098 ],
99 'Company': [
Dany Robert00b2ded2022-01-06 18:42:56 +0530100 dict(fieldname='company_name_in_arabic', label='Company Name In Arabic',
101 fieldtype='Data', insert_after='company_name')
Deepesh Gargc81d4732021-11-08 17:14:03 +0530102 ]
103 }
Ahmad9dae36b2021-09-17 01:51:32 +0500104
Deepesh Garg615dd9d2022-02-13 19:24:10 +0530105 create_custom_fields(custom_fields, ignore_validate=True, update=True)
ahmadpak2a5beec2021-10-30 17:18:45 +0300106
Deepesh Gargc81d4732021-11-08 17:14:03 +0530107def update_regional_tax_settings(country, company):
108 create_ksa_vat_setting(company)