Skip to content

Laf/rename pos settings doctype#240

Open
laidan96 wants to merge 3 commits intoBrainWise-DEV:developfrom
Lafco-global:laf/rename-pos-settings-doctype
Open

Laf/rename pos settings doctype#240
laidan96 wants to merge 3 commits intoBrainWise-DEV:developfrom
Lafco-global:laf/rename-pos-settings-doctype

Conversation

@laidan96
Copy link
Copy Markdown

No description provided.

Lafco CTO (laidan) and others added 3 commits April 16, 2026 21:41
…te + submit

Move the paid_amount/base_paid_amount recomputation out of the is_return
branch so regular Sales Invoices with POS payment rows also get the totals
recalculated before save and again on submit. This prevents the invoice
from being marked "Pay on Account" when payment rows exist.

Restored from cddf4205 invoices.py delta only — i18n dump in the same
local snapshot is intentionally NOT carried over (see LAF-6 plan).

Co-Authored-By: Paperclip <noreply@paperclip.ing>
…16 compat

ERPNext v16 introduces a singleton DocType named 'POS Settings' (with fields
like invoice_type, post_change_gl_entries). This collides with pos_next's
existing per-profile (non-single) 'POS Settings' DocType and causes:

- ERPNext v16 patch 1 (set_invoice_type_in_pos_settings) to hard-fail
  'bench migrate' with ValidationError: Field invoice_type does not exist
  on POS Settings.
- ERPNext v16 patch 22 (set_post_change_gl_entries_on_pos_settings) to
  silently write an orphan row to tabSingles against a non-single doctype.

This patch renames pos_next's DocType from 'POS Settings' to
'POS Next Settings', freeing the canonical 'POS Settings' name for ERPNext
v16 to install its singleton. All pos_next code, workspace links,
whitelisted API dotted paths, and the frontend permission check are
updated accordingly.

Migration:
  pos_next.patches.v1_7_0.rename_pos_settings_to_pos_next_settings runs
  in pre_model_sync so it executes BEFORE ERPNext v16's DocType sync
  creates the new single 'POS Settings'. The patch is idempotent — safe
  on fresh v16 installs, v15 sites with pos_next's POS Settings, and
  already-renamed state.

Downstream: the v16 path in overrides/sales_invoice.py can now call
frappe.db.get_single_value('POS Settings', 'post_change_gl_entries')
directly — the Singles-table Query-Builder fallback is no longer needed.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
… RENAME TABLE

`frappe.rename_doc` renames the parent table (DDL) before running
`update_link_field_values`. MariaDB invalidates the session's cached
table metadata after the DDL, so the next UPDATE in the same session
raises error 1412: "Table definition has changed, please retry transaction".

The DDL itself succeeded — `tabPOS Settings` is renamed to
`tabPOS Next Settings` and the `tabDocType` row is updated. Only the
downstream link-field fixups get tripped.

The patch now:

1. Commits before the rename to flush any pending transaction state.
2. Wraps `frappe.rename_doc(..., rebuild_search=False)` in a try/except.
3. On 1412, swallows the error, reconnects to DB for fresh metadata,
   and manually re-runs the tail of the rename flow
   (`update_link_field_values` + `rename_dynamic_links` +
   `update_user_settings` + `update_attachments`).

Verified on staged rebuild from fresh anchi.ddns.net dump:

- All 34 erpnext v16_0 patches applied cleanly (including patch 1
  `set_invoice_type_in_pos_settings` and patch 22
  `set_post_change_gl_entries_on_pos_settings`, which previously
  hard-stopped migrate).
- `POS Settings` post-migrate is erpnext's v16 single (module=Accounts,
  issingle=1) with `invoice_type='POS Invoice'` +
  `post_change_gl_entries=1` in `tabSingles`.
- `POS Next Settings` retains pos_next's per-profile schema
  (module='POS Next', 70 fields including `pos_profile`,
  `allow_credit_sale`, `wallet_account`, `barcode_rules`); existing
  profile row preserved.
- `pos_next.overrides.sales_invoice._get_post_change_gl_entries_setting()`
  returns 1 (reads erpnext's single cleanly).
- Workspace links in `POSNext` and `Selling` workspaces point to
  `POS Next Settings`, with the user-facing `label` preserved as
  "POS Settings" for UX continuity.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@engahmed1190
Copy link
Copy Markdown
Contributor

I will test this change as it very important

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants