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 |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 6 | 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] | 7 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
rohitwaghchaure | 4e17fae | 2017-12-12 14:40:52 +0530 | [diff] [blame] | 8 | |
| 9 | def setup(company=None, patch=True): |
rohitwaghchaure | 4e17fae | 2017-12-12 14:40:52 +0530 | [diff] [blame] | 10 | add_print_formats() |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 11 | add_permissions() |
ahmadpak | 2a5beec | 2021-10-30 17:18:45 +0300 | [diff] [blame] | 12 | make_custom_fields() |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 13 | |
Dany Robert | bb3119c | 2021-12-07 11:05:41 +0000 | [diff] [blame] | 14 | def add_print_formats(): |
Dany Robert | a0aeace | 2021-12-07 12:39:39 +0000 | [diff] [blame] | 15 | 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 Robert | bb3119c | 2021-12-07 11:05:41 +0000 | [diff] [blame] | 20 | |
Dany Robert | ca85094 | 2021-12-08 07:52:06 +0530 | [diff] [blame] | 21 | 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 Robert | bb3119c | 2021-12-07 11:05:41 +0000 | [diff] [blame] | 23 | |
Ahmad | cb0c2d1 | 2021-08-26 07:35:59 +0500 | [diff] [blame] | 24 | def 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) |
Ahmad | 87380d0 | 2021-09-06 23:36:55 +0500 | [diff] [blame] | 34 | |
ahmadpak | 2a5beec | 2021-10-30 17:18:45 +0300 | [diff] [blame] | 35 | def make_custom_fields(): |
| 36 | """Create Custom fields |
| 37 | - QR code Image file |
| 38 | - Company Name in Arabic |
| 39 | - Address in Arabic |
| 40 | """ |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 41 | 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 Robert | 63a4c1d | 2022-01-06 18:48:02 +0530 | [diff] [blame] | 44 | |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 45 | 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 Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 69 | custom_fields = { |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 70 | '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 Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 74 | ], |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 75 | 'Supplier': [ |
| 76 | dict(fieldname='supplier_name_in_arabic', label='Supplier Name in Arabic', |
| 77 | fieldtype='Data', insert_after='supplier_name'), |
Dany Robert | d06c4b5 | 2021-12-07 12:29:59 +0530 | [diff] [blame] | 78 | ], |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 79 | '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 Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 95 | 'Address': [ |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 96 | dict(fieldname='address_in_arabic', label='Address in Arabic', |
| 97 | fieldtype='Data',insert_after='address_line2') |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 98 | ], |
| 99 | 'Company': [ |
Dany Robert | 00b2ded | 2022-01-06 18:42:56 +0530 | [diff] [blame] | 100 | dict(fieldname='company_name_in_arabic', label='Company Name In Arabic', |
| 101 | fieldtype='Data', insert_after='company_name') |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 102 | ] |
| 103 | } |
Ahmad | 9dae36b | 2021-09-17 01:51:32 +0500 | [diff] [blame] | 104 | |
Deepesh Garg | 615dd9d | 2022-02-13 19:24:10 +0530 | [diff] [blame] | 105 | create_custom_fields(custom_fields, ignore_validate=True, update=True) |
ahmadpak | 2a5beec | 2021-10-30 17:18:45 +0300 | [diff] [blame] | 106 | |
Deepesh Garg | c81d473 | 2021-11-08 17:14:03 +0530 | [diff] [blame] | 107 | def update_regional_tax_settings(country, company): |
| 108 | create_ksa_vat_setting(company) |