-
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[15.0][ADD] stock_inventory_adjustment
- Loading branch information
1 parent
7880648
commit 79649c6
Showing
16 changed files
with
383 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Stock Inventory Adjustment", | ||
"version": "15.0.1.0.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", | ||
"views/stock_quant.xml", | ||
"views/stock_move_line.xml", | ||
], | ||
"installable": True, | ||
"application": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class InventoryAdjustmentsGroup(models.Model): | ||
_name = "stock.inventory" | ||
_description = "Inventory Adjustment Group" | ||
_order = "date desc, id desc" | ||
|
||
name = fields.Char( | ||
required=True, default="Inventory ", string="Inventory Reference" | ||
) | ||
|
||
date = fields.Datetime(default=lambda self: fields.Datetime.now()) | ||
|
||
state = fields.Selection( | ||
[("draft", "Draft"), ("in_progress", "In Progress"), ("done", "Done")], | ||
default="draft", | ||
) | ||
|
||
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, | ||
) | ||
|
||
product_ids = fields.Many2many("product.product", string="Products") | ||
|
||
stock_quant_ids = fields.Many2many("stock.quant", string="Inventory Adjustment") | ||
|
||
stock_move_ids = fields.One2many( | ||
"stock.move.line", | ||
"inventory_adjustment_id", | ||
string="Inventory Adjustments Done", | ||
) | ||
|
||
count_stock_quants = fields.Integer( | ||
compute="_compute_count_stock_quants", string="Adjustments" | ||
) | ||
|
||
count_stock_quants_string = fields.Char( | ||
compute="_compute_count_stock_quants", string="Adjustments" | ||
) | ||
|
||
count_stock_moves = fields.Integer( | ||
compute="_compute_count_stock_moves", string="Stock Moves Lines" | ||
) | ||
|
||
@api.depends("stock_quant_ids") | ||
def _compute_count_stock_quants(self): | ||
self.count_stock_quants = len(self.stock_quant_ids) | ||
count_todo = len( | ||
self.stock_quant_ids.search( | ||
[("id", "in", self.stock_quant_ids.ids), ("to_do", "=", "True")] | ||
) | ||
) | ||
self.count_stock_quants_string = "{} / {}".format( | ||
count_todo, self.count_stock_quants | ||
) | ||
|
||
@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", "=", "in_progress")]) | ||
if active_rec: | ||
raise ValidationError( | ||
_("There's already an Adjustment in Process: %s") % active_rec.name | ||
) | ||
self.state = "in_progress" | ||
if self.product_selection == "all": | ||
for location in self._origin.location_ids: | ||
self.stock_quant_ids = self.env["stock.quant"].search( | ||
[ | ||
"|", | ||
("location_id", "=", location.id), | ||
("location_id", "in", location.child_ids.ids), | ||
] | ||
) | ||
else: | ||
for location in self._origin.location_ids: | ||
self.stock_quant_ids = self.env["stock.quant"].search( | ||
[ | ||
("product_id", "in", self.product_ids.ids), | ||
"|", | ||
("location_id", "=", location.id), | ||
("location_id", "in", location.child_ids.ids), | ||
] | ||
) | ||
return | ||
|
||
def action_state_to_done(self): | ||
self.state = "done" | ||
for quant in self.stock_quant_ids: | ||
quant.to_do = True | ||
return | ||
|
||
def action_state_to_draft(self): | ||
self.state = "draft" | ||
for quant in self.stock_quant_ids: | ||
quant.to_do = True | ||
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)] | ||
result["search_view_id"] = self.env.ref("stock.quant_search_view").id | ||
result["context"]["search_default_to_do"] = 1 | ||
return result | ||
|
||
def action_view_stock_moves(self): | ||
result = self.env["ir.actions.act_window"]._for_xml_id( | ||
"stock_inventory.action_view_stock_move_line_inventory_tree" | ||
) | ||
sm_ids = self.mapped("stock_move_ids").ids | ||
result["domain"] = [("id", "in", sm_ids)] | ||
result["context"] = [] | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class StockMoveLine(models.Model): | ||
_inherit = "stock.move.line" | ||
|
||
inventory_adjustment_id = fields.Many2one("stock.inventory") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class StockQuant(models.Model): | ||
_inherit = "stock.quant" | ||
|
||
to_do = fields.Boolean(default=True) | ||
|
||
def _apply_inventory(self): | ||
res = super()._apply_inventory() | ||
record_moves = self.env["stock.move.line"] | ||
adjustment = self.env["stock.inventory"].search([("state", "=", "in_progress")]) | ||
for rec in self: | ||
moves = record_moves.search( | ||
[ | ||
("product_id", "=", rec.product_id.id), | ||
("lot_id", "=", rec.lot_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 | ||
rec.to_do = False | ||
|
||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `ForgeFlow <https://www.forgeflow.com>`_: | ||
|
||
* David Jiménez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<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', ['in_progress', 'done'])]}" | ||
string="Begin Adjustments" | ||
/> | ||
<button | ||
type="object" | ||
name="action_state_to_draft" | ||
attrs="{'invisible':['|',('state', 'in', ['draft', 'done']), ('count_stock_moves', '!=', 0)]}" | ||
string="Back to Draft" | ||
/> | ||
<button | ||
type="object" | ||
name="action_state_to_done" | ||
class="oe_highlight" | ||
attrs="{'invisible':[('state', 'in', ['draft', 'done'])]}" | ||
string="Set to Done" | ||
/> | ||
<field | ||
name="state" | ||
widget="statusbar" | ||
statusbar_visible="draft,in_progress,done" | ||
/> | ||
</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" | ||
attrs="{'invisible':['|', ('state', 'in', ['draft', 'done']), ('count_stock_quants', '=', 0)]}" | ||
> | ||
<field | ||
name="count_stock_quants_string" | ||
widget="statinfo" | ||
readonly="1" | ||
/> | ||
<field invisible="True" name="count_stock_quants" /> | ||
</button> | ||
<button | ||
type="object" | ||
name="action_view_stock_moves" | ||
class="oe_stat_button" | ||
icon="fa-cubes" | ||
attrs="{'invisible':['|', ('state', '=', 'draft'), ('count_stock_moves', '=', 0)]}" | ||
> | ||
<field | ||
name="count_stock_moves" | ||
widget="statinfo" | ||
readonly="1" | ||
/> | ||
</button> | ||
</div> | ||
<div class="oe_title" name="title"> | ||
<label for="name" class="oe_edit_only" /> | ||
<h1><field name="name" placeholder="e.g. Annual inventory" /></h1> | ||
</div> | ||
<group> | ||
<group> | ||
<field | ||
name="product_selection" | ||
widget="radio" | ||
attrs="{'readonly':[('state', 'in', ['in_progress', 'done'])]}" | ||
/> | ||
<field | ||
name="location_ids" | ||
string="Locations" | ||
widget="many2many_tags" | ||
attrs="{'readonly':[('state', 'in', ['in_progress', 'done'])]}" | ||
required="1" | ||
/> | ||
<field | ||
name="product_ids" | ||
widget="many2many_tags" | ||
attrs="{'readonly':[('state', 'in', ['in_progress', 'done'])], 'required': [('product_selection', '=', 'manual')],'invisible': [('product_selection', '=', 'all')]}" | ||
/> | ||
</group> | ||
<group> | ||
<field name="date" /> | ||
</group> | ||
</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" | ||
widget="badge" | ||
decoration-success="state == 'done'" | ||
decoration-info="state not in ('done', 'draft')" | ||
decoration-muted="state == 'draft'" | ||
/> | ||
<field name="date" /> | ||
</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<odoo> | ||
<record id="view_stock_move_line_inventory_tree" model="ir.ui.view"> | ||
<field name="name">stock.move.line.tree.view.inventory</field> | ||
<field name="model">stock.move.line</field> | ||
<field name="priority">1000</field> | ||
<field name="arch" type="xml"> | ||
<tree> | ||
<field name="date" /> | ||
<field name="product_id" /> | ||
<field name="lot_id" /> | ||
<field name="location_id" /> | ||
<field name="location_dest_id" /> | ||
<field name="qty_done" /> | ||
<field name="company_id" optional="hide" /> | ||
<field name="reference" optional="show" /> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record | ||
id="action_view_stock_move_line_inventory_tree" | ||
model="ir.actions.act_window" | ||
> | ||
<field name="name">Stock Move Lines</field> | ||
<field name="res_model">stock.move.line</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="view_id" ref="view_stock_move_line_inventory_tree" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<odoo> | ||
<record id="view_stock_quant_search_not_done" model="ir.ui.view"> | ||
<field name="name">stock.quant.search.not.done</field> | ||
<field name="model">stock.quant</field> | ||
<field name="inherit_id" ref="stock.quant_search_view" /> | ||
<field name="arch" type="xml"> | ||
<filter name="to_apply" position="after"> | ||
<filter | ||
name='to_do' | ||
string="To Do" | ||
domain="[('to_do', '=', 'True')]" | ||
/> | ||
</filter> | ||
</field> | ||
</record> | ||
</odoo> |