Skip to content

[16.0][IMP] hr_personal_equipment_stock: Enhance PPE view - #1497

Open
anusriNPS wants to merge 3 commits into
OCA:16.0from
PyTech-SRL:16.0-enhance-ppe-view
Open

anusriNPS wants to merge 3 commits into
OCA:16.0from
PyTech-SRL:16.0-enhance-ppe-view

Conversation

@anusriNPS

@anusriNPS anusriNPS commented Aug 4, 2025 •

Copy link
Copy Markdown

Display serial number under "Personal Equipment" Tab
in Personal Equipment request form view when Personal Equipment Request is in "Accepted" state.

  • Introduced lot_ids as computed field which helps to update serial number even when pickings are duplicated.
  • Corrected qty_delivered field to be uptodate based on stock availability in PPE location which helps to avoid wrong field updation when an allocation is returned from pickings or pickings are duplicated.

Included commit from 18.0 to backport refactored changes.

@quirino95 quirino95 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code and functional review: LGTM

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@quirino95

Copy link
Copy Markdown

@OCA/human-resources-maintainers we've been using this successfully in production for a couple of months now. Could you please take a look? Thanks!

@alexey-pelykh alexey-pelykh 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.

The functional intent is sound -- showing serial/lot numbers on accepted equipment requests is useful. However, three issues need addressing:

  1. The hr_personal_equipment_request/static/description/index.html change is a regenerated README from a different module and should be dropped from this PR.
  2. OCA convention requires a version bump in __manifest__.py for IMP-type changes (e.g., 16.0.1.0.0 -> 16.0.1.1.0).
  3. No tests cover the new lot_ids related field. At minimum, a test should verify the field is populated correctly when stock moves with lots are created via the equipment request flow.

@anusriNPS
anusriNPS force-pushed the 16.0-enhance-ppe-view branch 2 times, most recently from 9eb3142 to 58a99fb Compare March 11, 2026 10:01

@marcos-mendez marcos-mendez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated Review -- Tests Failed

1. Root Cause

The test failure occurs because the stock.move is not properly linked to the stock.lot records during the test setup. Specifically, the lot_ids field on the stock.move is not correctly assigned, leading to an inconsistency between allocation.lot_ids and allocation.move_ids.lot_ids.

2. Suggested Fix

In test_compute_qty_delivered and related tests, ensure that move.lot_ids is correctly assigned using the write method or by directly assigning the recordset to move.lot_ids. Also, in the test_action_cancel_without_qty_delivered, the assignment of move.lot_ids should be done correctly to reflect actual serial numbers used in the test.

File: hr_personal_equipment_stock/tests/test_hr_personal_equipment_stock.py
Lines: Around 175, 218, and 232

Change:

move.lot_ids = [lot_id.id for lot_id in lot_ids]

to:

move.write({'lot_ids': [(6, 0, [lot_id.id for lot_id in lot_ids])]})

This ensures the many2many relationship is properly written to the database.

3. Additional Code Issues

  • Missing error handling in _create_lot_ids: The function assumes product.product_variant_id exists and is valid, but no check is performed. This could cause runtime errors if product has no variants.

    Suggested fix:

    if not product.product_variant_id:
        raise UserError("Product must have a variant to create lots.")
  • Potential performance issue in _create_lot_ids: Creating many records in a loop without batching may cause performance degradation in large-scale tests.

    Suggested improvement:
    Use self.env["stock.lot"].create() with a list of dictionaries for better performance.

4. Test Improvements

Add the following test cases to improve coverage:

  • Test with product tracking = 'none': Ensure lot_ids is empty when no tracking is enabled.
  • Test with multiple serial numbers per move: Validate that multiple lots can be assigned to a single move.
  • Test lot_ids on cancelled moves: Confirm that lot_ids are cleared when a move is cancelled.
  • Test with lot_ids after backorder creation: Ensure that lot_ids are correctly propagated in backorders.

Use OCA patterns:

  • Use TransactionCase for tests involving data creation and manipulation.
  • Tag tests using @tag('post_install', 'manual') if they require installation steps.
  • Use SavepointCase for tests that need database isolation, especially when dealing with stock.move and stock.lot relationships.

Example:

@tag('post_install', 'manual')
def test_lot_ids_with_tracking_none(self):
    self.product_personal_equipment_1.tracking = 'none'
    self.personal_equipment_request.accept_request()
    allocation = self.personal_equipment_request.line_ids[0]
    self.assertFalse(allocation.lot_ids)

This will ensure that the module behaves correctly under various tracking configurations.


⚠️ PR Aging Alert: CRITICAL

This PR by @anusriNPS has been waiting for 223 days — that is over 7 months without being merged or closed.

Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)


Reciprocal Review Request

Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):

My open PRs across OCA:

Reviewing each other's work helps the whole community move forward. Thank you!


Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

@alexey-pelykh alexey-pelykh 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.

Re-reviewing after the update — good progress:

  1. Stray hr_personal_equipment_request file — ✅ Removed from the PR. All changes now scoped to hr_personal_equipment_stock.
  2. Tests for lot_ids — ✅ Comprehensive coverage added: lot creation helper, lot assignment verification on delivery, lot clearing on cancel, partial delivery with lots. Well done.
  3. Version bump — Still missing. OCA convention requires bumping the minor version for IMP changes (e.g., 16.0.1.0.0 → 16.0.1.1.0). Can be done at merge time if needed.

All CI green. The functional change and tests are solid.

Co-Reviewed-By: Claude Opus 4.6 (1M context) [email protected]

@marcos-mendez marcos-mendez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@WesleyOliveira98 WesleyOliveira98 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@BhaveshHeliconia BhaveshHeliconia 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.

LGTM!

@anusriNPS
anusriNPS force-pushed the 16.0-enhance-ppe-view branch from 58a99fb to 7bf9eae Compare June 25, 2026 15:57
@OCA-git-bot OCA-git-bot added series:16.0 mod:hr_personal_equipment_stock Module hr_personal_equipment_stock labels Jun 25, 2026
@anusriNPS

Copy link
Copy Markdown
Author

Note: Using lot_ids (i.e. many2many) as related fields does not update lot id values when pickings are duplicated. Hence, modified lot_ids as a computed field

@SirPyTech SirPyTech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the PR!
I reviewed the code and tried it locally, everything looks good 👏

@SirPyTech

Copy link
Copy Markdown

@OCA/human-resources-maintainers this has more than enough reviews, can someone please have a look? Thanks!

@anusriNPS
anusriNPS force-pushed the 16.0-enhance-ppe-view branch 3 times, most recently from 936d66a to d662ccb Compare September 3, 2026 03:26

@SirPyTech SirPyTech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for implementing the simpler approach I proposed in PyTech-SRL#1 🙏
I only noticed a small issue (coming from my own proposal 😅), please check

@SirPyTech SirPyTech mentioned this pull request Sep 7, 2026
@anusriNPS
anusriNPS force-pushed the 16.0-enhance-ppe-view branch from d662ccb to 1023139 Compare September 9, 2026 14:12

@SirPyTech SirPyTech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good now, thanks!

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@SirPyTech

Copy link
Copy Markdown

@SirPyTech Can you check this PR? If ready, we will merge

Originally posted by @Saran440 in #1497 (comment)

This is ready from almost 2 months and has a bunch of approvals, please have a look, thanks!
cc @OCA/human-resources-maintainers

@SirPyTech SirPyTech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for aligning this to the 18.0 version, I noticed one small change that is still missing, please check.

)
)
for move in moves:
moved_qty = move.quantity_done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: Please convert the quantity as mentioned in #1643 (comment).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agree, while porting back refactored changes, missed to include quantity conversion

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

lot = move_line.lot_id
if lot not in qty_by_lot:
qty_by_lot[lot] = 0
moved_qty = move_line.qty_done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: Please convert the quantity as mentioned in #1643 (comment).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Implemented quantity conversion as required

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

   Display serial number under "Personal Equipment" Tab
in Personal Equipment request form view when Personal
Equipment Request is in "Accepted" state.
   Using proper values for qty_delivered based on stock availability
when a picking associated with allocation is validated/returned/scrapped.
   Refactored computation method of qty_delivered and
lot_ids to use common methods for same logic.
@anusriNPS
anusriNPS force-pushed the 16.0-enhance-ppe-view branch from d4d4b22 to e7a51b3 Compare November 24, 2026 10:44

@SirPyTech SirPyTech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks!
I have suggested a few more changes in the 18.0 porting (#1643 (review)) but it's fine to keep them only in there.

)
)
for move in moves:
moved_qty = move.quantity_done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

lot = move_line.lot_id
if lot not in qty_by_lot:
qty_by_lot[lot] = 0
moved_qty = move_line.qty_done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants