[MIG] stock_usability to v14

This commit is contained in:
Alexis de Lattre
2020-12-03 00:17:57 +01:00
parent f818bb5895
commit e060de7efc
26 changed files with 664 additions and 700 deletions

View File

@@ -0,0 +1,9 @@
from . import stock_move
from . import stock_picking
from . import stock_location_route
from . import stock_warehouse_orderpoint
from . import stock_quant
from . import procurement_group
from . import procurement_scheduler_log
from . import product_template
from . import res_partner

View File

@@ -0,0 +1,46 @@
# Copyright 2015-2020 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, fields, models
from datetime import datetime
import logging
logger = logging.getLogger(__name__)
class ProcurementGroup(models.Model):
_inherit = 'procurement.group'
picking_ids = fields.One2many(
'stock.picking', 'group_id', string='Pickings', readonly=True)
@api.model
def run_scheduler(self, use_new_cursor=False, company_id=False):
'''Inherit to add info logs'''
logger.info(
'START procurement scheduler '
'(company ID=%d, uid=%d, use_new_cursor=%s)',
company_id, self._uid, use_new_cursor)
start_datetime = datetime.now()
res = super().run_scheduler(
use_new_cursor=use_new_cursor, company_id=company_id)
logger.info(
'END procurement scheduler '
'(company ID=%d, uid=%d, use_new_cursor=%s)',
company_id, self._uid, use_new_cursor)
try:
# I put it in a try/except, to be sure that, even if the user
# the execute the scheduler doesn't have create right on
# procurement.scheduler.log
self.env['procurement.scheduler.log'].create({
'company_id': company_id,
'start_datetime': start_datetime,
})
# If I don't do an explicit cr.commit(), it doesn't create
# the procurement.scheduler.log... I don't know why
self._cr.commit()
except Exception as e:
logger.warning(
'Could not create procurement.scheduler.log (error: %s)', e)
return res

View File

@@ -0,0 +1,15 @@
# Copyright 2015-2020 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 ProcurementSchedulerLog(models.Model):
_name = 'procurement.scheduler.log'
_description = 'Logs of the Procurement Scheduler'
_order = 'create_date desc'
company_id = fields.Many2one(
'res.company', string='Company', readonly=True)
start_datetime = fields.Datetime(string='Start Date', readonly=True)

View File

@@ -0,0 +1,12 @@
# Copyright 2016-2020 Akretion France
# @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 ProductTemplate(models.Model):
_inherit = 'product.template'
tracking = fields.Selection(tracking=True)
sale_delay = fields.Float(tracking=True)

View File

@@ -0,0 +1,11 @@
# Copyright 2017-2020 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).
from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
picking_warn = fields.Selection(tracking=True)

View File

@@ -0,0 +1,11 @@
# Copyright 2014-2020 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'
name = fields.Char(translate=False)

View File

@@ -0,0 +1,70 @@
# Copyright 2014-2020 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 models, _
from odoo.exceptions import UserError
import logging
logger = logging.getLogger(__name__)
class StockMove(models.Model):
_inherit = 'stock.move'
# 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
def button_do_unreserve(self):
for move in self:
move._do_unreserve()
picking = move.picking_id
if picking:
product = move.product_id
picking.message_post(_(
"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,
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'
# 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(_(
"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,32 @@
# Copyright 2014-2020 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, _
import logging
logger = logging.getLogger(__name__)
class StockPicking(models.Model):
_inherit = 'stock.picking'
# _order = 'id desc'
# In the stock module: _order = "priority desc, scheduled_date asc, id desc"
# The problem is date asc
partner_id = fields.Many2one(tracking=True)
picking_type_id = fields.Many2one(tracking=True)
move_type = fields.Selection(tracking=True)
is_locked = fields.Boolean(tracking=True)
def do_unreserve(self):
res = super().do_unreserve()
for pick in self:
pick.message_post(body=_("Picking <b>unreserved</b>."))
return res
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'
name = fields.Char(translate=False)

View File

@@ -0,0 +1,15 @@
# Copyright 2014-2020 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 models
class StockQuant(models.Model):
_inherit = 'stock.quant'
def action_stock_move_lines_reserved(self):
self.ensure_one()
action = self.action_view_stock_moves()
action['context'] = {'search_default_todo': True}
return action

View File

@@ -0,0 +1,50 @@
# Copyright 2015-2020 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
import logging
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):
logger.info(
'procurement scheduler: START to create moves from '
'orderpoints')
res = super()._procure_orderpoint_confirm(
use_new_cursor=use_new_cursor, company_id=company_id,
raise_user_error=raise_user_error)
logger.info(
'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.'
)]