Frappe | 1dfb5eb | 2021-07-14 12:33:45 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Frappe | 1dfb5eb | 2021-07-14 12:33:45 +0530 | [diff] [blame] | 4 | |
Anuja Pawar | 08ae49c | 2021-08-09 17:58:52 +0530 | [diff] [blame] | 5 | import frappe |
Anuja | 5dcd5e4 | 2021-07-29 00:54:48 +0530 | [diff] [blame] | 6 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
Frappe | 1dfb5eb | 2021-07-14 12:33:45 +0530 | [diff] [blame] | 7 | from frappe.permissions import add_permission, update_permission_property |
| 8 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 9 | |
Anuja Pawar | abc63cf | 2021-07-26 18:11:38 +0530 | [diff] [blame] | 10 | def setup(company=None, patch=True): |
Anuja Pawar | 08ae49c | 2021-08-09 17:58:52 +0530 | [diff] [blame] | 11 | make_custom_fields() |
Frappe | 1dfb5eb | 2021-07-14 12:33:45 +0530 | [diff] [blame] | 12 | add_permissions() |
| 13 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 14 | |
Anuja | 5dcd5e4 | 2021-07-29 00:54:48 +0530 | [diff] [blame] | 15 | def make_custom_fields(update=True): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 16 | is_zero_rated = dict( |
| 17 | fieldname="is_zero_rated", |
| 18 | label="Is Zero Rated", |
| 19 | fieldtype="Check", |
| 20 | fetch_from="item_code.is_zero_rated", |
| 21 | insert_after="description", |
| 22 | print_hide=1, |
| 23 | ) |
Anuja | 5dcd5e4 | 2021-07-29 00:54:48 +0530 | [diff] [blame] | 24 | custom_fields = { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 25 | "Item": [ |
| 26 | dict( |
| 27 | fieldname="is_zero_rated", |
| 28 | label="Is Zero Rated", |
| 29 | fieldtype="Check", |
| 30 | insert_after="item_group", |
| 31 | print_hide=1, |
| 32 | ) |
Anuja | 5dcd5e4 | 2021-07-29 00:54:48 +0530 | [diff] [blame] | 33 | ], |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 34 | "Sales Invoice Item": is_zero_rated, |
| 35 | "Purchase Invoice Item": is_zero_rated, |
Anuja | 5dcd5e4 | 2021-07-29 00:54:48 +0530 | [diff] [blame] | 36 | } |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 37 | |
Anuja | 5dcd5e4 | 2021-07-29 00:54:48 +0530 | [diff] [blame] | 38 | create_custom_fields(custom_fields, update=update) |
| 39 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 40 | |
Frappe | 1dfb5eb | 2021-07-14 12:33:45 +0530 | [diff] [blame] | 41 | def add_permissions(): |
Anuja Pawar | 08ae49c | 2021-08-09 17:58:52 +0530 | [diff] [blame] | 42 | """Add Permissions for South Africa VAT Settings and South Africa VAT Account |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 43 | and VAT Audit Report""" |
| 44 | for doctype in ("South Africa VAT Settings", "South Africa VAT Account"): |
| 45 | add_permission(doctype, "All", 0) |
| 46 | for role in ("Accounts Manager", "Accounts User", "System Manager"): |
Frappe | 1dfb5eb | 2021-07-14 12:33:45 +0530 | [diff] [blame] | 47 | add_permission(doctype, role, 0) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 48 | update_permission_property(doctype, role, 0, "write", 1) |
| 49 | update_permission_property(doctype, role, 0, "create", 1) |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 50 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 51 | if not frappe.db.get_value("Custom Role", dict(report="VAT Audit Report")): |
| 52 | frappe.get_doc( |
| 53 | dict( |
| 54 | doctype="Custom Role", |
| 55 | report="VAT Audit Report", |
| 56 | roles=[dict(role="Accounts User"), dict(role="Accounts Manager"), dict(role="Auditor")], |
| 57 | ) |
| 58 | ).insert() |