Skip to content

fix(spp_change_request_v2): fix batch approval wizard line deletion#130

Open
emjay0921 wants to merge 3 commits into19.0from
fix/batch-approval-wizard-delete-lines
Open

fix(spp_change_request_v2): fix batch approval wizard line deletion#130
emjay0921 wants to merge 3 commits into19.0from
fix/batch-approval-wizard-delete-lines

Conversation

@emjay0921
Copy link
Contributor

Why is this change needed?

The batch approval wizard opened in "new" (unsaved) mode via default_get, causing all One2many line operations (delete rows, object buttons) to fail with "Please save your changes first".

How was the change implemented?

  • Replaced default_get with create_from_selection() method that explicitly creates the wizard record in the DB before returning the window action
  • Changed the 3 list-view binding actions from ir.actions.act_window to ir.actions.server that call create_from_selection()
  • Removed the custom action_remove_line button — Odoo's built-in One2many delete works now that the record is saved
  • Updated tests to use create_from_selection instead of create({})

New unit tests

Existing tests updated to use the new creation flow.

Unit tests executed by the author

How to test manually

  1. Go to Change Requests list view
  2. Select multiple CRs
  3. Choose "Batch Approve" from the Actions menu
  4. Verify the wizard opens with all selected CRs listed
  5. Click the trash icon on any line — it should be removed without errors
  6. Verify the counts update after removal

Related links

Replace act_window bindings with server actions that create the wizard
record before opening the form, so One2many line operations work
without "Please save your changes first" errors.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the batch approval wizard where One2many line operations, such as deleting rows, failed because the wizard was initialized in an unsaved state. The solution ensures that the wizard record is persisted to the database immediately upon its creation, thereby enabling all expected functionalities for its lines and improving the user experience for batch approvals.

Highlights

  • Wizard Creation Logic: Implemented a new create_from_selection method in the batch approval wizard to ensure the wizard record is saved to the database immediately upon creation, resolving issues with One2many line operations.
  • Action Type Migration: Migrated the batch approval, decline, and request changes actions from ir.actions.act_window to ir.actions.server to utilize the new create_from_selection method, which explicitly creates and saves the wizard.
  • One2many Line Deletion: Removed the custom action_remove_line button and its corresponding method, as Odoo's built-in One2many deletion now functions correctly due to the wizard being saved.
  • Test Updates: Updated existing unit tests to use the new create_from_selection flow for wizard instantiation, ensuring test coverage for the revised logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves the issue with deleting lines in the batch approval wizard by switching from default_get to a create_from_selection method called by server actions. This is a robust and standard Odoo approach for this kind of problem. The changes are well-implemented across the Python logic, XML views, and tests. The refactoring of the tests to use a helper method for wizard creation is a nice improvement for maintainability. I have one suggestion to improve internationalization by making error messages translatable.

Comment on lines +133 to 136
if change_request.approval_state != "pending":
return f"Not pending approval (state: {change_request.display_state})"
if not change_request.can_approve:
return "You are not authorized to approve this request"

Choose a reason for hiding this comment

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

medium

The error messages returned by this method are not translatable. To support internationalization, they should be wrapped in _(). The previous implementation had a note about avoiding this in default_get, but this concern is likely not applicable anymore now that the logic is in create_from_selection which is called from a server action.

Suggested change
if change_request.approval_state != "pending":
return f"Not pending approval (state: {change_request.display_state})"
if not change_request.can_approve:
return "You are not authorized to approve this request"
if change_request.approval_state != "pending":
return _("Not pending approval (state: %s)") % change_request.display_state
if not change_request.can_approve:
return _("You are not authorized to approve this request")

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.01%. Comparing base (a8efe28) to head (2c97d72).
⚠️ Report is 1 commits behind head on 19.0.

Files with missing lines Patch % Lines
...change_request_v2/wizards/batch_approval_wizard.py 93.75% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #130      +/-   ##
==========================================
+ Coverage   69.96%   70.01%   +0.04%     
==========================================
  Files         832      835       +3     
  Lines       48813    49139     +326     
==========================================
+ Hits        34154    34406     +252     
- Misses      14659    14733      +74     
Flag Coverage Δ
spp_api_v2_change_request 66.66% <ø> (ø)
spp_base_common 90.26% <ø> (ø)
spp_change_request_v2 74.50% <93.75%> (+0.63%) ⬆️
spp_cr_types_advanced 0.00% <ø> (ø)
spp_cr_types_base 0.00% <ø> (ø)
spp_dci_demo 69.23% <ø> (ø)
spp_farmer_registry_cr 61.15% <ø> (ø)
spp_farmer_registry_demo 54.01% <ø> (ø)
spp_mis_demo_v2 69.73% <ø> (-0.09%) ⬇️
spp_programs 45.51% <ø> (ø)
spp_security 66.66% <ø> (ø)
spp_starter_social_registry 0.00% <ø> (ø)
spp_starter_sp_mis 81.25% <ø> (ø)
spp_studio_change_requests 84.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...change_request_v2/wizards/batch_approval_wizard.py 49.21% <93.75%> (+16.14%) ⬆️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add tests for create_from_selection error paths, action types,
return value validation, error messages, and line removal.
Move tests that don't need pending CRs into a separate class so
they run even without approval definitions, improving patch coverage.
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.

1 participant