-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create module stock_picking_type_shipping_policy
- Loading branch information
1 parent
c99030c
commit 320b342
Showing
10 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
{ | ||
"name": "Stock Picking Type Shipping Policy", | ||
"summary": "Define different shipping policies according to picking type", | ||
"version": "13.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Warehouse Management", | ||
"website": "https://github.com/OCA/wms", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": ["stock"], | ||
"data": ["views/stock_picking_type.xml"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import stock_move | ||
from . import stock_picking_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import models | ||
|
||
|
||
class StockMove(models.Model): | ||
|
||
_inherit = 'stock.move' | ||
|
||
def _get_new_picking_values(self): | ||
res = super()._get_new_picking_values() | ||
picking_type = self.mapped('picking_type_id') | ||
if picking_type.shipping_policy == 'force_as_soon_as_possible': | ||
res['move_type'] = 'direct' | ||
elif picking_type.shipping_policy == 'force_all_products_ready': | ||
res['move_type'] = 'one' | ||
return res |
26 changes: 26 additions & 0 deletions
26
stock_picking_type_shipping_policy/models/stock_picking_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import api, fields, models | ||
|
||
|
||
SHIPPING_POLICY_SELECTION = [ | ||
('procurement_group', 'Take from procurement group'), | ||
('force_as_soon_as_possible', 'Force to as soon as possible'), | ||
('force_all_products_ready', 'Force to when all products are ready'), | ||
] | ||
|
||
|
||
class StockPickingType(models.Model): | ||
|
||
_inherit = 'stock.picking.type' | ||
|
||
@api.model | ||
def _default_shipping_policy(self): | ||
return 'procurement_group' | ||
|
||
shipping_policy = fields.Selection( | ||
SHIPPING_POLICY_SELECTION, | ||
default=lambda r: r._default_shipping_policy(), | ||
help="Allows to force the shipping policy on pickings according to the" | ||
" picking type." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Akim Juillerat <akim.juillerat@camptocamp.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module adds a Shipping Policy field on Operations Types in order to force | ||
a specific Shipping Policy on Pickings according to their types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) |
60 changes: 60 additions & 0 deletions
60
stock_picking_type_shipping_policy/tests/test_stock_picking_type_shipping_policy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo.tests import SavepointCase | ||
|
||
|
||
class TestPickingTypeShippingPolicy(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
ref = cls.env.ref | ||
cls.warehouse = ref("stock.warehouse0") | ||
# set pick-pack-ship on warehouse | ||
cls.warehouse.delivery_steps = "pick_pack_ship" | ||
cls.pick_type = cls.warehouse.pick_type_id | ||
cls.pack_type = cls.warehouse.pack_type_id | ||
cls.ship_type = cls.warehouse.out_type_id | ||
|
||
cls.customers_location = cls.env.ref("stock.stock_location_customers") | ||
cls.output_location = cls.warehouse.wh_output_stock_loc_id | ||
|
||
cls.product = cls.env.ref("product.product_product_9") | ||
# Create ir.default for procure_method as make_to_order in order to | ||
# generate chained moves | ||
cls.env['ir.default'].create({ | ||
"field_id": cls.env.ref("stock.field_stock_move__procure_method").id, | ||
"json_value": '"make_to_order"' | ||
}) | ||
|
||
def test_shipping_policy(self): | ||
self.pack_type.shipping_policy = 'force_all_products_ready' | ||
self.pick_type.shipping_policy = 'force_as_soon_as_possible' | ||
# Create picking | ||
out_picking = self.env["stock.picking"].create( | ||
{ | ||
"picking_type_id": self.ship_type.id, | ||
"location_id": self.output_location.id, | ||
"location_dest_id": self.customers_location.id, | ||
"move_lines": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": self.product.name, | ||
"product_id": self.product.id, | ||
"product_uom_qty": 10.0, | ||
"product_uom": self.product.uom_id.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
out_picking.action_confirm() | ||
|
||
pack_picking = out_picking.move_lines.move_orig_ids.picking_id | ||
pick_picking = pack_picking.move_lines.move_orig_ids.picking_id | ||
self.assertEqual(pack_picking.picking_type_id, self.pack_type) | ||
self.assertEqual(pack_picking.move_type, 'one') | ||
self.assertEqual(pick_picking.picking_type_id, self.pick_type) | ||
self.assertEqual(pick_picking.move_type, 'direct') |
13 changes: 13 additions & 0 deletions
13
stock_picking_type_shipping_policy/views/stock_picking_type.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record model="ir.ui.view" id="view_picking_type_form_inherit"> | ||
<field name="name">Operation Types inherit</field> | ||
<field name="model">stock.picking.type</field> | ||
<field name="inherit_id" ref="stock.view_picking_type_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="show_reserved" position="after"> | ||
<field name="shipping_policy" /> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |