blob: 8f2ad5cfeb0e1044c387e4aa143573dce8d221d9 [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):
Dany Robert90eb0462022-01-06 18:15:40 +053010 make_custom_fields()
rohitwaghchaure4e17fae2017-12-12 14:40:52 +053011 add_print_formats()
Ahmadcb0c2d12021-08-26 07:35:59 +050012 add_permissions()
ahmadpak2a5beec2021-10-30 17:18:45 +030013 make_custom_fields()
Ahmadcb0c2d12021-08-26 07:35:59 +050014
Dany Robert90eb0462022-01-06 18:15:40 +053015def make_custom_fields():
16 is_zero_rated = dict(fieldname='is_zero_rated', label='Is Zero Rated',
17 fieldtype='Check', fetch_from='item_code.is_zero_rated', insert_after='description',
18 print_hide=1)
19
20 is_exempt = dict(fieldname='is_exempt', label='Is Exempt',
21 fieldtype='Check', fetch_from='item_code.is_exempt', insert_after='is_zero_rated',
22 print_hide=1)
23
24 purchase_invoice_fields = [
25 dict(fieldname='company_trn', label='Company TRN',
26 fieldtype='Read Only', insert_after='shipping_address',
27 fetch_from='company.tax_id', print_hide=1),
28 dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic',
29 fieldtype='Read Only', insert_after='supplier_name',
30 fetch_from='supplier.supplier_name_in_arabic', print_hide=1)
31 ]
32
33 sales_invoice_fields = [
34 dict(fieldname='company_trn', label='Company TRN',
35 fieldtype='Read Only', insert_after='company_address',
36 fetch_from='company.tax_id', print_hide=1),
37 dict(fieldname='customer_name_in_arabic', label='Customer Name in Arabic',
38 fieldtype='Read Only', insert_after='customer_name',
39 fetch_from='customer.customer_name_in_arabic', print_hide=1)
40 ]
41
42 custom_fields = {
43 'Item': [is_zero_rated, is_exempt],
44 'Customer': [
45 dict(fieldname='customer_name_in_arabic', label='Customer Name in Arabic',
46 fieldtype='Data', insert_after='customer_name'),
47 ],
48 'Supplier': [
49 dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic',
50 fieldtype='Data', insert_after='supplier_name'),
51 ],
52 'Purchase Invoice': purchase_invoice_fields,
53 'Purchase Order': purchase_invoice_fields,
54 'Purchase Receipt': purchase_invoice_fields,
55 'Sales Invoice': sales_invoice_fields,
56 'POS Invoice': sales_invoice_fields,
57 'Sales Order': sales_invoice_fields,
58 'Delivery Note': sales_invoice_fields,
59 'Sales Invoice Item': [is_zero_rated, is_exempt],
60 'POS Invoice Item': [is_zero_rated, is_exempt],
61 'Purchase Invoice Item': [is_zero_rated, is_exempt],
62 'Sales Order Item': [is_zero_rated, is_exempt],
63 'Delivery Note Item': [is_zero_rated, is_exempt],
64 'Quotation Item': [is_zero_rated, is_exempt],
65 'Purchase Order Item': [is_zero_rated, is_exempt],
66 'Purchase Receipt Item': [is_zero_rated, is_exempt],
67 'Supplier Quotation Item': [is_zero_rated, is_exempt],
68 }
69
70 create_custom_fields(custom_fields)
71
Dany Robertbb3119c2021-12-07 11:05:41 +000072def add_print_formats():
Dany Roberta0aeace2021-12-07 12:39:39 +000073 frappe.reload_doc("regional", "print_format", "detailed_tax_invoice", force=True)
74 frappe.reload_doc("regional", "print_format", "simplified_tax_invoice", force=True)
75 frappe.reload_doc("regional", "print_format", "tax_invoice", force=True)
76 frappe.reload_doc("regional", "print_format", "ksa_vat_invoice", force=True)
77 frappe.reload_doc("regional", "print_format", "ksa_pos_invoice", force=True)
Dany Robertbb3119c2021-12-07 11:05:41 +000078
Dany Robertca850942021-12-08 07:52:06 +053079 for d in ('Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice', 'KSA VAT Invoice', 'KSA POS Invoice'):
80 frappe.db.set_value("Print Format", d, "disabled", 0)
Dany Robertbb3119c2021-12-07 11:05:41 +000081
Ahmadcb0c2d12021-08-26 07:35:59 +050082def add_permissions():
83 """Add Permissions for KSA VAT Setting."""
84 add_permission('KSA VAT Setting', 'All', 0)
85 for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
86 add_permission('KSA VAT Setting', role, 0)
87 update_permission_property('KSA VAT Setting', role, 0, 'write', 1)
88 update_permission_property('KSA VAT Setting', role, 0, 'create', 1)
89
90 """Enable KSA VAT Report"""
91 frappe.db.set_value('Report', 'KSA VAT', 'disabled', 0)
Ahmad87380d02021-09-06 23:36:55 +050092
ahmadpak2a5beec2021-10-30 17:18:45 +030093def make_custom_fields():
94 """Create Custom fields
95 - QR code Image file
96 - Company Name in Arabic
97 - Address in Arabic
98 """
Deepesh Gargc81d4732021-11-08 17:14:03 +053099 custom_fields = {
100 'Sales Invoice': [
101 dict(
Dany Robert6a6d6f72021-12-07 12:17:45 +0530102 fieldname='ksa_einv_qr',
103 label='KSA E-Invoicing QR',
Deepesh Gargc81d4732021-11-08 17:14:03 +0530104 fieldtype='Attach Image',
105 read_only=1, no_copy=1, hidden=1
106 )
107 ],
Dany Robertd06c4b52021-12-07 12:29:59 +0530108 'POS Invoice': [
109 dict(
110 fieldname='ksa_einv_qr',
111 label='KSA E-Invoicing QR',
112 fieldtype='Attach Image',
113 read_only=1, no_copy=1, hidden=1
114 )
115 ],
Deepesh Gargc81d4732021-11-08 17:14:03 +0530116 'Address': [
117 dict(
118 fieldname='address_in_arabic',
119 label='Address in Arabic',
120 fieldtype='Data',
121 insert_after='address_line2'
122 )
123 ],
124 'Company': [
125 dict(
126 fieldname='company_name_in_arabic',
127 label='Company Name In Arabic',
128 fieldtype='Data',
129 insert_after='company_name'
130 )
131 ]
132 }
Ahmad9dae36b2021-09-17 01:51:32 +0500133
Deepesh Gargc81d4732021-11-08 17:14:03 +0530134 create_custom_fields(custom_fields, update=True)
ahmadpak2a5beec2021-10-30 17:18:45 +0300135
Deepesh Gargc81d4732021-11-08 17:14:03 +0530136def update_regional_tax_settings(country, company):
137 create_ksa_vat_setting(company)