Skip to content

Commit

Permalink
[15.0][ADD] stock_group_inventory_adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJForgeFlow committed Oct 24, 2022
1 parent 7880648 commit 1a4afb0
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_inventory_adjustment/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Empty file.
1 change: 1 addition & 0 deletions stock_inventory_adjustment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions stock_inventory_adjustment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
3 changes: 3 additions & 0 deletions stock_inventory_adjustment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_inventory
from . import stock_quant
from . import stock_move
83 changes: 83 additions & 0 deletions stock_inventory_adjustment/models/stock_inventory.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions stock_inventory_adjustment/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class StockMove(models.Model):
_inherit = "stock.move"

inventory_adjustment_id = fields.Many2one("stock.inventory")
25 changes: 25 additions & 0 deletions stock_inventory_adjustment/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions stock_inventory_adjustment/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `ForgeFlow <https://www.forgeflow.com>`_:

* David Jiménez
1 change: 1 addition & 0 deletions stock_inventory_adjustment/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to group Inventory Adjustments and have a group traceability (like before Odoo 15.0).
6 changes: 6 additions & 0 deletions stock_inventory_adjustment/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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).
3 changes: 3 additions & 0 deletions stock_inventory_adjustment/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
124 changes: 124 additions & 0 deletions stock_inventory_adjustment/views/stock_inventory.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<odoo>

<record id="view_inventory_group_form" model="ir.ui.view">
<field name="name">stock.inventory.form.view</field>
<field name="model">stock.inventory</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<form>
<header>
<button
type="object"
name="action_state_to_in_progress"
class="oe_highlight"
attrs="{'invisible':[('state', 'in', ['1', '3'])]}"
string="Begin Adjustments"
/>
<button
type="object"
name="action_state_to_draft"
attrs="{'invisible':['|',('state', 'in', ['2', '3']), ('count_stock_moves', '!=', 0)]}"
string="Back to Draft"
/>
<button
type="object"
name="action_state_to_done"
class="oe_highlight"
attrs="{'invisible':[('state', 'in', ['2', '3'])]}"
string="Set to Done"
/>
<field name="state" widget="statusbar" statusbar_visible="2,1,3" />
</header>

<sheet>
<div class="oe_button_box" name="button_box">
<button
type="object"
name="action_view_inventory_adjustment"
class="oe_stat_button"
icon="fa-pencil-square-o"
string="Adjustments"
attrs="{'invisible':[('state', 'in', ['2', '3'])]}"
>
<field name="count_stock_quants" readonly="1" />
</button>
<button
type="object"
name="action_view_stock_moves"
class="oe_stat_button"
icon="fa-cubes"
string="Stock Moves"
attrs="{'invisible':[('state', '=', '2')]}"
>
<field name="count_stock_moves" readonly="1" />
</button>
</div>
<div class="oe_title" name="title">
<h1>
<field name="name" />
</h1>
</div>
<group>
<group>
<field
name="product_selection"
attrs="{'readonly':[('state', 'in', ['1', '3'])]}"
/>
<field
name="location_ids"
string="Locations"
widget="many2many_tags"
attrs="{'readonly':[('state', 'in', ['1', '3'])], 'required': [('product_selection', '=', 'all')],'invisible': [('product_selection', '=', 'manual')]}"
/>
</group>
<group>
<field name="date" />
</group>
</group>
<group>
<field
name="stock_quant_ids"
string="Products In Location"
attrs="{'invisible':['|',('state', 'in', ['1', '3']), ('product_selection', '!=', 'manual')]}"
required="1"
>
<tree>
<field name="display_name" string="Product Name" />
<field name="location_id" string="Location" />
<field name="lot_id" string="Lot / Serial Number" />
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>

<record id="view_inventory_group_tree" model="ir.ui.view">
<field name="name">stock.inventory.tree.view</field>
<field name="model">stock.inventory</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="state" />
</tree>
</field>
</record>

<record id="action_view_inventory_group_form" model="ir.actions.act_window">
<field name="name">Inventory Adjustment Group</field>
<field name="res_model">stock.inventory</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_inventory_group_tree" />
</record>

<menuitem
id="menu_action_inventory_tree"
name="Inventory Adjustments"
parent="stock.menu_stock_warehouse_mgmt"
sequence="30"
action="action_view_inventory_group_form"
/>
<delete model="ir.ui.menu" id="stock.menu_action_inventory_tree" />
</odoo>

0 comments on commit 1a4afb0

Please sign in to comment.