rohitwaghchaure | 4e17fae | 2017-12-12 14:40:52 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 4 | import frappe |
| 5 | from frappe.permissions import add_permission, update_permission_property |
Dany Robert | bb3119c | 2021-12-07 11:05:41 +0000 | [diff] [blame^] | 6 | from erpnext.regional.united_arab_emirates.setup import make_custom_fields as uae_custom_fields |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 7 | from erpnext.regional.saudi_arabia.wizard.operations.setup_ksa_vat_setting import create_ksa_vat_setting |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 8 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
rohitwaghchaure | 4e17fae | 2017-12-12 14:40:52 +0530 | [diff] [blame] | 9 | |
| 10 | def setup(company=None, patch=True): |
Ahmad | 87380d0 | 2021-09-06 23:36:55 +0500 | [diff] [blame] | 11 | uae_custom_fields() |
rohitwaghchaure | 4e17fae | 2017-12-12 14:40:52 +0530 | [diff] [blame] | 12 | add_print_formats() |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 13 | add_permissions() |
ahmadpak | 2a5beec | 2021-10-30 17:18:45 +0300 | [diff] [blame] | 14 | make_custom_fields() |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 15 | |
Dany Robert | bb3119c | 2021-12-07 11:05:41 +0000 | [diff] [blame^] | 16 | def add_print_formats(): |
| 17 | frappe.reload_doc("regional", "print_format", "detailed_tax_invoice") |
| 18 | frappe.reload_doc("regional", "print_format", "simplified_tax_invoice") |
| 19 | frappe.reload_doc("regional", "print_format", "tax_invoice") |
| 20 | frappe.reload_doc("regional", "print_format", "ksa_vat_invoice") |
| 21 | frappe.reload_doc("regional", "print_format", "ksa_pos_invoice") |
| 22 | |
| 23 | frappe.db.sql("""UPDATE`tabPrint Format` SET disabled = 0 WHERE |
| 24 | name IN ('Simplified Tax Invoice', 'Detailed Tax Invoice', |
| 25 | 'Tax Invoice', 'KSA VAT Invoice', 'KSA POS Invoice') |
| 26 | """) |
| 27 | |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 28 | def add_permissions(): |
| 29 | """Add Permissions for KSA VAT Setting.""" |
| 30 | add_permission('KSA VAT Setting', 'All', 0) |
| 31 | for role in ('Accounts Manager', 'Accounts User', 'System Manager'): |
| 32 | add_permission('KSA VAT Setting', role, 0) |
| 33 | update_permission_property('KSA VAT Setting', role, 0, 'write', 1) |
| 34 | update_permission_property('KSA VAT Setting', role, 0, 'create', 1) |
| 35 | |
| 36 | """Enable KSA VAT Report""" |
| 37 | frappe.db.set_value('Report', 'KSA VAT', 'disabled', 0) |
Ahmad | 87380d0 | 2021-09-06 23:36:55 +0500 | [diff] [blame] | 38 | |
ahmadpak | 2a5beec | 2021-10-30 17:18:45 +0300 | [diff] [blame] | 39 | def make_custom_fields(): |
| 40 | """Create Custom fields |
| 41 | - QR code Image file |
| 42 | - Company Name in Arabic |
| 43 | - Address in Arabic |
| 44 | """ |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 45 | custom_fields = { |
| 46 | 'Sales Invoice': [ |
| 47 | dict( |
Dany Robert | 6a6d6f7 | 2021-12-07 12:17:45 +0530 | [diff] [blame] | 48 | fieldname='ksa_einv_qr', |
| 49 | label='KSA E-Invoicing QR', |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 50 | fieldtype='Attach Image', |
| 51 | read_only=1, no_copy=1, hidden=1 |
| 52 | ) |
| 53 | ], |
Dany Robert | d06c4b5 | 2021-12-07 12:29:59 +0530 | [diff] [blame] | 54 | 'POS Invoice': [ |
| 55 | dict( |
| 56 | fieldname='ksa_einv_qr', |
| 57 | label='KSA E-Invoicing QR', |
| 58 | fieldtype='Attach Image', |
| 59 | read_only=1, no_copy=1, hidden=1 |
| 60 | ) |
| 61 | ], |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 62 | 'Address': [ |
| 63 | dict( |
| 64 | fieldname='address_in_arabic', |
| 65 | label='Address in Arabic', |
| 66 | fieldtype='Data', |
| 67 | insert_after='address_line2' |
| 68 | ) |
| 69 | ], |
| 70 | 'Company': [ |
| 71 | dict( |
| 72 | fieldname='company_name_in_arabic', |
| 73 | label='Company Name In Arabic', |
| 74 | fieldtype='Data', |
| 75 | insert_after='company_name' |
| 76 | ) |
| 77 | ] |
| 78 | } |
Ahmad | 9dae36b | 2021-09-17 01:51:32 +0500 | [diff] [blame] | 79 | |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 80 | create_custom_fields(custom_fields, update=True) |
ahmadpak | 2a5beec | 2021-10-30 17:18:45 +0300 | [diff] [blame] | 81 | |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 82 | def update_regional_tax_settings(country, company): |
| 83 | create_ksa_vat_setting(company) |