Skip to content

[16.0][IMP] purchase_request_sequence_kmitl: number on submit, format PR/YYYY/NNNN - #1208

Open
PiyaChaiyanit wants to merge 12 commits into
16.0from
16.0-imp-purchase_request-doc-number
Open

[16.0][IMP] purchase_request_sequence_kmitl: number on submit, format PR/YYYY/NNNN#1208
PiyaChaiyanit wants to merge 12 commits into
16.0from
16.0-imp-purchase_request-doc-number

Conversation

@PiyaChaiyanit

Copy link
Copy Markdown
Collaborator

Summary

  • Move purchase request numbering from create() to button_to_verify() so drafts no longer consume sequence numbers — the number is only drawn when the user clicks Request approval.
  • Change the number format from PR/{yy}/{dept_short}/{0001} (e.g. PR/69/ENG/0001) to PR/{fiscal_year}/{0001} (e.g. PR/2569/0001): use the 4-digit fiscal year name and drop the department short name. One ir.sequence per fiscal year, auto-created on first submit.
  • Lock the Fiscal Year field once the record leaves draft so the year embedded in the number stays consistent with the FY the sequence keyed off. Manifest depends updated to purchase_request_approval_kmitl since button_to_verify lives there.

Test plan

  • Create a new PR: name stays /, fiscal year is editable and prefilled with the current FY.
  • Click Request approval: state moves to to_verify (or to_examine), name becomes PR/{fy.name}/0001, and the fiscal year field turns read-only.
  • Submit a second PR in the same FY → PR/{fy.name}/0002.
  • Override the FY to a different year in draft, then submit → number reflects the chosen FY and uses that year's sequence.
  • Existing pre-migration PRs reset to draft and re-submitted keep their original number (no new sequence pull).

Sunny added 2 commits August 26, 2026 15:57
…erify and change format

- Assign the document number when the user submits the request
  (button_to_verify) instead of at record creation, so drafts do not
  consume sequence numbers.
- Change the format from PR/{yy}/{dept_short}/{0001} to
  PR/{fiscal_year}/{0001} (e.g. PR/2569/0001): use the 4-digit fiscal
  year name and drop the department short name.
- Lock the fiscal year field once the record leaves draft to keep the
  year embedded in the number consistent with the FY the sequence keyed
  off.
…popup blocks submission

super().button_to_verify() returns the exception popup wizard without
changing state when detect_exceptions() fires and ignore_exception is
False. The previous code still generated a document number in that
case, wasting a slot in the fiscal-year sequence.

Only assign the number when the state actually moved out of draft, so
the retry path (user acknowledges the popup and clicks Request approval
again) is what draws the number.
Comment thread purchase_request_sequence_kmitl/models/purchase_request.py Outdated
"website": "https://github.com/aginix/kmitl",
"category": "KMITL",
'depends': ['hr_department_short_name', 'purchase_request_department'],
'depends': ['purchase_request_approval_kmitl'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?????

Comment thread purchase_request_sequence_kmitl/models/purchase_request.py Outdated
Comment thread purchase_request_kmitl/views/purchase_request_views.xml Outdated
Sunny added 7 commits August 27, 2026 17:51
Address PR #1208 review by switching to the compute-based numbering
pattern from budget_transfer (models/budget_transfer.py:65-253):

- Declare the sequence statically in data/sequence.xml with
  PR/%(year_be)s/, use_date_range=1 and no_gap, so the BE year is
  rendered by l10n_th_base_sequence from the sequence_date we pass
  and per-FY counters reset automatically.
- Redeclare name as compute-store on @api.depends(state,
  account_fiscal_year_id) with default=_("New"), and override
  _get_default_name to no-op so the base's next_by_code no longer
  fires at create. The mint is drawn on account_fiscal_year_id.date_to
  so the number's year comes from the FY, not today.
- Add fiscal_year_locked (compute on name) and gate the field's
  readonly on it via a new inherited view; add a write() guard that
  rejects FY changes once the number has been assigned.
- Drop the depends on purchase_request_approval_kmitl,
  hr_department_short_name and purchase_request_department — none are
  needed with the compute-based approach.
- Revert the state-based readonly modifier in purchase_request_kmitl
  so the lock lives in exactly one place (the new inherited view).

Also handles the exception-popup case automatically: if
super().button_to_verify() returns the popup without changing state,
the compute's state dependency doesn't fire and no number is drawn.
Follow procurement_plan's action_send_to_verify pattern instead of a
compute-store on name. next_by_code() has a side effect (advances the
sequence counter) which does not belong inside a compute; putting it in
the button makes the mint an explicit, greppable step at the transition
call site.

- purchase_request_sequence_kmitl now provides just the XML sequence
  and a _get_default_name override that returns _("New"), so the base's
  next_by_code("purchase.request") no longer fires at create.
  Deps trim to purchase_request + l10n_th_base_sequence.
- purchase_request_approval_kmitl owns the mint: button_to_verify now
  writes the state and then calls _assign_document_number, drawing the
  sequence on account_fiscal_year_id.date_to. It also owns
  fiscal_year_locked (compute on name), the write() guard rejecting FY
  changes on numbered records, and the inherited view that swaps the
  FY field's readonly modifier. Adds purchase_request_sequence_kmitl to
  its depends.

Exception path preserved: the popup returns before the state write and
mint, so no number is drawn when submission is blocked.
Consolidate all sequence-related behaviour inside
purchase_request_sequence_kmitl so approval_kmitl carries only the
approval workflow, not any sequence logic.

- Move button_to_verify override + _assign_document_number to
  sequence_kmitl. The override calls super() then draws the number
  when state has moved out of draft, so the exception popup path
  (super() returns the popup without changing state) still skips
  the mint automatically.
- Move fiscal_year_locked field, _compute_fiscal_year_locked, and
  the write() FY-freeze guard to sequence_kmitl.
- Move the inherited view that swaps the FY field's readonly modifier
  to sequence_kmitl.
- sequence_kmitl now depends on purchase_request_approval_kmitl —
  documented in the manifest — because the button_to_verify hook needs
  approval_kmitl's method to exist first.
- approval_kmitl reverts to its original button_to_verify and drops
  the sequence_kmitl dep along with the unused UserError/ValidationError
  imports.
Keep this file's imports unchanged from origin/16.0 since none of this
module's logic was actually modified. The previous refactor trimmed
_ / UserError / ValidationError when moving the sequence-related code
out, but these imports belong to code paths owned by this module and
should stay to avoid noise in the diff.
Translate "New" to "รายการใหม่" so draft PRs read consistently in Thai
UI, matching the budget_appropriation convention. Also translate the
Fiscal Year required and FY freeze error messages.
…e_request_approval_kmitl

purchase_request_approval_kmitl was a thin bridge that mixed two
concerns: the to_verify workflow (state, button, editable rule,
exception-confirm wizard) and budget-specific overrides
(_compute_hide_reserve_budget_button, _compute_is_budget_editable).
Split it whole-cloth and delete the module so purchase_request_kmitl
becomes the single base with the complete state model.

- Move to_verify state + button_to_verify + is_purchase_request +
  can_request + _compute_is_editable whitelist into
  purchase_request_kmitl (it already owns to_submit, to_approve,
  cancelled, returned and even references to_verify in views).
- Add the Request approval button + hide button_approved to the
  existing kmitl form-view inherit (statusbar already includes
  to_verify).
- Move the purchase_request_exception_confirm wizard override into
  purchase_request_kmitl/wizards/ so ignore-and-retry still fires.
- Fold approval_kmitl's budget-compute overrides directly into
  purchase_request_budget's own computes as a single canonical
  layer — the super() chain collapses cleanly since budget is now
  the sole owner.
- Redirect the four downstream manifests
  (purchase_request_sequence_kmitl, purchase_request_verify_state,
  purchase_request_todo, kmitl_demo) from purchase_request_approval_kmitl
  to purchase_request_kmitl.
- Bump purchase_request_kmitl to 16.0.0.3.0 and purchase_request_budget
  to 16.0.1.6.0 to signal the merged scope.
- Delete purchase_request_approval_kmitl entirely. Update the
  standalone-reservation ADR to reflect the new module ownership.

MRO chain for button_to_verify is preserved:
verify_state → sequence_kmitl → todo → kmitl (base) — the base just
lives one module up. All overrides still call super() so semantics
are identical.
The Request approval button label and the To be verified state moved
from purchase_request_approval_kmitl into purchase_request_kmitl, but
their translations were left behind when the old module was deleted.
Re-attach them under the new module name so the UI reads correctly:

- "Request approval" → "ส่งข้อมูล"
- "To be verified" → "รอจองงบประมาณ"
@PiyaChaiyanit PiyaChaiyanit added the status/ready-for-review Status: Issue is up for grabs label Aug 28, 2026

@n3n n3n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code review แล้วโอเค แต่ยังไม่ approve นะ ขอทดลองกับ UAT database ล่าสุดก่อน ว่าจะไม่ error เพราะว่ามีเรื่องลบโมดูลออก

n3n added 3 commits August 30, 2026 01:31
… _("New")

Switch the document-number sentinel from _("New") to "/" so locale
comparisons are deterministic: a Thai user minting in th_TH would store
"รายการใหม่" but an en_US reader evaluates _("New") as "New", making the
record appear already-numbered and skipping the mint.  The form view now
renders a translatable "New" <span> when fiscal_year_locked is False so
users still see a friendly label.
button_to_verify is not the only way out of draft (OCA base's
button_to_approve, purchase_request_verify_state's to_examine path, direct
writes) so hooking the mint there let documents reach to_approve/approved
with name still "/" and the fiscal year unfrozen. Move the mint into
write(), keyed on any state transition out of draft except the states that
mean the request was dropped (draft, cancelled).

Also bump the version and raise instead of silently falling back to "/"
when ir.sequence is missing, since an un-upgraded DB would otherwise mint
unnumbered documents with no error.
…proval_kmitl

The module was absorbed into purchase_request_kmitl and purchase_request_budget
and its directory deleted, but Odoo does not uninstall a module whose files
disappear. On a DB where it was previously installed, its
view_purchase_request_form stays active and still resolves its xpath,
duplicating the button_to_verify button and overriding statusbar_visible with
the old set.

Pre-migration deletes the stale view first (its xmlid name collides with
purchase_request_kmitl's own view, so a plain re-own would skip it), re-owns
the remaining xmlids, and flips the module to uninstalled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/ready-for-review Status: Issue is up for grabs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants