Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions pos_next/api/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"brand",
"has_variants",
"variant_of",
"custom_company",
"disabled",
]

Expand Down Expand Up @@ -525,22 +524,13 @@ def get_item_variants(template_item, pos_profile):
Item.has_serial_no,
Item.item_group,
Item.brand,
Item.custom_company,
Item.variant_of,
)
.where(Item.variant_of == template_item)
.where(Item.disabled == 0)
.where(Item.is_sales_item == 1)
)

# Company scope: strict by default; include empty (global) items only if
# the profile's POS Settings explicitly opts in.
if pos_profile_doc.company:
if _pos_settings_allow_global_items(pos_profile_doc.name):
query = query.where(fn.Coalesce(Item.custom_company, "").isin([pos_profile_doc.company, ""]))
else:
query = query.where(Item.custom_company == pos_profile_doc.company)

variants = query.run(as_dict=True)

# If no variants found, return empty with helpful message
Expand Down Expand Up @@ -726,37 +716,6 @@ def _get_allowed_profile_brands(pos_profile):
return _get_pos_profile_configured_brands(pos_profile)


def invalidate_pos_settings_cache(doc, method=None):
"""Doc-event hook: drop cached `allow_global_items` when POS Settings is saved."""
if doc and getattr(doc, "pos_profile", None):
frappe.cache().delete_value(f"pos_settings_allow_global_items:{doc.pos_profile}")


def _pos_settings_allow_global_items(pos_profile_name):
"""Whether the POS Settings row for this profile opts into global items.

A "global item" is one whose ``custom_company`` is NULL or empty — historically
used as a shared SKU across companies. With strict company filtering as the
default, these items are hidden unless this flag is enabled.
"""
cache_key = f"pos_settings_allow_global_items:{pos_profile_name}"
cached = frappe.cache().get_value(cache_key)
if cached is not None:
return cached

value = (
frappe.db.get_value(
"POS Settings",
{"pos_profile": pos_profile_name, "enabled": 1},
"allow_global_items",
)
or 0
)
result = int(value)
frappe.cache().set_value(cache_key, result, expires_in_sec=300)
return result


def _get_pos_profile_allowed_item_groups(pos_profile_doc):
"""Return the item groups (with descendants) authorised for a POS Profile.

Expand Down Expand Up @@ -806,13 +765,6 @@ def _build_item_base_conditions(

where_params = []

if pos_profile_doc.company:
if _pos_settings_allow_global_items(pos_profile_doc.name):
conditions.append("(i.custom_company = %s OR IFNULL(i.custom_company, '') = '')")
else:
conditions.append("i.custom_company = %s")
where_params.append(pos_profile_doc.company)

allowed_item_groups = _get_pos_profile_allowed_item_groups(pos_profile_doc)

if item_group:
Expand Down
39 changes: 0 additions & 39 deletions pos_next/company_isolation.py

This file was deleted.

14 changes: 0 additions & 14 deletions pos_next/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@

# notification_config = "pos_next.notifications.get_notification_config"

# Permissions
# Standard Queries
# ----------------
# Custom query for company-aware item filtering
standard_queries = {
"Item": "pos_next.validations.item_query"
}

# DocType Class
# ---------------
# Override standard doctype classes
Expand All @@ -157,9 +149,6 @@
# Hook on document methods and events

doc_events = {
"Item": {
"validate": "pos_next.validations.validate_item"
},
"Customer": {
"after_insert": [
"pos_next.api.customers.auto_assign_loyalty_program",
Expand All @@ -185,9 +174,6 @@
"POS Profile": {
"on_update": "pos_next.realtime_events.emit_pos_profile_updated_event"
},
"POS Settings": {
"on_update": "pos_next.api.items.invalidate_pos_settings_cache"
},
"Promotional Scheme": {
"on_update": "pos_next.overrides.pricing_rule.sync_pos_only_to_pricing_rules"
}
Expand Down
3 changes: 2 additions & 1 deletion pos_next/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

[post_model_sync]
# Patches added in this section will be executed after doctypes are migrated
pos_next.patches.v1_7_0.reinstall_workspace
pos_next.patches.v1_7_0.reinstall_workspace
pos_next.patches.v2_0_0.remove_custom_company_fields
Empty file.
21 changes: 21 additions & 0 deletions pos_next/patches/v2_0_0/remove_custom_company_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import frappe


CUSTOM_FIELDS = [
"Brand-custom_company",
"Customer-custom_company",
"Customer Group-custom_company",
"Item-custom_company",
"Item Group-custom_company",
"Price List-custom_company",
"Supplier-custom_company",
"Supplier Group-custom_company",
]


def execute():
for field_name in CUSTOM_FIELDS:
if frappe.db.exists("Custom Field", field_name):
frappe.delete_doc("Custom Field", field_name, force=True, ignore_permissions=True)

frappe.cache().delete_keys("pos_settings_allow_global_items:*")
21 changes: 0 additions & 21 deletions pos_next/pos_next/custom/brand.json

This file was deleted.

21 changes: 0 additions & 21 deletions pos_next/pos_next/custom/customer.json

This file was deleted.

21 changes: 0 additions & 21 deletions pos_next/pos_next/custom/customer_group.json

This file was deleted.

73 changes: 0 additions & 73 deletions pos_next/pos_next/custom/item.json

This file was deleted.

21 changes: 0 additions & 21 deletions pos_next/pos_next/custom/item_group.json

This file was deleted.

21 changes: 0 additions & 21 deletions pos_next/pos_next/custom/price_list.json

This file was deleted.

2 changes: 1 addition & 1 deletion pos_next/pos_next/custom/promotional_scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "disable",
"insert_after": "selling",
"is_system_generated": 0,
"is_virtual": 0,
"label": "POS Only",
Expand Down
Loading
Loading