From ffb8b68c87ade14c740c474939d59bf562d82aa9 Mon Sep 17 00:00:00 2001 From: DavidJForgeFlow Date: Thu, 6 Oct 2022 15:28:51 +0200 Subject: [PATCH] [15.0][ADD] stock_inventory_adjustment --- .../odoo/addons/stock_inventory_adjustment | 1 + setup/stock_inventory_adjustment/setup.py | 6 + stock_inventory_adjustment/README.rst | 0 stock_inventory_adjustment/__init__.py | 1 + stock_inventory_adjustment/__manifest__.py | 13 ++ stock_inventory_adjustment/models/__init__.py | 3 + .../models/stock_inventory.py | 83 ++++++++++++ .../models/stock_move.py | 7 + .../models/stock_quant.py | 25 ++++ .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + stock_inventory_adjustment/readme/USAGE.rst | 6 + .../security/ir.model.access.csv | 3 + .../views/stock_inventory.xml | 124 ++++++++++++++++++ 14 files changed, 276 insertions(+) create mode 120000 setup/stock_inventory_adjustment/odoo/addons/stock_inventory_adjustment create mode 100644 setup/stock_inventory_adjustment/setup.py create mode 100644 stock_inventory_adjustment/README.rst create mode 100644 stock_inventory_adjustment/__init__.py create mode 100644 stock_inventory_adjustment/__manifest__.py create mode 100644 stock_inventory_adjustment/models/__init__.py create mode 100644 stock_inventory_adjustment/models/stock_inventory.py create mode 100644 stock_inventory_adjustment/models/stock_move.py create mode 100644 stock_inventory_adjustment/models/stock_quant.py create mode 100644 stock_inventory_adjustment/readme/CONTRIBUTORS.rst create mode 100644 stock_inventory_adjustment/readme/DESCRIPTION.rst create mode 100644 stock_inventory_adjustment/readme/USAGE.rst create mode 100644 stock_inventory_adjustment/security/ir.model.access.csv create mode 100644 stock_inventory_adjustment/views/stock_inventory.xml diff --git a/setup/stock_inventory_adjustment/odoo/addons/stock_inventory_adjustment b/setup/stock_inventory_adjustment/odoo/addons/stock_inventory_adjustment new file mode 120000 index 000000000000..e42be3793e17 --- /dev/null +++ b/setup/stock_inventory_adjustment/odoo/addons/stock_inventory_adjustment @@ -0,0 +1 @@ +../../../../stock_inventory_adjustment \ No newline at end of file diff --git a/setup/stock_inventory_adjustment/setup.py b/setup/stock_inventory_adjustment/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_inventory_adjustment/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_inventory_adjustment/README.rst b/stock_inventory_adjustment/README.rst new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stock_inventory_adjustment/__init__.py b/stock_inventory_adjustment/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_inventory_adjustment/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_inventory_adjustment/__manifest__.py b/stock_inventory_adjustment/__manifest__.py new file mode 100644 index 000000000000..f42afaa82c7e --- /dev/null +++ b/stock_inventory_adjustment/__manifest__.py @@ -0,0 +1,13 @@ +{ + "name": "Stock Inventory Adjustment", + "version": "15.0.1.1.0", + "license": "LGPL-3", + "category": "Inventory/Inventory", + "summary": "Allows to do an easier follow up of the Inventory Adjustments", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": ["stock"], + "data": ["security/ir.model.access.csv", "views/stock_inventory.xml"], + "installable": True, + "application": False, +} diff --git a/stock_inventory_adjustment/models/__init__.py b/stock_inventory_adjustment/models/__init__.py new file mode 100644 index 000000000000..6821f95db0d1 --- /dev/null +++ b/stock_inventory_adjustment/models/__init__.py @@ -0,0 +1,3 @@ +from . import stock_inventory +from . import stock_quant +from . import stock_move diff --git a/stock_inventory_adjustment/models/stock_inventory.py b/stock_inventory_adjustment/models/stock_inventory.py new file mode 100644 index 000000000000..d03cf192ca3c --- /dev/null +++ b/stock_inventory_adjustment/models/stock_inventory.py @@ -0,0 +1,83 @@ +import datetime + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class InventoryAdjustmentsGroup(models.Model): + _name = "stock.inventory" + _description = "Inventory Adjustment Group" + _order = "state, id desc" + + name = fields.Char(required=True) + + date = fields.Datetime(default=datetime.date.today()) + + state = fields.Selection( + [("2", "Draft"), ("1", "In Progress"), ("3", "Done")], default="2" + ) + + location_ids = fields.Many2many( + "stock.location", string="Location", domain="[('usage', '=', 'internal')]" + ) + + product_selection = fields.Selection( + [("all", "All Products"), ("manual", "Manual Selection")], + default="all", + required=True, + ) + + stock_quant_ids = fields.Many2many("stock.quant", string="Inventory Adjustment") + + stock_move_ids = fields.One2many( + "stock.move", "inventory_adjustment_id", string="Inventory Adjustments Done" + ) + + count_stock_quants = fields.Integer(compute="_compute_count_stock_quants") + + count_stock_moves = fields.Integer(compute="_compute_count_stock_moves") + + @api.depends("stock_quant_ids") + def _compute_count_stock_quants(self): + self.count_stock_quants = len(self.stock_quant_ids) + + @api.depends("stock_move_ids") + def _compute_count_stock_moves(self): + sm_ids = self.mapped("stock_move_ids").ids + self.count_stock_moves = len(sm_ids) + + def action_state_to_in_progress(self): + active_rec = self.env["stock.inventory"].search([("state", "=", "1")]) + if active_rec: + raise ValidationError( + _("There's already an Adjustment in Process: %s") % active_rec.name + ) + self.state = "1" + if self.product_selection == "all": + for location_id in self._origin.location_ids: + self.stock_quant_ids += self.env["stock.quant"].search( + [("location_id", "=", location_id.id)] + ) + return + + def action_state_to_done(self): + self.state = "3" + return + + def action_state_to_draft(self): + self.state = "2" + self.stock_quant_ids = None + return + + def action_view_inventory_adjustment(self): + result = self.env["stock.quant"].action_view_inventory() + ia_ids = self.mapped("stock_quant_ids").ids + result["domain"] = [("id", "in", ia_ids)] + return result + + def action_view_stock_moves(self): + result = self.env["ir.actions.actions"]._for_xml_id("stock.stock_move_action") + sm_ids = self.mapped("stock_move_ids").ids + result["domain"] = [("id", "in", sm_ids)] + result["context"] = [] + return result diff --git a/stock_inventory_adjustment/models/stock_move.py b/stock_inventory_adjustment/models/stock_move.py new file mode 100644 index 000000000000..94e22561d98e --- /dev/null +++ b/stock_inventory_adjustment/models/stock_move.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + inventory_adjustment_id = fields.Many2one("stock.inventory") diff --git a/stock_inventory_adjustment/models/stock_quant.py b/stock_inventory_adjustment/models/stock_quant.py new file mode 100644 index 000000000000..b646d99eefd3 --- /dev/null +++ b/stock_inventory_adjustment/models/stock_quant.py @@ -0,0 +1,25 @@ +from odoo import models + + +class StockQuant(models.Model): + _inherit = "stock.quant" + + def _apply_inventory(self): + res = super()._apply_inventory() + record_moves = self.env["stock.move"] + adjustment = self.env["stock.inventory"].search([("state", "=", "1")]) + for rec in self: + moves = record_moves.search( + [ + ("product_id", "=", rec.product_id.id), + ("company_id", "=", rec.company_id.id), + "|", + ("location_id", "=", rec.location_id.id), + ("location_dest_id", "=", rec.location_id.id), + ] + ) + move = moves[len(moves) - 1] + adjustment.stock_move_ids += move + move.inventory_adjustment_id = adjustment + + return res diff --git a/stock_inventory_adjustment/readme/CONTRIBUTORS.rst b/stock_inventory_adjustment/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..95cc88de027e --- /dev/null +++ b/stock_inventory_adjustment/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow `_: + + * David Jiménez diff --git a/stock_inventory_adjustment/readme/DESCRIPTION.rst b/stock_inventory_adjustment/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..ca91fe8f2dd0 --- /dev/null +++ b/stock_inventory_adjustment/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to group Inventory Adjustments and have a group traceability (like before Odoo 15.0). diff --git a/stock_inventory_adjustment/readme/USAGE.rst b/stock_inventory_adjustment/readme/USAGE.rst new file mode 100644 index 000000000000..556dca26538b --- /dev/null +++ b/stock_inventory_adjustment/readme/USAGE.rst @@ -0,0 +1,6 @@ +Go to Inventory / Operations / Inventory Adjustments. Here you can see the list of Adjustment Grouped. +If you create a new Group, you can choose 2 types of product selection: +- All Products (all products from theselected locations) +- Manual Selection (choose manually each product in location). +When you start the adjustment (only one at a time) clicking on adjustments gets you to the view where adjustments are made. +From the group view, if you click on Stock Moves you can see the movements done (includes the 0 qty moves). diff --git a/stock_inventory_adjustment/security/ir.model.access.csv b/stock_inventory_adjustment/security/ir.model.access.csv new file mode 100644 index 000000000000..0dd1ae475bd3 --- /dev/null +++ b/stock_inventory_adjustment/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_stock_inventory_user,stock.inventory,model_stock_inventory,base.group_user,1,0,0,0 +access_stock_inventory_manager,stock.inventory,model_stock_inventory,base.group_system,1,1,1,1 diff --git a/stock_inventory_adjustment/views/stock_inventory.xml b/stock_inventory_adjustment/views/stock_inventory.xml new file mode 100644 index 000000000000..ff34f7524c14 --- /dev/null +++ b/stock_inventory_adjustment/views/stock_inventory.xml @@ -0,0 +1,124 @@ + + + + stock.inventory.form.view + stock.inventory + 1000 + +
+
+
+ + +
+ + +
+
+

+ +

+
+ + + + + + + + + + + + + + + + + + +
+
+
+
+ + + stock.inventory.tree.view + stock.inventory + 1000 + + + + + + + + + + Inventory Adjustment Group + stock.inventory + tree,form + + + + + +