From 6b5282994a6f1336fff06096874ad3f17a95498f Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 28 Aug 2023 11:07:02 +0200 Subject: [PATCH] stock_usability: Add computed field is_dropship (needed to customize some reports) --- stock_usability/__manifest__.py | 1 + stock_usability/models/__init__.py | 1 + stock_usability/models/stock_picking.py | 9 ------- stock_usability/models/stock_picking_type.py | 27 ++++++++++++++++++++ stock_usability/views/stock_move.xml | 4 +++ stock_usability/views/stock_picking_type.xml | 22 ++++++++++++++++ 6 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 stock_usability/models/stock_picking_type.py create mode 100644 stock_usability/views/stock_picking_type.xml diff --git a/stock_usability/__manifest__.py b/stock_usability/__manifest__.py index 5a59eeb..5d807a7 100644 --- a/stock_usability/__manifest__.py +++ b/stock_usability/__manifest__.py @@ -31,6 +31,7 @@ This module has been written by Alexis de Lattre from Akretion unreserved.")) return res - - -class StockPickingType(models.Model): - _inherit = 'stock.picking.type' - - name = fields.Char(translate=False) diff --git a/stock_usability/models/stock_picking_type.py b/stock_usability/models/stock_picking_type.py new file mode 100644 index 0000000..0a3d7d3 --- /dev/null +++ b/stock_usability/models/stock_picking_type.py @@ -0,0 +1,27 @@ +# Copyright 2014-2020 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockPickingType(models.Model): + _inherit = 'stock.picking.type' + + name = fields.Char(translate=False) + is_dropship = fields.Boolean(compute="_compute_is_dropship", store=True) + + @api.depends("code", "warehouse_id", "default_location_src_id", "default_location_dest_id") + def _compute_is_dropship(self): + supplier_loc_id = self.env.ref("stock.stock_location_suppliers").id + customer_loc_id = self.env.ref("stock.stock_location_customers").id + for picktype in self: + is_dropship = False + if ( + picktype.code == 'incoming' + and not picktype.warehouse_id + and picktype.default_location_src_id.id == supplier_loc_id + and picktype.default_location_dest_id.id == customer_loc_id + ): + is_dropship = True + picktype.is_dropship = is_dropship diff --git a/stock_usability/views/stock_move.xml b/stock_usability/views/stock_move.xml index e813976..6f53638 100644 --- a/stock_usability/views/stock_move.xml +++ b/stock_usability/views/stock_move.xml @@ -61,6 +61,10 @@ + + + + diff --git a/stock_usability/views/stock_picking_type.xml b/stock_usability/views/stock_picking_type.xml new file mode 100644 index 0000000..93f2a3c --- /dev/null +++ b/stock_usability/views/stock_picking_type.xml @@ -0,0 +1,22 @@ + + + + + + + + stock.picking.type + + + + + + + + + +