Skip to content

Commit

Permalink
[IMP] stock_split_picking: Use specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rousseldenis committed Dec 11, 2024
1 parent 07d0694 commit d7f5754
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions stock_split_picking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

from . import models
from . import wizards
from . import exceptions
33 changes: 33 additions & 0 deletions stock_split_picking/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _
from odoo.exceptions import UserError


class StockSplitPickingStateError(UserError):
"""
Exception class to represent stock picking split error for picking wrong state
"""

def __init__(self, env, picking):
self.env = env
super().__init__(
_(
"Cannot split picking %(name)s in state %(state)s",
name=picking.name,
state=picking.state,
)
)


class StockSplitPickingError(UserError):
"""
Exception class to represent stock picking split error for picking
"""

def __init__(self, env, picking):
self.env = env
super().__init__(
_("Cannot split off all moves from picking %(name)s", name=picking.name)
)
12 changes: 4 additions & 8 deletions stock_split_picking/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_compare

from ..exceptions import StockSplitPickingError, StockSplitPickingStateError


class StockPicking(models.Model):
"""Adds picking split without done state."""
Expand Down Expand Up @@ -100,16 +102,10 @@ def _split_off_moves(self, moves):
new_picking = self.env["stock.picking"]
for this in self:
if this.state in ("done", "cancel"):
raise UserError(
_("Cannot split picking {name} in state {state}").format(
name=this.name, state=this.state
)
)
raise StockSplitPickingStateError(self.env, this)
new_picking = new_picking or this._create_split_backorder()
if not this.move_ids - moves:
raise UserError(
_("Cannot split off all moves from picking %s") % this.name
)
raise StockSplitPickingError(self.env, this)
moves.write({"picking_id": new_picking.id})
moves.mapped("move_line_ids").write({"picking_id": new_picking.id})
return new_picking

0 comments on commit d7f5754

Please sign in to comment.