From dbedf6145fcfe084bf9111455669c462d67c422e Mon Sep 17 00:00:00 2001 From: "Kevin.roche" Date: Mon, 29 Nov 2021 13:24:24 +0100 Subject: [PATCH] [ADD] stock_reception_usability --- stock_reception_usability/__init__.py | 1 + stock_reception_usability/__manifest__.py | 24 ++++++++++++ stock_reception_usability/models/__init__.py | 2 + .../models/stock_move.py | 36 ++++++++++++++++++ .../models/stock_picking.py | 38 +++++++++++++++++++ .../views/stock_picking.xml | 27 +++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 stock_reception_usability/__init__.py create mode 100644 stock_reception_usability/__manifest__.py create mode 100644 stock_reception_usability/models/__init__.py create mode 100644 stock_reception_usability/models/stock_move.py create mode 100644 stock_reception_usability/models/stock_picking.py create mode 100644 stock_reception_usability/views/stock_picking.xml diff --git a/stock_reception_usability/__init__.py b/stock_reception_usability/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/stock_reception_usability/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_reception_usability/__manifest__.py b/stock_reception_usability/__manifest__.py new file mode 100644 index 0000000..5cf9773 --- /dev/null +++ b/stock_reception_usability/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Kévin Roche +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock relation usability", + "summary": "SUMMARY", + "version": "14.0.1.0.0", + "category": "Inventory, Logistic, Storage", + "website": "http://www.akretion.com", + "author": "Akretion", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "stock", + "purchase", + ], + "data": [ + "views/stock_picking.xml", + ], + "demo": [], + "qweb": [], +} diff --git a/stock_reception_usability/models/__init__.py b/stock_reception_usability/models/__init__.py new file mode 100644 index 0000000..a33bde1 --- /dev/null +++ b/stock_reception_usability/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_move +from . import stock_picking diff --git a/stock_reception_usability/models/stock_move.py b/stock_reception_usability/models/stock_move.py new file mode 100644 index 0000000..bba5408 --- /dev/null +++ b/stock_reception_usability/models/stock_move.py @@ -0,0 +1,36 @@ +# Copyright (C) 2021 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + location_dest_list = fields.Text( + string="Locations", compute="_compute_locations_dest_list" + ) + + @api.depends( + "move_line_ids", "move_line_ids.location_dest_id", "move_line_ids.qty_done" + ) + def _compute_locations_dest_list(self): + for move in self: + data = [] + separator = ", " + dest_list = move.move_line_ids.location_dest_id + for dest in dest_list: + lines_qty = move.move_line_ids.search( + [("move_id", "=", move.id), ("location_dest_id", "=", dest.id)] + ).mapped("qty_done") + quantity = int(sum(lines_qty)) + location = dest.name + data.append("{}: {}".format(quantity, location)) + move.location_dest_list = separator.join(data) + + def _compute_is_quantity_done_editable(self): + super()._compute_is_quantity_done_editable() + for move in self: + if len(move.move_line_ids) == 1 and move.show_details_visible: + move.is_quantity_done_editable = True diff --git a/stock_reception_usability/models/stock_picking.py b/stock_reception_usability/models/stock_picking.py new file mode 100644 index 0000000..cd6b75c --- /dev/null +++ b/stock_reception_usability/models/stock_picking.py @@ -0,0 +1,38 @@ +# Copyright (C) 2021 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def action_fill_quantity_done(self): + self.ensure_one() + for move in self.move_ids_without_package: + if move.move_line_ids: + first_line = move.move_line_ids[0] + else: + first_line = False + if move.quantity_done == 0 and first_line: + qty = move.product_uom_qty + if first_line.qty_done == 0: + first_line.write( + { + "qty_done": qty, + } + ) + elif move.quantity_done < move.product_uom_qty or ( + move.quantity_done == 0 and not first_line + ): + qty = move.product_uom_qty - move.quantity_done + self.env["stock.move.line"].create( + { + "move_id": move.id, + "location_dest_id": move.location_dest_id.id, + "location_id": move.location_id.id, + "product_uom_id": move.product_uom.id, + "qty_done": qty, + } + ) diff --git a/stock_reception_usability/views/stock_picking.xml b/stock_reception_usability/views/stock_picking.xml new file mode 100644 index 0000000..c59ee62 --- /dev/null +++ b/stock_reception_usability/views/stock_picking.xml @@ -0,0 +1,27 @@ + + + + stock.picking + + + + + + + {'column_invisible': [('parent.state', '=', 'done')]} + + + + + + + +