Repository navigation
Conversation
a8dde6c to
2342555
Compare
2342555 to
36f1dbc
Compare
| move.quantity = allocation.quantity | ||
| move.picked = True | ||
| move.lot_ids = [lot_id.id for lot_id in lot_ids] | ||
| move.quantity = allocation.quantity |
There was a problem hiding this comment.
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.quantityThere was a problem hiding this comment.
Apologies on missing them while resolving conflicts. Updated now
| 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 |
There was a problem hiding this comment.
chore: move.quantity is assigned twice here too
| <field | ||
| name="lot_ids" | ||
| widget="many2many_tags" | ||
| attrs="{'column_invisible': [('parent.state', '!=', 'accepted')]}" |
There was a problem hiding this comment.
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
attrsandstatesare no longer used.
There was a problem hiding this comment.
Missed to remove attrs. Updated now
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
As scrapped condition is removed and using all moves from pickings, updated comment as per latest code
| and ( | ||
| move.lot_ids in line.move_ids.lot_ids | ||
| if line.move_ids.lot_ids | ||
| else True | ||
| ) |
There was a problem hiding this comment.
suggestion: Maybe we can drop the lots condition while computing the delivered quantity, what do you think?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, comment would be useful to know the usecase. Added comment as suggested
| ) | ||
| ) | ||
| for move in moves: | ||
| moved_qty = move.quantity |
There was a problem hiding this comment.
issue: The moves might have a different UoM for this quantity, please keep the quantity conversion that was here
hr/hr_personal_equipment_stock/models/hr_personal_equipment.py
Lines 51 to 53 in 96c6ad7
There was a problem hiding this comment.
Udpated using quantity conversion while computing qty_delivered
| 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 | ||
| ) | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Introduced common method to filter moves which is used by both computation methods
28ce3ab to
e970876
Compare
SirPyTech
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
| 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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| move.quantity = allocation.quantity | ||
| move.picked = True | ||
| move.lot_ids = [lot_id.id for lot_id in lot_ids] | ||
| move.quantity = allocation.quantity |
| 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 |
| <field | ||
| name="lot_ids" | ||
| widget="many2many_tags" | ||
| attrs="{'column_invisible': [('parent.state', '!=', 'accepted')]}" |
| and ( | ||
| move.lot_ids in line.move_ids.lot_ids | ||
| if line.move_ids.lot_ids | ||
| else True | ||
| ) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
suggestion: allocation is the same model as self so the argument is not really needed, please just use self.
There was a problem hiding this comment.
Agree, should have handled using self. Updated as suggested
| moved_qty = move.quantity | ||
| moved_qty = move.product_uom._compute_quantity( | ||
| move.product_uom_qty, line.product_uom_id | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
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.
e970876 to
efe4ea6
Compare
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.
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