forked from OCA/wms
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by guewen
- Loading branch information
Showing
36 changed files
with
663 additions
and
573 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
File renamed without changes.
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) | ||
{ | ||
"name": "Delivery Carrier Preference", | ||
"summary": "Advanced selection of preferred shipping methods", | ||
"version": "13.0.1.2.0", | ||
"category": "Operations/Inventory/Delivery", | ||
"website": "https://github.com/OCA/wms", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"delivery", | ||
"product_total_weight_from_packaging", | ||
"stock_available_to_promise_release", | ||
"stock_picking_group_by_partner_by_carrier", | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/delivery_carrier_preference.xml", | ||
"views/stock_move.xml", | ||
"views/stock_picking.xml", | ||
"views/stock_location_route.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,5 @@ | ||
from . import delivery_carrier_preference | ||
from . import procurement_group | ||
from . import stock_move | ||
from . import stock_picking | ||
from . import stock_location_route |
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
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,11 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import fields, models | ||
|
||
|
||
class ProcurementGroup(models.Model): | ||
_inherit = "procurement.group" | ||
|
||
picking_ids = fields.One2many( | ||
comodel_name="stock.picking", inverse_name="group_id", readonly=True | ||
) |
14 changes: 14 additions & 0 deletions
14
delivery_carrier_preference/models/stock_location_route.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,14 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import fields, models | ||
|
||
|
||
class StockLocationRoute(models.Model): | ||
|
||
_inherit = "stock.location.route" | ||
|
||
force_recompute_preferred_carrier_on_release = fields.Boolean( | ||
string="Force recomputation of preferred carrier.", | ||
help="Mark this box to trigger a recomputation of preferred carrier on" | ||
" the release of operations.", | ||
) |
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,100 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from itertools import groupby | ||
|
||
from odoo import api, fields, models, tools | ||
|
||
|
||
class StockMove(models.Model): | ||
|
||
_inherit = "stock.move" | ||
|
||
estimated_shipping_weight = fields.Float( | ||
string="Estimated shipping weight", | ||
compute="_compute_estimated_shipping_weight", | ||
help="Total weight available to promise calculated according to the" | ||
" quantity available to promise and weight defined on packagings " | ||
"for this product.", | ||
) | ||
|
||
@api.depends( | ||
"product_id", | ||
"product_id.packaging_ids", | ||
"product_id.packaging_ids.max_weight", | ||
"product_id.weight", | ||
"ordered_available_to_promise", | ||
) | ||
def _compute_estimated_shipping_weight(self): | ||
for move in self: | ||
prod = move.product_id | ||
move.estimated_shipping_weight = prod.get_total_weight_from_packaging( | ||
move.ordered_available_to_promise | ||
) | ||
|
||
def _get_new_picking_values(self): | ||
vals = super()._get_new_picking_values() | ||
# Take the carrier_id from the group only when we have a related line | ||
# (i.e. we are in an OUT). It reflects the code of the super method in | ||
# "delivery" which takes the carrier of the related SO through SO line | ||
if self.sale_line_id: | ||
group_carrier = self.mapped("group_id.carrier_id") | ||
if group_carrier: | ||
vals["carrier_id"] = group_carrier.id | ||
return vals | ||
|
||
@staticmethod | ||
def _filter_recompute_preferred_carrier(move): | ||
precision = move.env["decimal.precision"].precision_get( | ||
"Product Unit of Measure" | ||
) | ||
return ( | ||
move.need_release | ||
# do not change the carrier is nothing can be released on the stock move | ||
and not tools.float_is_zero( | ||
move._ordered_available_to_promise(), precision_digits=precision | ||
) | ||
and move.rule_id.route_id.force_recompute_preferred_carrier_on_release | ||
) | ||
|
||
def release_available_to_promise(self): | ||
modified_groups = {} | ||
for picking in self.filtered(self._filter_recompute_preferred_carrier).mapped( | ||
"picking_id" | ||
): | ||
if picking.picking_type_code != "outgoing": | ||
continue | ||
picking.add_preferred_carrier() | ||
|
||
# if we have other pickings in the same group and now they have different | ||
# carriers, split them in 2 groups and sync the carrier on their group | ||
sorted_pickings = self.mapped("picking_id").sorted( | ||
lambda pick: (pick.group_id, pick.carrier_id) | ||
) | ||
for (group, new_carrier), iter_pickings in groupby( | ||
sorted_pickings, lambda pick: (pick.group_id, pick.carrier_id) | ||
): | ||
pickings = self.env["stock.picking"].union(*iter_pickings) | ||
if group.carrier_id != new_carrier: | ||
# always create a new procurement group when we change carrier, | ||
# the old group will be reassigned to the backorders if any, | ||
# otherwise it will stay empty in the depths of nothingness | ||
new_group = group.copy( | ||
default={"name": "{} ({})".format(group.name, new_carrier.name)} | ||
) | ||
pickings.move_lines.group_id = new_group | ||
|
||
# sync carrier | ||
new_group.carrier_id = new_carrier | ||
modified_groups[new_group] = group | ||
|
||
res = super().release_available_to_promise() | ||
|
||
for new_group, original_group in modified_groups.items(): | ||
# these are backorders created for unavailable qties, | ||
# reassign them the original group and carrier | ||
need_release_pickings = new_group.picking_ids.filtered("need_release") | ||
# reassign the original group and carriers on the backorders | ||
need_release_pickings.move_lines.group_id = original_group | ||
need_release_pickings.carrier_id = original_group.carrier_id | ||
|
||
return res |
Oops, something went wrong.