Skip to content

Commit

Permalink
Merge c9f0f9a into f55995f
Browse files Browse the repository at this point in the history
  • Loading branch information
grindtildeath committed Jun 21, 2018
2 parents f55995f + c9f0f9a commit ced655b
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 9 deletions.
1 change: 1 addition & 0 deletions mrp_stock_picking_restrict_cancel/__init__.py
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions mrp_stock_picking_restrict_cancel/__manifest__.py
@@ -0,0 +1,16 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "MRP Stock Picking Restrict Cancel",
"summary": "Restrict cancellation with MRP.",
"version": "11.0.1.0.1",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"mrp",
"stock_picking_restrict_cancel_with_orig_move",
],
'auto-install': True,
}
1 change: 1 addition & 0 deletions mrp_stock_picking_restrict_cancel/models/__init__.py
@@ -0,0 +1 @@
from . import stock_move
14 changes: 14 additions & 0 deletions mrp_stock_picking_restrict_cancel/models/stock_move.py
@@ -0,0 +1,14 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, api


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

def identify_blocking_objects(self, blocking_moves):
res = super().identify_objects(blocking_moves)
workorders = blocking_moves.mapped('production_id')
if workorders:
res.update({'workorders': workorders})
return res
1 change: 1 addition & 0 deletions purchase_stock_picking_restrict_cancel/__init__.py
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions purchase_stock_picking_restrict_cancel/__manifest__.py
@@ -0,0 +1,16 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Stock Picking Restrict Cancel",
"summary": "Restrict cancellation with Purchase.",
"version": "11.0.1.0.1",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"purchase",
"stock_picking_restrict_cancel_with_orig_move",
],
'auto-install': True,
}
1 change: 1 addition & 0 deletions purchase_stock_picking_restrict_cancel/models/__init__.py
@@ -0,0 +1 @@
from . import stock_move
15 changes: 15 additions & 0 deletions purchase_stock_picking_restrict_cancel/models/stock_move.py
@@ -0,0 +1,15 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, api


class StockMove(models.Model):

_inherit = 'stock.move'

def identify_blocking_objects(self, blocking_moves):
res = super().identify_objects(blocking_moves)
purchases = blocking_moves.mapped('created_purchase_line_id')
if purchases:
res.update({'purchases': purchases})
return res
Expand Up @@ -3,7 +3,7 @@
{
"name": "Stock Picking Restrict Cancel with Original Moves",
"summary": "Restrict cancellation of dest moves according to origin.",
"version": "11.0.1.0.0",
"version": "11.0.1.0.1",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
50 changes: 42 additions & 8 deletions stock_picking_restrict_cancel_with_orig_move/models/stock_move.py
Expand Up @@ -5,23 +5,57 @@
from odoo.exceptions import UserError


def format_link(object):
return '<a href=# data-oe-model=%s data-oe-id=%d>%s</a>' % (
object._name, object.id, object.name)


class StockMove(models.Model):

_inherit = 'stock.move'

def _action_cancel(self):
if (self.env.context.get('bypass_check_state') or
all(move.state in ('cancel', 'done')
for move in self.mapped('move_orig_ids'))):

orig_moves = self.mapped('move_orig_ids')
all_om_canceled_or_done = all(
move.state in ('cancel', 'done') for move in orig_moves)
all_om_in_self = all(om in self for om in orig_moves)

if (
self.env.context.get('bypass_check_state') or
all_om_canceled_or_done or
all_om_in_self
):
return super(StockMove, self.with_context(
bypass_check_state=True))._action_cancel()
else:
pickings = self.env['stock.picking']
for move in self:
for orig_stock_move in move.move_orig_ids:
pickings |= orig_stock_move.picking_id
blocking_moves = self.get_blocking_moves(orig_moves)
blocking_objects = self.identify_objects(blocking_moves)
error_objects = ''
for object_type, objects in blocking_objects.items():
error_objects += _('- %s : %s. \n' % (
object_type, ','.join([format_link(o) for o in objects])))
# TODO Fix error message:
# We'd like the links to be clickable but they are interpreted as
# raw text
raise UserError(
_("Cancelation of destination move is restricted if any "
"previous move is not canceled or done."
"Original moves are not canceled or done on the following "
"pickings : %s") % ', '.join([p.name for p in pickings]))
"objects : \n%s") % error_objects)

def get_blocking_moves(self, orig_moves):
not_canceled_or_done = orig_moves.filtered(
lambda m: m.state not in ('cancel', 'done')
)
not_in_self = orig_moves.filtered(
lambda m: m not in self
)
return not_in_self & not_canceled_or_done

def identify_blocking_objects(self, blocking_moves):
pickings = blocking_moves.mapped('picking_id')
if pickings:
return {'pickings': pickings}
else:
return {}

0 comments on commit ced655b

Please sign in to comment.