Skip to content

[FW][IMP] hr_personal_equipment_stock: Enhance PPE view - #1643

Open
anusriNPS wants to merge 3 commits into
OCA:18.0from
PyTech-SRL:18-port-from-16-hr_personal_equipment_stock
Open

anusriNPS wants to merge 3 commits into
OCA:18.0from
PyTech-SRL:18-port-from-16-hr_personal_equipment_stock

Conversation

@anusriNPS

@anusriNPS anusriNPS commented Oct 30, 2026 •

Copy link
Copy Markdown

FW from 16.0 - #1497

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

  1. Introduced lot_ids as computed field which helps to update serial number even when pickings are duplicated.
  2. 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.

Introduced improvements based on comments in a seperate commit such as usage of common method for filtering moves and using quantity conversion while computing qty_delivered. Same has been backported in 16.0 as part of PR #1668

@OCA-git-bot OCA-git-bot added series:18.0 mod:hr_personal_equipment_stock Module hr_personal_equipment_stock labels Oct 30, 2026
@anusriNPS
anusriNPS marked this pull request as draft October 30, 2026 14:05
@anusriNPS anusriNPS changed the title [FW][IMP] hr_personal_equipment_stock: Port PR from 16.0 [FW][IMP] hr_personal_equipment_stock: Enhance PPE view Nov 4, 2026
@anusriNPS
anusriNPS force-pushed the 18-port-from-16-hr_personal_equipment_stock branch from a8dde6c to 2342555 Compare November 10, 2026 14:12
@anusriNPS
anusriNPS marked this pull request as ready for review November 10, 2026 14:28
@anusriNPS
anusriNPS force-pushed the 18-port-from-16-hr_personal_equipment_stock branch from 2342555 to 36f1dbc Compare November 10, 2026 14:40

@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 porting this change, some of the comments are related to the porting itself, but others are new things I didn't notice in #1497: please create new commits for those so they can be easily backported if needed.

Comment on lines +189 to +192
move.quantity = allocation.quantity
move.picked = True
move.lot_ids = [lot_id.id for lot_id in lot_ids]
move.quantity = allocation.quantity

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chore: move.quantity is assigned twice, please just assign the lots before assigning the quantity like in 32fd0b2#diff-f2ba74e7472daf9fb29393989682450994844a4acad1601ec1b33b38f8055d7fR188:

         move = allocation.move_ids[0]
+        move.lot_ids = [lot_id.id for lot_id in lot_ids]
         move.quantity_done = allocation.quantity

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.

Apologies on missing them while resolving conflicts. Updated now

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

Comment on lines +233 to +236
move.quantity = allocation.quantity - 1
move.picked = True
move.lot_ids = [lot_ids[index].id for index in range(allocation.quantity - 1)]
move.quantity = allocation.quantity - 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chore: move.quantity is assigned twice here too

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.

Updated 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.

👍🏻️

<field
name="lot_ids"
widget="many2many_tags"
attrs="{'column_invisible': [('parent.state', '!=', 'accepted')]}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chore: attrs should not be used anymore since 17.0, see https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-17.0:

The XML attributes attrs and states are no longer used.

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.

Missed to remove attrs. Updated now

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

lambda move, line=line: move.state == "done"
and move.product_id == line.product_id
) | line.equipment_request_id.picking_ids.move_ids.filtered(
lambda move, line=line: move.scrapped

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

question: Please remind me, why do we only want scrapped moves from the pickings?
If there is no specific reason, we can remove this condition.

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.

If a user uses scrap button in pickings view to scrap any of the item, then scraps moves created is linked with line.equipment_request_id.picking_ids.move_ids . Scrapped products are moved to scrap location, so this scrapped move as well needs to be taken into account while computing qty_delivered and lot_ids which helps to obtain proper values for lot_ids and qty_delivered

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 explanation! Please add a comment in the code so it's directly more clear to whoever reads it; if I understood correctly it could be something like

Scrapped moves are not linked directly to the current line
because they are generated from the pickings

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.

As scrapped condition is removed and using all moves from pickings, updated comment as per latest code

Comment on lines 60 to 64
and (
move.lot_ids in line.move_ids.lot_ids
if line.move_ids.lot_ids
else True
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Maybe we can drop the lots condition while computing the delivered quantity, what do you think?

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.

This lots condition was included to handle usecase: When two allocations with same product used in the same PPE request, if any one of the allocation is scrapped from picking then it results in negative value. So, lot_ids were required to differentiate scrapped moves between same products.

Included based on discussion: https://gitlab.nps100.com/odoo/nps-odoo/-/merge_requests/806#note_212583

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Right, the problem is that we don't know which scrap is linked to the current line, it's a bit annoying to look for the correct move according to some heuristic (product and lot) instead of having a direct relation, but since currently there is none it's fine to keep the check on lots.
Thanks for the clarification, please add a comment in the code explaining this for the future devs.

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.

Yes, comment would be useful to know the usecase. Added comment as suggested

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

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: The moves might have a different UoM for this quantity, please keep the quantity conversion that was here

qty += move.product_uom._compute_quantity(
move.product_uom_qty, line.product_uom_id
)

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.

Udpated using quantity conversion while computing qty_delivered

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

Comment on lines +53 to +65
moves = line.move_ids.filtered(
lambda move, line=line: move.state == "done"
and move.product_id == line.product_id
) | line.equipment_request_id.picking_ids.move_ids.filtered(
lambda move, line=line: move.scrapped
and move.state == "done"
and move.product_id == line.product_id
and (
move.lot_ids in line.move_ids.lot_ids
if line.move_ids.lot_ids
else True
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: These moves are the same we gathered for computing the moved lots, please extract a common method that returns the moves we are interested in instead of repeating the code.

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.

Introduced common method to filter moves which is used by both computation methods

@anusriNPS
anusriNPS force-pushed the 18-port-from-16-hr_personal_equipment_stock branch 2 times, most recently from 28ce3ab to e970876 Compare November 12, 2026 14:53

@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 changes 🙏
I think a few more edits are needed, and then we'll be good to go 🚀

lambda move, line=line: move.state == "done"
and move.product_id == line.product_id
) | line.equipment_request_id.picking_ids.move_ids.filtered(
lambda move, line=line: move.scrapped

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 explanation! Please add a comment in the code so it's directly more clear to whoever reads it; if I understood correctly it could be something like

Scrapped moves are not linked directly to the current line
because they are generated from the pickings

Comment on lines +68 to +71
moves = line.move_ids.filtered(
lambda move, line=line: move.state == "done"
and move.product_id == line.product_id
) | line.equipment_request_id.picking_ids.move_ids.filtered(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

thought: Checking the behavior you explained in #1643 (comment), I noticed that all the moves linked to line are already linked to one of the pickings in the request:

>>> req = env["hr.personal.equipment.request"].browse(3)
hr.personal.equipment.request(3,)
>>> req.line_ids.move_ids
stock.move(48,)
>>> req.picking_ids.move_ids
stock.move(48, 49)

(Move 49 is a scrap)
, so maybe we could only look at the moves in the pickings, what do you think?

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, all moves including scraps available under picking moves linked to PPE request. So, using only picking moves to filter required moves to compute lot_ids and qty_delivered

Comment on lines +189 to +192
move.quantity = allocation.quantity
move.picked = True
move.lot_ids = [lot_id.id for lot_id in lot_ids]
move.quantity = allocation.quantity

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

Comment on lines +233 to +236
move.quantity = allocation.quantity - 1
move.picked = True
move.lot_ids = [lot_ids[index].id for index in range(allocation.quantity - 1)]
move.quantity = allocation.quantity - 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

<field
name="lot_ids"
widget="many2many_tags"
attrs="{'column_invisible': [('parent.state', '!=', 'accepted')]}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍🏻️

Comment on lines 60 to 64
and (
move.lot_ids in line.move_ids.lot_ids
if line.move_ids.lot_ids
else True
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Right, the problem is that we don't know which scrap is linked to the current line, it's a bit annoying to look for the correct move according to some heuristic (product and lot) instead of having a direct relation, but since currently there is none it's fine to keep the check on lots.
Thanks for the clarification, please add a comment in the code explaining this for the future devs.

for record in self:
record.skip_procurement = record._skip_procurement()

def _filter_allocation_moves(self, allocation):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: allocation is the same model as self so the argument is not really needed, please just use self.

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, should have handled using self. Updated as suggested

Comment on lines +67 to +72
moved_qty = move.quantity
moved_qty = move.product_uom._compute_quantity(
move.product_uom_qty, line.product_uom_id
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chore: This goes into a FIX commit or even better, squashed in the same commit that introduced the issue described in #1643 (comment).
The rest of the commit (extracting a method) should be a REF.

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, REF would be the appropriate tag here. Updated commit with REF tag and included quantity conversion in FIX commit which take cares of qty_delivered computation

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

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

   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.
quantity conversion is also taken care while computing qty_delivered.
   Refactored computation method of qty_delivered and
lot_ids to use common methods for same logic.
@anusriNPS
anusriNPS force-pushed the 18-port-from-16-hr_personal_equipment_stock branch from e970876 to efe4ea6 Compare November 17, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:hr_personal_equipment_stock Module hr_personal_equipment_stock series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants