Skip to content

Commit

Permalink
[MIG] stock_inventory: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev committed Jul 2, 2024
1 parent 278778f commit 27496dc
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion stock_inventory/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Stock Inventory Adjustment",
"version": "16.0.2.3.0",
"version": "17.0.1.0.0",
"license": "LGPL-3",
"maintainer": ["DavidJForgeFlow"],
"development_status": "Beta",
Expand Down
23 changes: 5 additions & 18 deletions stock_inventory/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
from odoo.exceptions import UserError, ValidationError
from odoo.osv import expression

READONLY_STATES = {
"draft": [("readonly", False)],
}


class InventoryAdjustmentsGroup(models.Model):
_name = "stock.inventory"
Expand All @@ -20,20 +16,17 @@ class InventoryAdjustmentsGroup(models.Model):
default="Inventory",
string="Inventory Reference",
readonly=True,
states=READONLY_STATES,
)

date = fields.Datetime(
default=lambda self: fields.Datetime.now(),
readonly=True,
states=READONLY_STATES,
)

company_id = fields.Many2one(
comodel_name="res.company",
readonly=True,
index=True,
states={"draft": [("readonly", False)]},
default=lambda self: self.env.company,
required=True,
)
Expand All @@ -54,7 +47,6 @@ class InventoryAdjustmentsGroup(models.Model):
"Owner",
help="This is the owner of the inventory adjustment",
readonly=True,
states=READONLY_STATES,
)

location_ids = fields.Many2many(
Expand All @@ -63,7 +55,6 @@ class InventoryAdjustmentsGroup(models.Model):
domain="[('usage', '=', 'internal'), "
"'|', ('company_id', '=', company_id), ('company_id', '=', False)]",
readonly=True,
states=READONLY_STATES,
)

product_selection = fields.Selection(
Expand All @@ -77,46 +68,40 @@ class InventoryAdjustmentsGroup(models.Model):
default="all",
required=True,
readonly=True,
states=READONLY_STATES,
)

product_ids = fields.Many2many(
"product.product",
string="Products",
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
readonly=True,
states=READONLY_STATES,
)

stock_quant_ids = fields.Many2many(
"stock.quant",
string="Inventory Adjustment",
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
readonly=True,
states=READONLY_STATES,
)

category_id = fields.Many2one(
"product.category",
string="Product Category",
readonly=True,
states=READONLY_STATES,
)

lot_ids = fields.Many2many(
"stock.lot",
string="Lot/Serial Numbers",
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
readonly=True,
states=READONLY_STATES,
)

stock_move_ids = fields.One2many(
"stock.move.line",
"inventory_adjustment_id",
string="Inventory Adjustments Done",
readonly=True,
states=READONLY_STATES,
)

count_stock_quants = fields.Integer(
Expand Down Expand Up @@ -276,7 +261,8 @@ def action_state_to_in_progress(self):
else:
error_field = "location_id"
error_message = _(
"There's already an Adjustment in Process using one requested Location: %s"
"There's already an Adjustment in Process using one "
"requested Location: %s"
)

quants = self.env["stock.quant"].search(search_filter)
Expand Down Expand Up @@ -407,8 +393,9 @@ def _check_inventory_in_progress_not_override(self):
):
raise ValidationError(

Check warning on line 394 in stock_inventory/models/stock_inventory.py

View check run for this annotation

Codecov / codecov/patch

stock_inventory/models/stock_inventory.py#L394

Added line #L394 was not covered by tests
_(
"Cannot have more than one in-progress inventory adjustment "
"affecting the same location or product at the same time."
"Cannot have more than one in-progress inventory "
"adjustment affecting the same location or product "
"at the same time."
)
)

Expand Down
4 changes: 2 additions & 2 deletions stock_inventory/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _apply_inventory(self):
self.env["stock.inventory"]
.search([("state", "=", "in_progress")])
.filtered(
lambda x: rec.location_id in x.location_ids
lambda x, rec=rec: rec.location_id in x.location_ids
or (
rec.location_id in x.location_ids.child_internal_location_ids
and not x.exclude_sublocation
Expand All @@ -32,7 +32,7 @@ def _apply_inventory(self):
],
order="create_date asc",
).filtered(
lambda x: not x.company_id.id
lambda x, rec=rec: not x.company_id.id
or not rec.company_id.id
or rec.company_id.id == x.company_id.id
)
Expand Down
16 changes: 8 additions & 8 deletions stock_inventory/tests/test_stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestStockInventory(TransactionCase):
def setUp(self):
super(TestStockInventory, self).setUp()
super().setUp()
self.env.company.stock_inventory_auto_complete = False
self.quant_model = self.env["stock.quant"]
self.move_model = self.env["stock.move.line"]
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_01_all_locations(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 3)
self.assertEqual(inventory1.count_stock_quants_string, "2 / 3")
self.assertEqual(inventory1.stock_move_ids.qty_done, 8)
self.assertEqual(inventory1.stock_move_ids.quantity, 8)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_1.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location1.id)
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_02_manual_selection(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 2)
self.assertEqual(inventory1.count_stock_quants_string, "1 / 2")
self.assertEqual(inventory1.stock_move_ids.qty_done, 26)
self.assertEqual(inventory1.stock_move_ids.quantity, 26)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_3.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location3.id)
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_03_one_selection(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 2)
self.assertEqual(inventory1.count_stock_quants_string, "1 / 2")
self.assertEqual(inventory1.stock_move_ids.qty_done, 26)
self.assertEqual(inventory1.stock_move_ids.quantity, 26)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_3.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location3.id)
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_04_lot_selection(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 1)
self.assertEqual(inventory1.count_stock_quants_string, "0 / 1")
self.assertEqual(inventory1.stock_move_ids.qty_done, 26)
self.assertEqual(inventory1.stock_move_ids.quantity, 26)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_3.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location3.id)
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_05_category_selection(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 1)
self.assertEqual(inventory1.count_stock_quants_string, "0 / 1")
self.assertEqual(inventory1.stock_move_ids.qty_done, 26)
self.assertEqual(inventory1.stock_move_ids.quantity, 26)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product2.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location3.id)
inventory1.action_state_to_done()
Expand Down Expand Up @@ -354,7 +354,7 @@ def test_06_exclude_sub_locations(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 1)
self.assertEqual(inventory1.count_stock_quants_string, "0 / 1")
self.assertEqual(inventory1.stock_move_ids.qty_done, 8)
self.assertEqual(inventory1.stock_move_ids.quantity, 8)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_1.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location1.id)
Expand Down Expand Up @@ -399,7 +399,7 @@ def test_07_stock_inventory_auto_complete(self):
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 2)
self.assertEqual(inventory1.count_stock_quants_string, "1 / 2")
self.assertEqual(inventory1.stock_move_ids.qty_done, 26)
self.assertEqual(inventory1.stock_move_ids.quantity, 26)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_3.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location3.id)
Expand Down
2 changes: 1 addition & 1 deletion stock_inventory/views/res_config_settings_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="stock.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='production_lot_info']" position='after'>
<xpath expr="//block[@id='production_lot_info']" position='after'>
<h2>Stock Inventory</h2>
<div class="row mt16 o_settings_container">
<div class="col-xs-12 col-md-6 o_setting_box">
Expand Down
56 changes: 35 additions & 21 deletions stock_inventory/views/stock_inventory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
type="object"
name="action_state_to_in_progress"
class="oe_highlight"
attrs="{'invisible':[('state', 'in', ['in_progress', 'done'])]}"
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)]}"
invisible="state in ('draft', 'done') or count_stock_moves != 0"
string="Back to Draft"
/>
<field name="action_state_to_cancel_allowed" invisible="1" />
<button
type="object"
name="action_state_to_cancel"
attrs="{'invisible':[('action_state_to_cancel_allowed', '=', False),]}"
invisible="not action_state_to_cancel_allowed"
string="Cancel"
/>
<button
type="object"
name="action_state_to_done"
class="oe_highlight"
attrs="{'invisible':[('state', 'in', ['draft', 'done'])]}"
invisible="state in ('draft', 'done')"
string="Set to Done"
/>
<field
Expand All @@ -48,7 +48,7 @@
name="action_view_inventory_adjustment"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible':[('state', 'in', ['draft', 'done'])]}"
invisible="state in ('draft', 'done')"
>
<field
name="count_stock_quants_string"
Expand All @@ -62,7 +62,7 @@
name="action_view_stock_moves"
class="oe_stat_button"
icon="fa-cubes"
attrs="{'invisible':['|', ('state', '=', 'draft'), ('count_stock_moves', '=', 0)]}"
invisible="state == 'draft' or count_stock_moves == 0"
>
<field
name="count_stock_moves"
Expand All @@ -73,51 +73,65 @@
</div>
<div class="oe_title" name="title">
<label for="name" class="oe_edit_only" />
<h1><field name="name" placeholder="e.g. Annual inventory" /></h1>
<h1><field
name="name"
placeholder="e.g. Annual inventory"
readonly="state != 'draft'"
/></h1>
</div>
<group>
<group>
<field name="product_selection" widget="radio" />
<field
name="product_selection"
widget="radio"
readonly="state != 'draft'"
/>
<field
name="location_ids"
string="Locations"
widget="many2many_tags"
required="1"
readonly="state != 'draft'"
/>
<field
name="exclude_sublocation"
attrs="{'readonly':[('state', 'in', ['in_progress', 'done'])]}"
readonly="state in ['in_progress', 'done']"
required="1"
/>
</group>
<group>
<field name="date" />
<field name="company_id" />
<field name="responsible_id" />
<field
name="owner_id"
attrs="{'readonly':[('state', '=', 'done')]}"
/>
<field name="date" readonly="state != 'draft'" />
<field name="company_id" readonly="state != 'draft'" />
<field name="responsible_id" readonly="state != 'draft'" />
<field name="owner_id" readonly="state != 'draft'" />
<field
name="product_ids"
widget="many2many_tags"
attrs="{'required': [('product_selection', 'in', ['manual', 'lot'])],'invisible': [('product_selection', 'in', ['all', 'category', 'one'])]}"
readonly="state != 'draft'"
required="product_selection in ['manual', 'lot']"
invisible="product_selection in ['all', 'category', 'one']"
/>
<field
name="product_ids"
widget="many2many_tags"
options="{'limit': 10}"
attrs="{'required': [('product_selection', '=', 'one')],'invisible': [('product_selection', '!=', 'one')]}"
required="product_selection == 'one'"
invisible="product_selection != 'one'"
readonly="state != 'draft'"
/>
<field
name="category_id"
attrs="{'required': [('product_selection', '=', 'category')],'invisible': [('product_selection', '!=', 'category')]}"
required="product_selection == 'category'"
invisible="product_selection != 'category'"
readonly="state != 'draft'"
/>
<field
name="lot_ids"
widget="many2many_tags"
domain="[('product_id', 'in', product_ids)]"
attrs="{'required': [('product_selection', '=', 'lot')],'invisible': [('product_selection', '!=', 'lot')]}"
readonly="state in ['in_progress', 'done']"
required="product_selection == 'lot'"
invisible="product_selection != 'lot'"
/>
</group>
</group>
Expand Down Expand Up @@ -175,7 +189,7 @@
<menuitem
id="menu_action_inventory_tree"
name="Inventory Adjustments"
parent="stock.menu_stock_warehouse_mgmt"
parent="stock.menu_stock_adjustments"
sequence="30"
action="action_view_inventory_group_form"
/>
Expand Down
2 changes: 1 addition & 1 deletion stock_inventory/views/stock_move_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field name="lot_id" />
<field name="location_id" />
<field name="location_dest_id" />
<field name="qty_done" />
<field name="quantity" />
<field name="company_id" optional="hide" />
<field name="reference" optional="show" />
</tree>
Expand Down

0 comments on commit 27496dc

Please sign in to comment.