[MIG] stock_usability from v14 to v16

This commit is contained in:
Alexis de Lattre
2022-10-27 00:05:43 +02:00
parent 4f13432bdc
commit 15c77b3e8a
28 changed files with 184 additions and 359 deletions

View File

@@ -1,9 +1,9 @@
from . import stock_move
from . import stock_move_line
from . import stock_picking
from . import stock_location_route
from . import stock_warehouse_orderpoint
from . import stock_quant
from . import stock_inventory
from . import procurement_group
from . import procurement_scheduler_log
from . import product

View File

@@ -1,4 +1,4 @@
# Copyright 2015-2020 Akretion (http://www.akretion.com)
# Copyright 2015-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,4 @@
# Copyright 2015-2020 Akretion (http://www.akretion.com)
# Copyright 2015-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,4 @@
# Copyright 2016-2021 Akretion France
# Copyright 2016-2022 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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

View File

@@ -1,4 +1,4 @@
# Copyright 2017-2020 Akretion France (https://akretion.com/)
# Copyright 2017-2022 Akretion France (https://akretion.com/)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,45 +0,0 @@
# Copyright 2021-2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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)]

View File

@@ -1,11 +1,11 @@
# Copyright 2014-2020 Akretion (http://www.akretion.com)
# Copyright 2014-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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)

View File

@@ -1,9 +1,8 @@
# Copyright 2014-2020 Akretion (http://www.akretion.com)
# Copyright 2014-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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 <a href=# data-oe-model=product.product "
"data-oe-id=%d>%s</a> qty %s %s <b>unreserved</b>")
% (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()

View File

@@ -0,0 +1,37 @@
# Copyright 2014-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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 <a href=# data-oe-model=product.product "
"data-oe-id=%d>%s</a> qty %s %s <b>unreserved</b>")
% (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()

View File

@@ -1,4 +1,4 @@
# Copyright 2014-2020 Akretion (http://www.akretion.com)
# Copyright 2014-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,4 @@
# Copyright 2014-2020 Akretion (http://www.akretion.com)
# Copyright 2014-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,8 +1,8 @@
# Copyright 2015-2020 Akretion (http://www.akretion.com)
# Copyright 2015-2022 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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.'
)]