From 15c77b3e8a05d737416cca26b3267a3ba7710200 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 27 Oct 2022 00:05:43 +0200 Subject: [PATCH] [MIG] stock_usability from v14 to v16 --- stock_usability/__manifest__.py | 11 +-- stock_usability/models/__init__.py | 2 +- stock_usability/models/procurement_group.py | 2 +- .../models/procurement_scheduler_log.py | 2 +- stock_usability/models/product.py | 10 +-- stock_usability/models/res_partner.py | 2 +- stock_usability/models/stock_inventory.py | 45 ------------ .../models/stock_location_route.py | 6 +- stock_usability/models/stock_move.py | 52 +------------- stock_usability/models/stock_move_line.py | 37 ++++++++++ stock_usability/models/stock_picking.py | 2 +- stock_usability/models/stock_quant.py | 2 +- .../models/stock_warehouse_orderpoint.py | 31 +------- stock_usability/post_install.py | 31 ++++---- stock_usability/security/ir.model.access.csv | 1 - stock_usability/views/procurement_group.xml | 2 +- .../views/procurement_scheduler_log.xml | 2 +- stock_usability/views/product.xml | 2 +- stock_usability/views/stock_inventory.xml | 68 ------------------ stock_usability/views/stock_location.xml | 4 +- ...stock_production_lot.xml => stock_lot.xml} | 2 +- stock_usability/views/stock_move.xml | 72 +------------------ stock_usability/views/stock_move_line.xml | 50 +++++++++++++ stock_usability/views/stock_picking.xml | 28 +------- stock_usability/views/stock_picking_type.xml | 22 ++++++ stock_usability/views/stock_quant.xml | 40 ++++++----- stock_usability/views/stock_warehouse.xml | 2 +- .../views/stock_warehouse_orderpoint.xml | 13 +--- 28 files changed, 184 insertions(+), 359 deletions(-) delete mode 100644 stock_usability/models/stock_inventory.py create mode 100644 stock_usability/models/stock_move_line.py delete mode 100644 stock_usability/views/stock_inventory.xml rename stock_usability/views/{stock_production_lot.xml => stock_lot.xml} (96%) create mode 100644 stock_usability/views/stock_move_line.xml create mode 100644 stock_usability/views/stock_picking_type.xml diff --git a/stock_usability/__manifest__.py b/stock_usability/__manifest__.py index c66e7cd..5ec7dba 100644 --- a/stock_usability/__manifest__.py +++ b/stock_usability/__manifest__.py @@ -1,11 +1,11 @@ -# Copyright 2014-2020 Akretion (http://www.akretion.com) +# Copyright 2014-2022 Akretion (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Stock Usability', - 'version': '14.0.1.0.0', + 'version': '16.0.1.0.0', 'category': 'Inventory, Logistic, Storage', 'license': 'AGPL-3', 'summary': 'Several usability enhancements in Warehouse management', @@ -27,18 +27,19 @@ This module has been written by Alexis de Lattre from Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_usability/models/procurement_scheduler_log.py b/stock_usability/models/procurement_scheduler_log.py index 0740a05..780f7c8 100644 --- a/stock_usability/models/procurement_scheduler_log.py +++ b/stock_usability/models/procurement_scheduler_log.py @@ -1,4 +1,4 @@ -# Copyright 2015-2020 Akretion (http://www.akretion.com) +# Copyright 2015-2022 Akretion (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_usability/models/product.py b/stock_usability/models/product.py index ed80662..5f1a205 100644 --- a/stock_usability/models/product.py +++ b/stock_usability/models/product.py @@ -1,4 +1,4 @@ -# Copyright 2016-2021 Akretion France +# Copyright 2016-2022 Akretion France # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -10,12 +10,12 @@ class ProductTemplate(models.Model): tracking = fields.Selection(tracking=True) sale_delay = fields.Float(tracking=True) - # the 'stock' module adds 'product' in type... + # the 'stock' module adds 'product' in detailed_type... # but forgets to make it the default - type = fields.Selection(default='product') + detailed_type = fields.Selection(default='product') def action_view_stock_move(self): - action = self.env.ref('stock.stock_move_action').sudo().read()[0] + action = self.env["ir.actions.actions"]._for_xml_id("stock.stock_move_action") action['domain'] = [('product_id.product_tmpl_id', 'in', self.ids)] action['context'] = {'search_default_done': True} return action @@ -25,7 +25,7 @@ class ProductProduct(models.Model): _inherit = 'product.product' def action_view_stock_move(self): - action = self.env.ref('stock.stock_move_action').sudo().read()[0] + action = self.env["ir.actions.actions"]._for_xml_id("stock.stock_move_action") action['domain'] = [('product_id', 'in', self.ids)] action['context'] = {'search_default_done': True} return action diff --git a/stock_usability/models/res_partner.py b/stock_usability/models/res_partner.py index 759fded..189ef62 100644 --- a/stock_usability/models/res_partner.py +++ b/stock_usability/models/res_partner.py @@ -1,4 +1,4 @@ -# Copyright 2017-2020 Akretion France (https://akretion.com/) +# Copyright 2017-2022 Akretion France (https://akretion.com/) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_usability/models/stock_inventory.py b/stock_usability/models/stock_inventory.py deleted file mode 100644 index 4ff5216..0000000 --- a/stock_usability/models/stock_inventory.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2021-2022 Akretion France (http://www.akretion.com/) -# @author: Alexis de Lattre -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import fields, models, _ -from odoo.tools import float_compare, float_is_zero - - -class StockInventory(models.Model): - _inherit = 'stock.inventory' - - prefill_counted_quantity = fields.Selection( - readonly=True, states={'draft': [('readonly', False)]}) - - -class StockInventoryLine(models.Model): - _inherit = 'stock.inventory.line' - - product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode") - difference_qty = fields.Float(search="_search_difference_qty_usability") - - def _search_difference_qty_usability(self, operator, value): - # Inspired by the method _search_difference_qty() from the - # official stock module - # So a part of this code is copyright Odoo SA under LGPL licence - if not self.env.context.get('default_inventory_id'): - raise NotImplementedError(_('Unsupported search on %s outside of an Inventory Adjustment', 'difference_qty')) - lines = self.search([('inventory_id', '=', self.env.context.get('default_inventory_id'))]) - line_ids = [] - for line in lines: - if operator == '=': - if float_is_zero(line.difference_qty, line.product_id.uom_id.rounding): - line_ids.append(line.id) - elif operator == '!=': - if not float_is_zero(line.difference_qty, line.product_id.uom_id.rounding): - line_ids.append(line.id) - elif operator == '>': - if float_compare(line.difference_qty, 0, line.product_id.uom_id.rounding) > 0: - line_ids.append(line.id) - elif operator == '<': - if float_compare(line.difference_qty, 0, line.product_id.uom_id.rounding) < 0: - line_ids.append(line.id) - else: - raise NotImplementedError() - return [('id', 'in', line_ids)] diff --git a/stock_usability/models/stock_location_route.py b/stock_usability/models/stock_location_route.py index ba6a856..2e0a3d3 100644 --- a/stock_usability/models/stock_location_route.py +++ b/stock_usability/models/stock_location_route.py @@ -1,11 +1,11 @@ -# Copyright 2014-2020 Akretion (http://www.akretion.com) +# Copyright 2014-2022 Akretion (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models -class StockLocationRoute(models.Model): - _inherit = 'stock.location.route' +class StockRoute(models.Model): + _inherit = 'stock.route' name = fields.Char(translate=False) diff --git a/stock_usability/models/stock_move.py b/stock_usability/models/stock_move.py index ec761fd..c996af5 100644 --- a/stock_usability/models/stock_move.py +++ b/stock_usability/models/stock_move.py @@ -1,9 +1,8 @@ -# Copyright 2014-2020 Akretion (http://www.akretion.com) +# Copyright 2014-2022 Akretion (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models, _ -from odoo.exceptions import UserError import logging logger = logging.getLogger(__name__) @@ -13,26 +12,8 @@ class StockMove(models.Model): _inherit = 'stock.move' # for optional display in tree view - product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode") - -# def name_get(self): -# '''name_get of stock_move is important for the reservation of the -# quants: so want to add the name of the customer and the expected date -# in it''' -# res = [] -# for line in self: -# name = '%s > %s' % ( -# line.location_id.name, line.location_dest_id.name) -# if line.product_id.code: -# name = '%s: %s' % (line.product_id.code, name) -# if line.picking_id.origin: -# name = '%s %s' % (line.picking_id.origin, name) -# if line.partner_id: -# name = '%s %s' % (line.partner_id.name, name) -# if line.date_expected: -# name = '%s %s' % (name, line.date_expected) -# res.append((line.id, name)) -# return res + product_barcode = fields.Char( + related='product_id.barcode', string="Product Barcode") def button_do_unreserve(self): for move in self: @@ -47,30 +28,3 @@ class StockMove(models.Model): move.product_qty, product.uom_id.name)) # Copied from do_unreserved of stock.picking picking.package_level_ids.filtered(lambda p: not p.move_ids).unlink() - - -class StockMoveLine(models.Model): - _inherit = 'stock.move.line' - - # for optional display in tree view - product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode") - - # TODO: I think it's not complete - def button_do_unreserve(self): - for moveline in self: - if moveline.state == 'cancel': - continue - elif moveline.state == 'done': - raise UserError(_( - "You cannot unreserve a move line in done state.")) - picking = moveline.move_id.picking_id - if picking: - product = moveline.product_id - picking.message_post(body=_( - "Product %s qty %s %s unreserved") - % (product.id, product.display_name, - moveline.product_qty, product.uom_id.name)) - # Copied from do_unreserved of stock.picking - picking.package_level_ids.filtered(lambda p: not p.move_ids).unlink() - moveline.unlink() diff --git a/stock_usability/models/stock_move_line.py b/stock_usability/models/stock_move_line.py new file mode 100644 index 0000000..4d41eea --- /dev/null +++ b/stock_usability/models/stock_move_line.py @@ -0,0 +1,37 @@ +# Copyright 2014-2022 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models, _ +from odoo.exceptions import UserError +import logging + +logger = logging.getLogger(__name__) + + +class StockMoveLine(models.Model): + _inherit = 'stock.move.line' + + # for optional display in tree view + product_barcode = fields.Char( + related='product_id.barcode', string="Product Barcode") + + # TODO: I think it's not complete + def button_do_unreserve(self): + for moveline in self: + if moveline.state == 'cancel': + continue + elif moveline.state == 'done': + raise UserError(_( + "You cannot unreserve a move line in done state.")) + picking = moveline.move_id.picking_id + if picking: + product = moveline.product_id + picking.message_post(body=_( + "Product %s qty %s %s unreserved") + % (product.id, product.display_name, + moveline.reserved_qty, product.uom_id.name)) + # Copied from do_unreserved of stock.picking + picking.package_level_ids.filtered(lambda p: not p.move_ids).unlink() + moveline.unlink() diff --git a/stock_usability/models/stock_picking.py b/stock_usability/models/stock_picking.py index dee8bfc..9b0ac41 100644 --- a/stock_usability/models/stock_picking.py +++ b/stock_usability/models/stock_picking.py @@ -1,4 +1,4 @@ -# Copyright 2014-2020 Akretion (http://www.akretion.com) +# Copyright 2014-2022 Akretion (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_usability/models/stock_quant.py b/stock_usability/models/stock_quant.py index 1d27ac9..15ab3ae 100644 --- a/stock_usability/models/stock_quant.py +++ b/stock_usability/models/stock_quant.py @@ -1,4 +1,4 @@ -# Copyright 2014-2020 Akretion (http://www.akretion.com) +# Copyright 2014-2022 Akretion (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_usability/models/stock_warehouse_orderpoint.py b/stock_usability/models/stock_warehouse_orderpoint.py index 66372a7..f539709 100644 --- a/stock_usability/models/stock_warehouse_orderpoint.py +++ b/stock_usability/models/stock_warehouse_orderpoint.py @@ -1,8 +1,8 @@ -# Copyright 2015-2020 Akretion (http://www.akretion.com) +# Copyright 2015-2022 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, models +from odoo import models import logging logger = logging.getLogger(__name__) @@ -11,9 +11,8 @@ logger = logging.getLogger(__name__) class StockWarehouseOrderpoint(models.Model): _inherit = 'stock.warehouse.orderpoint' - @api.model def _procure_orderpoint_confirm( - self, use_new_cursor=False, company_id=False, raise_user_error=True): + self, use_new_cursor=False, company_id=None, raise_user_error=True): logger.info( 'procurement scheduler: START to create moves from ' 'orderpoints') @@ -24,27 +23,3 @@ class StockWarehouseOrderpoint(models.Model): 'procurement scheduler: END creation of moves from ' 'orderpoints') return res - - # This is for the button shortcut "reordering rules" on - # stock.location form view, so that the location_id has the - # good value, not the default stock location of the first WH of the company - @api.model - def default_get(self, fields_list): - if self._context.get('default_location_id'): - location = self.env['stock.location'].browse( - self._context['default_location_id']) - wh = location.get_warehouse() - if location and wh: - self = self.with_context(default_warehouse_id=wh.id) - return super().default_get(fields_list) - - # This SQL constraint blocks the use of the "active" field - # but I think it's not very useful to have such an "active" field - # on orderpoints ; when you think the order point is bad, you update - # the min/max values, you don't de-active it ! - _sql_constraints = [( - 'company_wh_location_product_unique', - 'unique(company_id, warehouse_id, location_id, product_id)', - 'An orderpoint already exists for the same company, same warehouse, ' - 'same stock location and same product.' - )] diff --git a/stock_usability/post_install.py b/stock_usability/post_install.py index 1c902e3..22c2830 100644 --- a/stock_usability/post_install.py +++ b/stock_usability/post_install.py @@ -1,4 +1,4 @@ -# Copyright 2021 Akretion France (http://www.akretion.com/) +# Copyright 2021-2022 Akretion France (http://www.akretion.com/) # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -9,18 +9,17 @@ logger = logging.getLogger(__name__) def create_config_parameter_immediate_tranfer(cr, registry): - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - ico = env["ir.config_parameter"] - conf_param = ico.search([('key', '=', 'stock.no_default_immediate_tranfer')]) - if not conf_param: - ico.create({ - 'key': 'stock.no_default_immediate_tranfer', - 'value': 'True', - }) - logger.info( - 'ir.config_parameter stock.no_default_immediate_tranfer created') - else: - logger.info( - 'ir.config_parameter stock.no_default_immediate_tranfer ' - 'already exists') + env = api.Environment(cr, SUPERUSER_ID, {}) + ico = env["ir.config_parameter"] + conf_param = ico.search([('key', '=', 'stock.no_default_immediate_tranfer')]) + if not conf_param: + ico.create({ + 'key': 'stock.no_default_immediate_tranfer', + 'value': 'True', + }) + logger.info( + 'ir.config_parameter stock.no_default_immediate_tranfer created') + else: + logger.info( + 'ir.config_parameter stock.no_default_immediate_tranfer ' + 'already exists') diff --git a/stock_usability/security/ir.model.access.csv b/stock_usability/security/ir.model.access.csv index c49d585..9316def 100644 --- a/stock_usability/security/ir.model.access.csv +++ b/stock_usability/security/ir.model.access.csv @@ -3,4 +3,3 @@ access_procurement_scheduler_log_full,Full access on procurement.scheduler.log t access_procurement_scheduler_log_user,Read/Create procurement.scheduler.log to Stock user,model_procurement_scheduler_log,stock.group_stock_user,1,0,1,0 access_procurement_scheduler_log_read,Read access on procurement.scheduler.log to Employee,model_procurement_scheduler_log,base.group_user,1,0,0,0 access_stock_warehouse_orderpoint_employee,Read access on stock.warehouse.orderpoint to employee (needed to open product form view with employee-only group),stock.model_stock_warehouse_orderpoint,base.group_user,1,0,0,0 -stock.access_stock_inventory_line_user,stock.inventory.line user,stock.model_stock_inventory_line,stock.group_stock_user,1,1,1,1 diff --git a/stock_usability/views/procurement_group.xml b/stock_usability/views/procurement_group.xml index e8e0c3e..b196a66 100644 --- a/stock_usability/views/procurement_group.xml +++ b/stock_usability/views/procurement_group.xml @@ -1,6 +1,6 @@ diff --git a/stock_usability/views/procurement_scheduler_log.xml b/stock_usability/views/procurement_scheduler_log.xml index 1cefb61..aee4258 100644 --- a/stock_usability/views/procurement_scheduler_log.xml +++ b/stock_usability/views/procurement_scheduler_log.xml @@ -28,6 +28,6 @@ + parent="stock.menu_warehouse_report" sequence="300"/> diff --git a/stock_usability/views/product.xml b/stock_usability/views/product.xml index 7e4c715..8a06368 100644 --- a/stock_usability/views/product.xml +++ b/stock_usability/views/product.xml @@ -1,6 +1,6 @@ diff --git a/stock_usability/views/stock_inventory.xml b/stock_usability/views/stock_inventory.xml deleted file mode 100644 index ce13eb5..0000000 --- a/stock_usability/views/stock_inventory.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - usability.stock.inventory.form - stock.inventory - - - - - {} - - - - - - usability.stock.inventory.line.tree - stock.inventory.line - - - - - - - - product_qty > theoretical_qty - product_qty < theoretical_qty - - - 0 - - - - - - usability.stock.inventory.line.search - stock.inventory.line - - - - - - - - - - - - - - - - diff --git a/stock_usability/views/stock_location.xml b/stock_usability/views/stock_location.xml index ed56749..3737a09 100644 --- a/stock_usability/views/stock_location.xml +++ b/stock_usability/views/stock_location.xml @@ -1,6 +1,6 @@ @@ -52,6 +52,6 @@ should be able to access it. So I add a menu entry under Inventory Control. --> + sequence="160"/> diff --git a/stock_usability/views/stock_production_lot.xml b/stock_usability/views/stock_lot.xml similarity index 96% rename from stock_usability/views/stock_production_lot.xml rename to stock_usability/views/stock_lot.xml index d4fd99d..7dc8be4 100644 --- a/stock_usability/views/stock_production_lot.xml +++ b/stock_usability/views/stock_lot.xml @@ -22,7 +22,7 @@ - stock.production.lot + stock.lot