Initialize v18 branch

Rename *_usability modules to *_usability_akretion
This commit is contained in:
Alexis de Lattre
2024-12-24 10:11:21 +01:00
parent 9913924202
commit 13744fc404
264 changed files with 50 additions and 87 deletions

View File

@@ -0,0 +1,11 @@
from . import stock_move
from . import stock_move_line
from . import stock_picking
from . import stock_picking_type
from . import stock_warehouse_orderpoint
from . import stock_quant
from . import stock_lot
from . import procurement_group
from . import procurement_scheduler_log
from . import product
from . import res_partner

View File

@@ -0,0 +1,46 @@
# 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, 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-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 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,31 @@
# 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).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
tracking = fields.Selection(tracking=True)
sale_delay = fields.Float(tracking=True)
# the 'stock' module adds 'product' in detailed_type...
# but forgets to make it the default
detailed_type = fields.Selection(default='product')
def action_view_stock_move(self):
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
class ProductProduct(models.Model):
_inherit = 'product.product'
def action_view_stock_move(self):
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

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

View File

@@ -0,0 +1,14 @@
# Copyright 2024 Akretion France (https://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 StockLot(models.Model):
_inherit = 'stock.lot'
name = fields.Char(tracking=True)
ref = fields.Char(tracking=True)
product_id = fields.Many2one(tracking=True)
company_id = fields.Many2one(tracking=True)

View File

@@ -0,0 +1,30 @@
# 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, _
import logging
logger = logging.getLogger(__name__)
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 button_do_unreserve(self):
for move in self:
move._do_unreserve()
picking = move.picking_id
if picking:
product = move.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,
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()

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

@@ -0,0 +1,26 @@
# 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, _
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

View File

@@ -0,0 +1,26 @@
# Copyright 2023 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
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'
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

View File

@@ -0,0 +1,51 @@
# 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 api, fields, models
class StockQuant(models.Model):
_inherit = 'stock.quant'
product_barcode = fields.Char(
related='product_id.barcode', string="Product Barcode")
def action_stock_move_lines_reserved(self):
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id(
"stock.stock_move_line_action")
action['domain'] = [
('state', 'not in', ('draft', 'done', 'cancel')),
('reserved_uom_qty', '!=', 0),
('product_id', '=', self.product_id.id),
('location_id', '=', self.location_id.id),
('lot_id', '=', self.lot_id.id or False),
'|',
('package_id', '=', self.package_id.id or False),
('result_package_id', '=', self.package_id.id or False),
]
action['context'] = {'create': 0}
return action
@api.model
def default_get(self, fields_list):
res = super().default_get(fields_list)
if (
not res.get('location_id') and
self._context.get('search_location') and
isinstance(self._context['search_location'], list) and
len(self._context['search_location']) == 1):
res['location_id'] = self._context['search_location'][0]
return res
@api.model
def action_view_inventory(self):
action = super().action_view_inventory()
# Remove filter 'My Counts' set by default for Stock Users
if (
action.get('context') and
isinstance(action['context'], dict) and
action['context'].get('search_default_my_count')):
action['context'].pop('search_default_my_count')
return action

View File

@@ -0,0 +1,30 @@
# 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 fields, models
import logging
logger = logging.getLogger(__name__)
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
# In the 'stock' module, the default value for 'trigger' is 'auto'
# but all the Odoo deployments I've seen so far need 'manual' by default
trigger = fields.Selection(default='manual')
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
def _procure_orderpoint_confirm(
self, use_new_cursor=False, company_id=None, 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