Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0][MIG] stock_picking_backorder_strategy #766

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stock_picking_backorder_strategy/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Picking backordering strategies",
"version": "12.0.1.0.1",
"version": "13.0.1.0.0",
"development_status": "Production/Stable",
"author": """ACSONE SA/NV,
Odoo Community Association (OCA)""",
Expand Down
3 changes: 1 addition & 2 deletions stock_picking_backorder_strategy/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo import models


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

@api.multi
def _cancel_remaining_quantities(self):
to_cancel = self.filtered(lambda m: m.state not in ("done", "cancel"))
to_cancel._action_cancel()
14 changes: 3 additions & 11 deletions stock_picking_backorder_strategy/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo import models


class StockPicking(models.Model):

_inherit = "stock.picking"

@api.multi
def _check_backorder(self):
self.ensure_one()
# If strategy == 'manual', let the normal process going on
if self.picking_type_id.backorder_strategy == "manual":
return super(StockPicking, self)._check_backorder()
return False

@api.multi
def _create_backorder(self, backorder_moves=None):
if backorder_moves is None:
backorder_moves = []
res = False
def _create_backorder(self):
# Do nothing with pickings 'no_create'
pickings = self.filtered(
lambda p: p.picking_type_id.backorder_strategy != "no_create"
)
pickings_no_create = self - pickings
pickings_no_create.mapped("move_lines")._cancel_remaining_quantities()
res = super(StockPicking, pickings)._create_backorder(
backorder_moves=backorder_moves
)
res = super(StockPicking, pickings)._create_backorder()
to_cancel = res.filtered(
lambda b: b.backorder_id.picking_type_id.backorder_strategy == "cancel"
)
Expand Down
31 changes: 16 additions & 15 deletions stock_picking_backorder_strategy/tests/test_backorder_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@
from odoo.tests import common


class TestBackorderStrategy(common.TransactionCase):
def setUp(self):
""" Create the picking
"""
super(TestBackorderStrategy, self).setUp()
class TestBackorderStrategy(common.SavepointCase):
@classmethod
def setUpClass(cls):
"""Create the picking."""
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


self.picking_obj = self.env["stock.picking"]
move_obj = self.env["stock.move"]
cls.picking_obj = cls.env["stock.picking"]
move_obj = cls.env["stock.move"]

self.picking_type = self.env.ref("stock.picking_type_in")
cls.picking_type = cls.env.ref("stock.picking_type_in")

product = self.env.ref("product.product_product_13")
loc_supplier_id = self.env.ref("stock.stock_location_suppliers").id
loc_stock_id = self.env.ref("stock.stock_location_stock").id
product = cls.env.ref("product.product_product_13")
loc_supplier_id = cls.env.ref("stock.stock_location_suppliers").id
loc_stock_id = cls.env.ref("stock.stock_location_stock").id

self.picking = self.picking_obj.create(
cls.picking = cls.picking_obj.create(
{
"picking_type_id": self.picking_type.id,
"picking_type_id": cls.picking_type.id,
"location_id": loc_supplier_id,
"location_dest_id": loc_stock_id,
}
)
move_obj.create(
{
"name": "/",
"picking_id": self.picking.id,
"picking_id": cls.picking.id,
"product_uom": product.uom_id.id,
"location_id": loc_supplier_id,
"location_dest_id": loc_stock_id,
"product_id": product.id,
"product_uom_qty": 2,
}
)
self.picking.action_confirm()
cls.picking.action_confirm()

def _process_picking(self):
""" Receive partially the picking
Expand Down