Skip to content

Commit

Permalink
[MIG] stock_lock_lot: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arantxa-s73 committed Jan 8, 2025
1 parent 75d788b commit b1304f6
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion stock_lock_lot/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"security/stock_lock_lot_security.xml",
"data/stock_lock_lot_data.xml",
"views/product_category_view.xml",
"views/stock_production_lot_view.xml",
"views/stock_lot_view.xml",
"views/stock_location_view.xml",
],
"installable": True,
Expand Down
4 changes: 2 additions & 2 deletions stock_lock_lot/data/stock_lock_lot_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<!-- Lot-related subtypes for messaging / Chatter -->
<record id="mt_lock_lot" model="mail.message.subtype">
<field name="name">Serial Number/lot blocked</field>
<field name="res_model">stock.production.lot</field>
<field name="res_model">stock.lot</field>
<field name="default" eval="False" />
<field name="description">Serial Number/lot blocked</field>
</record>
<record id="mt_unlock_lot" model="mail.message.subtype">
<field name="name">Serial Number/lot unblocked</field>
<field name="res_model">stock.production.lot</field>
<field name="res_model">stock.lot</field>
<field name="default" eval="False" />
<field name="description">Serial Number/lot unblocked</field>
</record>
Expand Down
2 changes: 1 addition & 1 deletion stock_lock_lot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import product_category
from . import stock_production_lot
from . import stock_lot
from . import stock_location
from . import stock_move_line
3 changes: 2 additions & 1 deletion stock_lock_lot/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class ProductCategory(models.Model):
lot_default_locked = fields.Boolean(
string="Block new Serial Numbers/lots",
help="If checked, future Serial Numbers/lots will be created blocked "
"by default",
"by default. This means they will not be available for use "
"in stock moves or other operations",
)
4 changes: 3 additions & 1 deletion stock_lock_lot/models/stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
class StockLocation(models.Model):
_inherit = "stock.location"

allow_locked = fields.Boolean()
allow_locked = fields.Boolean(
help="Indicates whether the location allows receipt of blocked batches"
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
from odoo import _, api, exceptions, fields, models


class StockProductionLot(models.Model):
_name = "stock.production.lot"
_inherit = ["stock.production.lot", "mail.thread"]
class StockLot(models.Model):
_name = "stock.lot"
_inherit = ["stock.lot", "mail.thread"]
_mail_post_access = "read"

locked = fields.Boolean(string="Blocked", tracking=True)
locked = fields.Boolean(
string="Blocked",
tracking=True,
help="Indicates whether this lot is blocked for use.",
)
product_id = fields.Many2one(tracking=True)

def _get_product_locked(self, product):
Expand Down Expand Up @@ -64,7 +68,9 @@ def create(self, vals):
)
)
vals["locked"] = self._get_product_locked(product)
lot = super().with_context(bypass_lock_permission_check=True).create(vals)
lot = super(
StockLot, self.with_context(bypass_lock_permission_check=True)
).create(vals)

return self.browse(lot.id) # for cleaning context

Expand Down
4 changes: 2 additions & 2 deletions stock_lock_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def _action_done(self):
raise exceptions.ValidationError(
_(
"The following lots/serial number is blocked and "
"cannot be moved:\n%s"
"cannot be moved:\n%(lot)s",
lot=ml.lot_id.name
)
% ml.lot_id.name
)
return super()._action_done()
10 changes: 5 additions & 5 deletions stock_lock_lot/tests/test_stock_lock_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from odoo.tests import common


class TestStockLockLot(common.SavepointCase):
class TestStockLockLot(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -25,21 +25,21 @@ def _get_lot_default_vals(self):

def test_new_lot_unlocked(self):
self.category.lot_default_locked = False
lot = self.env["stock.production.lot"].create(self._get_lot_default_vals())
lot = self.env["stock.lot"].create(self._get_lot_default_vals())
self.assertFalse(lot.locked)

def test_new_lot_locked(self):
lot = self.env["stock.production.lot"].create(self._get_lot_default_vals())
lot = self.env["stock.lot"].create(self._get_lot_default_vals())
self.assertTrue(lot.locked)

def test_lot_onchange_product(self):
lot = self.env["stock.production.lot"].new(self._get_lot_default_vals())
lot = self.env["stock.lot"].new(self._get_lot_default_vals())
lot._onchange_product_id()
self.assertTrue(lot.locked)

def test_lock_permissions(self):
self.env.user.groups_id -= self.env.ref("stock_lock_lot.group_lock_lot")
# This should work correctly
lot = self.env["stock.production.lot"].create(self._get_lot_default_vals())
lot = self.env["stock.lot"].create(self._get_lot_default_vals())
with self.assertRaises(exceptions.AccessError):
lot.locked = False
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<odoo>
<record id="view_production_lot_form" model="ir.ui.view">
<field name="name">view.production.lot.form.inherit.lock.lot</field>
<field name="model">stock.production.lot</field>
<field name="model">stock.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form" />
<field name="arch" type="xml">
<field name="ref" position="after">
Expand All @@ -12,7 +12,7 @@
</record>
<record id="view_production_lot_tree" model="ir.ui.view">
<field name="name">view.production.lot.tree.inh.locklot</field>
<field name="model">stock.production.lot</field>
<field name="model">stock.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_tree" />
<field name="arch" type="xml">
<field name="create_date" position="after">
Expand All @@ -22,7 +22,7 @@
</record>
<record id="search_product_lot_filter" model="ir.ui.view">
<field name="name">search.product.lot.filter.inh.locklot</field>
<field name="model">stock.production.lot</field>
<field name="model">stock.lot</field>
<field name="inherit_id" ref="stock.search_product_lot_filter" />
<field name="arch" type="xml">
<group position="before">
Expand Down

0 comments on commit b1304f6

Please sign in to comment.