fix: Patch fixes for v13 upgrade (#25220)

diff --git a/erpnext/accounts/workspace/accounting/accounting.json b/erpnext/accounts/workspace/accounting/accounting.json
index fadb665..9ffa481 100644
--- a/erpnext/accounts/workspace/accounting/accounting.json
+++ b/erpnext/accounts/workspace/accounting/accounting.json
@@ -444,6 +444,16 @@
    "type": "Link"
   },
   {
+    "dependencies": "GL Entry",
+    "hidden": 0,
+    "is_query_report": 1,
+    "label": "UAE VAT 201",
+    "link_to": "UAE VAT 201",
+    "link_type": "Report",
+    "onboard": 0,
+    "type": "Link"
+   },
+  {
    "hidden": 0,
    "is_query_report": 0,
    "label": "Financial Statements",
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 59058a4..09d4b22 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -761,3 +761,4 @@
 erpnext.patches.v13_0.rename_membership_settings_to_non_profit_settings
 erpnext.patches.v13_0.setup_gratuity_rule_for_india_and_uae
 erpnext.patches.v13_0.setup_uae_vat_fields
+erpnext.patches.v13_0.fix_non_unique_represents_company
diff --git a/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py
index 48d5cb4..59b2e49 100644
--- a/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py
+++ b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py
@@ -11,4 +11,8 @@
 	if not company:
 		return
 
+
+	frappe.reload_doc('accounts', 'doctype', 'pos_invoice')
+	frappe.reload_doc('accounts', 'doctype', 'pos_invoice_item')
+
 	make_custom_fields()
\ No newline at end of file
diff --git a/erpnext/patches/v13_0/fix_non_unique_represents_company.py b/erpnext/patches/v13_0/fix_non_unique_represents_company.py
new file mode 100644
index 0000000..61dc824
--- /dev/null
+++ b/erpnext/patches/v13_0/fix_non_unique_represents_company.py
@@ -0,0 +1,8 @@
+import frappe
+
+def execute():
+	frappe.db.sql("""
+		update tabCustomer
+		set represents_company = NULL
+		where represents_company = ''
+	""")
\ No newline at end of file
diff --git a/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py b/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py
index de08aa2..7ec470c 100644
--- a/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py
+++ b/erpnext/patches/v13_0/setup_patient_history_settings_for_standard_doctypes.py
@@ -6,6 +6,8 @@
 	if "Healthcare" not in frappe.get_active_domains():
 		return
 
+	frappe.reload_doc("healthcare", "doctype", "Inpatient Medication Order")
+	frappe.reload_doc("healthcare", "doctype", "Therapy Session")
 	frappe.reload_doc("healthcare", "doctype", "Patient History Settings")
 	frappe.reload_doc("healthcare", "doctype", "Patient History Standard Document Type")
 	frappe.reload_doc("healthcare", "doctype", "Patient History Custom Document Type")
diff --git a/erpnext/patches/v13_0/setup_uae_vat_fields.py b/erpnext/patches/v13_0/setup_uae_vat_fields.py
index ee55bb8..1830bab 100644
--- a/erpnext/patches/v13_0/setup_uae_vat_fields.py
+++ b/erpnext/patches/v13_0/setup_uae_vat_fields.py
@@ -9,4 +9,8 @@
 	if not company:
 		return
 
+	frappe.reload_doc('regional', 'report', 'uae_vat_201')
+	frappe.reload_doc('regional', 'doctype', 'uae_vat_settings')
+	frappe.reload_doc('regional', 'doctype', 'uae_vat_account')
+
 	setup()
diff --git a/erpnext/regional/germany/setup.py b/erpnext/regional/germany/setup.py
index d6047e8..ac1f543 100644
--- a/erpnext/regional/germany/setup.py
+++ b/erpnext/regional/germany/setup.py
@@ -3,4 +3,17 @@
 
 
 def setup(company=None, patch=True):
-	pass
+	add_custom_roles_for_reports()
+
+
+def add_custom_roles_for_reports():
+	"""Add Access Control to UAE VAT 201."""
+	if not frappe.db.get_value('Custom Role', dict(report='DATEV')):
+		frappe.get_doc(dict(
+			doctype='Custom Role',
+			report='DATEV',
+			roles= [
+				dict(role='Accounts User'),
+				dict(role='Accounts Manager')
+			]
+		)).insert()
\ No newline at end of file
diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py
index f7689cf..d573425 100644
--- a/erpnext/regional/india/setup.py
+++ b/erpnext/regional/india/setup.py
@@ -12,14 +12,14 @@
 from frappe.utils import today
 
 def setup(company=None, patch=True):
-	setup_company_independent_fixtures()
+	setup_company_independent_fixtures(patch=patch)
 	if not patch:
 		make_fixtures(company)
 
 # TODO: for all countries
-def setup_company_independent_fixtures():
+def setup_company_independent_fixtures(patch=False):
 	make_custom_fields()
-	make_property_setters()
+	make_property_setters(patch=patch)
 	add_permissions()
 	add_custom_roles_for_reports()
 	frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
@@ -112,10 +112,11 @@
 	frappe.db.set_value("Print Format", "GST Tax Invoice", "disabled", 0)
 	frappe.db.set_value("Print Format", "GST E-Invoice", "disabled", 0)
 
-def make_property_setters():
+def make_property_setters(patch=False):
 	# GST rules do not allow for an invoice no. bigger than 16 characters
-	make_property_setter('Sales Invoice', 'naming_series', 'options', 'SINV-.YY.-\nSRET-.YY.-', '')
-	make_property_setter('Purchase Invoice', 'naming_series', 'options', 'PINV-.YY.-\nPRET-.YY.-', '')
+	if not patch:
+		make_property_setter('Sales Invoice', 'naming_series', 'options', 'SINV-.YY.-\nSRET-.YY.-', '')
+		make_property_setter('Purchase Invoice', 'naming_series', 'options', 'PINV-.YY.-\nPRET-.YY.-', '')
 
 def make_custom_fields(update=True):
 	hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
diff --git a/erpnext/regional/report/datev/datev.json b/erpnext/regional/report/datev/datev.json
index 80a866c..94e3960 100644
--- a/erpnext/regional/report/datev/datev.json
+++ b/erpnext/regional/report/datev/datev.json
@@ -1,29 +1,22 @@
 {
-	"add_total_row": 0,
-	"apply_user_permissions": 0,
-	"creation": "2019-04-24 08:45:16.650129",
-	"disabled": 0,
-	"icon": "octicon octicon-repo-pull",
-	"color": "#4CB944",
-	"docstatus": 0,
-	"doctype": "Report",
-	"idx": 0,
-	"is_standard": "Yes",
-	"module": "Regional",
-	"name": "DATEV",
-	"owner": "Administrator",
-	"ref_doctype": "GL Entry",
-	"report_name": "DATEV",
-	"report_type": "Script Report",
-	"roles": [
-		{
-			"role": "Accounts User"
-		},
-		{
-			"role": "Accounts Manager"
-		},
-		{
-			"role": "Auditor"
-		}
-	]
-}
+ "add_total_row": 0,
+ "columns": [],
+ "creation": "2019-04-24 08:45:16.650129",
+ "disable_prepared_report": 0,
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "filters": [],
+ "idx": 0,
+ "is_standard": "Yes",
+ "modified": "2021-04-06 12:23:00.379517",
+ "modified_by": "Administrator",
+ "module": "Regional",
+ "name": "DATEV",
+ "owner": "Administrator",
+ "prepared_report": 0,
+ "ref_doctype": "GL Entry",
+ "report_name": "DATEV",
+ "report_type": "Script Report",
+ "roles": []
+}
\ No newline at end of file