Maintainers
+Maintainers
This module is maintained by the OCA.
@@ -428,5 +433,6 @@ diff --git a/hr_personal_equipment_stock/README.rst b/hr_personal_equipment_stock/README.rst index 5b408ff1a8f..0fc56903959 100644 --- a/hr_personal_equipment_stock/README.rst +++ b/hr_personal_equipment_stock/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + =========================== Hr Personal Equipment Stock =========================== @@ -13,7 +17,7 @@ Hr Personal Equipment Stock .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github diff --git a/hr_personal_equipment_stock/models/hr_personal_equipment.py b/hr_personal_equipment_stock/models/hr_personal_equipment.py index 3840031c47e..548df98d083 100644 --- a/hr_personal_equipment_stock/models/hr_personal_equipment.py +++ b/hr_personal_equipment_stock/models/hr_personal_equipment.py @@ -30,6 +30,9 @@ class HrPersonalEquipment(models.Model): "stock.move", "personal_equipment_id", string="Stock Moves" ) skip_procurement = fields.Boolean(compute="_compute_skip_procurement") + lot_ids = fields.Many2many( + "stock.lot", compute="_compute_lot_ids", string="Serial Numbers" + ) @api.depends("state", "product_id", "product_id.type") def _compute_skip_procurement(self): @@ -41,18 +44,61 @@ def _compute_skip_procurement(self): "move_ids.scrapped", "move_ids.product_uom_qty", "move_ids.product_uom", + "equipment_request_id.picking_ids.move_ids.scrapped", + "equipment_request_id.picking_ids.move_ids.state", ) def _compute_qty_delivered(self): for line in self: qty = 0.0 - for move in line.move_ids.filtered( - lambda r: r.state == "done" and line.product_id == r.product_id - ): - qty += move.product_uom._compute_quantity( - move.product_uom_qty, line.product_uom_id - ) + dest_location = line.location_id + moves = line.move_ids.filtered( + lambda move: move.state == "done" and move.product_id == line.product_id + ) + line.equipment_request_id.picking_ids.move_ids.filtered( + lambda move: move.scrapped + and move.state == "done" + and move.product_id == line.product_id + ) + for move in moves: + moved_qty = move.quantity_done + if move.location_dest_id == dest_location: + qty += moved_qty + elif move.location_id == dest_location: + qty -= moved_qty line.qty_delivered = qty + @api.depends( + "move_ids.lot_ids", + "equipment_request_id.picking_ids.move_ids.scrapped", + "equipment_request_id.picking_ids.move_ids.state", + ) + def _compute_lot_ids(self): + for line in self: + qty_by_lot = {} + dest_location = line.location_id + moves = line.move_ids.filtered( + lambda move: move.state == "done" and move.product_id == line.product_id + ) + line.equipment_request_id.picking_ids.move_ids.filtered( + lambda move: move.scrapped + and move.state == "done" + and move.product_id == line.product_id + ) + for move in moves: + for move_line in move.move_line_ids: + lot = move_line.lot_id + if lot not in qty_by_lot: + qty_by_lot[lot] = 0 + moved_qty = move_line.qty_done + if move.location_dest_id == dest_location: + qty_by_lot[lot] += moved_qty + elif move.location_id == dest_location: + qty_by_lot[lot] -= moved_qty + + lots = self.env["stock.lot"].browse() + for lot, moved in qty_by_lot.items(): + if moved > 0: + lots |= lot + line.lot_ids = lots + def _skip_procurement(self): return self.product_id.type not in ("consu", "product") diff --git a/hr_personal_equipment_stock/static/description/index.html b/hr_personal_equipment_stock/static/description/index.html index 563e4bce53f..6e0c5a47090 100644 --- a/hr_personal_equipment_stock/static/description/index.html +++ b/hr_personal_equipment_stock/static/description/index.html @@ -3,7 +3,7 @@
-This module integrates stock with hr_personal_equipment_request module. When the equipment request is accepted, a stock request is generated and a “stock.move” is created for each request line. If the “stock.move” is marked as done, the corresponding allocations are marked as valid if the quantity_delivered is equal to the requested quantity. @@ -389,11 +394,11 @@
This module is auto installed if the modules “hr_personal_equipment_request” and “stock” are installed.
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -401,21 +406,21 @@
Do not contact contributors directly about support or help with technical issues.