Skip to content

feature/Allow restricting credit vouchers to incidents and/or requests - #270

Open
anthonymontebrun wants to merge 4 commits into
pluginsGLPI:mainfrom
anthonymontebrun:feature/voucher-ticket-type
Open

anthonymontebrun wants to merge 4 commits into
pluginsGLPI:mainfrom
anthonymontebrun:feature/voucher-ticket-type

Conversation

@anthonymontebrun

@anthonymontebrun anthonymontebrun commented Oct 20, 2026 •

Copy link
Copy Markdown

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.

Description

This PR adds two options on each credit voucher, Usable for incidents and Usable for requests, to control the ticket types on which the voucher can be consumed. Both options are enabled by default, so existing behaviour is unchanged.

Voucher configuration

  • New fields is_for_incidents / is_for_requests on glpi_plugin_credit_entities (default 1). They are available in the entity tab add form, in the voucher form, in the vouchers list and as search options (998 / 999).
  • Migration adds both columns and sets existing vouchers to 1. Running it again is safe.

Ticket side

  • The voucher dropdowns only list vouchers usable for the ticket type: the followup / task / solution consume block, the ticket Credit tab and the ticket default vouchers.
  • The "Consume a voucher?" block is hidden when the entity has no active voucher usable for the ticket type.
  • A default voucher (ticket or entity level) that does not match the ticket type is not preselected.

Enforcement

  • PluginCreditTicket::prepareInputForAdd() / prepareInputForUpdate() reject a consumption whose voucher cannot be used for the ticket type. This covers the followup / task / solution hook, the ticket tab, the "Update" massive action and the API. On update, the check only runs when the ticket or the voucher changes, so editing the quantity of an older consumption still works.
  • PluginCreditTicketConfig resets a ticket default voucher that does not match the ticket type, and shows a warning. This applies both from the ticket form, which uses the type submitted in the same form, and from the ticket tab.

Tests

  • tests/Units/TicketTypeVoucherTest.php:
    • default values
    • consumption rejected or accepted depending on the ticket type
    • consumption cannot be added or moved to a voucher that does not match the ticket type
    • an invalid ticket default voucher is reset
    • the consume block is shown or hidden depending on the vouchers available.

Add "Usable for incidents" and "Usable for requests" options on credit
vouchers (both enabled by default, including for existing vouchers on
migration).

Vouchers not usable for the ticket type are filtered out of voucher
dropdowns, default vouchers are ignored when not applicable, the consume
block is hidden when no voucher applies, and consumption is rejected
server side.
Check that the voucher can be used for the ticket type when a consumption
is added, or when its ticket or voucher is changed (massive action, API).

Reset ticket default vouchers that cannot be used for the ticket type,
from both the ticket form and the ticket tab.

Fix test relying on item_add hook, which is not registered in tests.

@Rom1-B Rom1-B left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fix CI

Comment thread inc/ticket.class.php Resolved
Comment thread CHANGELOG.md Resolved
Extract the default voucher resolution into
PluginCreditTicket::getDefaultVoucherForTicket(): ticket default, then
entity default, as long as the voucher can be used for the ticket type.

Add tests for this fallback, and for the ticket config update when the
ticket type is changed in the same ticket update.

Consume expected session messages in tests, as unhandled warning and
error messages make the GLPI test case fail.

Move the changelog entry to a new Unreleased section.
@Rom1-B
Rom1-B requested review from a team, MyvTsv and RomainLvr and removed request for a team November 13, 2026 07:12

This branch has not been deployed

No deployments
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.

3 participants