Unify and refactor exception handling in framework and addons. The generic `except_osv` is now deprecated, and replaced by more specialized exception subtypes: - `UserError` (renamed from Warning, as it conflicts with the built-in `Warning`) raised when a non-technical error occurs during a business operation. It could be a missing information in the data provided by the user, or a misconfiguration. - `AccessError`: raised when any operation is denied because the user conducting it does not have the required access rights. - `AccessDenied`: raised when an operation that requires authenticated access is attempted via an unauthenticated request. - `MissingError`: raised when an operation is attempted on a record that does not exist. - `ValidationError`: raised when an operation violates a SQL or Python constraint. - All other exceptions are internal errors due to a system problem or bug, and raised untouched to the client-side, which should display a traceback. All exceptions take a single message argument. The `test_exceptions` module has been updated to showcase both new and old (deprecated) exceptions. A great many old `except_osv` had a useless title with "Error!" or "Warning", those have been removed, as this is handled by the client-side widget that displays the messages. This commit introduces a more consistent policy for logging errors and warnings: - All messages that do not require administrator attention should be logged at INFO level or lower. This includes all errors that are notified to the user in a friendly manner, even for access right problems or validation errors during business operations. - All messages that indicate a likely misconfiguration or malicious use by the users should be logged at WARNING level, as they typically require administrator attention. - All other unhandled internal errors cannot typically be handled by the user and should be logged at ERROR or higher level, as they require immediate administrator attention.
70 lines
3.4 KiB
Python
70 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from openerp.osv import fields, osv
|
|
from openerp.tools.translate import _
|
|
from openerp.exceptions import UserError
|
|
|
|
class stock_picking_wave(osv.osv):
|
|
_name = "stock.picking.wave"
|
|
_description = "Picking Wave"
|
|
_order = "name desc"
|
|
_columns = {
|
|
'name': fields.char('Picking Wave Name', required=True, help='Name of the picking wave', copy=False),
|
|
'user_id': fields.many2one('res.users', 'Responsible', help='Person responsible for this wave'),
|
|
'picking_ids': fields.one2many('stock.picking', 'wave_id', 'Pickings', help='List of picking associated to this wave'),
|
|
'state': fields.selection([('draft', 'Draft'), ('in_progress', 'Running'), ('done', 'Done'), ('cancel', 'Cancelled')], string="State", required=True, copy=False),
|
|
}
|
|
|
|
_defaults = {
|
|
'name': '/',
|
|
'state': 'draft',
|
|
}
|
|
|
|
def confirm_picking(self, cr, uid, ids, context=None):
|
|
picking_todo = self.pool.get('stock.picking').search(cr, uid, [('wave_id', 'in', ids)], context=context)
|
|
self.write(cr, uid, ids, {'state': 'in_progress'}, context=context)
|
|
return self.pool.get('stock.picking').action_assign(cr, uid, picking_todo, context=context)
|
|
|
|
def cancel_picking(self, cr, uid, ids, context=None):
|
|
picking_todo = self.pool.get('stock.picking').search(cr, uid, [('wave_id', 'in', ids)], context=context)
|
|
self.pool.get('stock.picking').action_cancel(cr, uid, picking_todo, context=context)
|
|
return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
|
|
|
|
def print_picking(self, cr, uid, ids, context=None):
|
|
'''
|
|
This function print the report for all picking_ids associated to the picking wave
|
|
'''
|
|
context = dict(context or {})
|
|
picking_ids = []
|
|
for wave in self.browse(cr, uid, ids, context=context):
|
|
picking_ids += [picking.id for picking in wave.picking_ids]
|
|
if not picking_ids:
|
|
raise UserError(_('Nothing to print.'))
|
|
context['active_ids'] = picking_ids
|
|
context['active_model'] = 'stock.picking'
|
|
return self.pool.get("report").get_action(cr, uid, [], 'stock.report_picking', context=context)
|
|
|
|
def create(self, cr, uid, vals, context=None):
|
|
if vals.get('name', '/') == '/':
|
|
vals['name'] = self.pool.get('ir.sequence').next_by_code(cr, uid, 'picking.wave') or '/'
|
|
return super(stock_picking_wave, self).create(cr, uid, vals, context=context)
|
|
|
|
def done(self, cr, uid, ids, context=None):
|
|
picking_todo = set()
|
|
for wave in self.browse(cr, uid, ids, context=context):
|
|
for picking in wave.picking_ids:
|
|
if picking.state in ('cancel', 'done'):
|
|
continue
|
|
if picking.state != 'assigned':
|
|
raise UserError(_('Some pickings are still waiting for goods. Please check or force their availability before setting this wave to done.'))
|
|
picking_todo.add(picking.id)
|
|
if picking_todo:
|
|
self.pool.get('stock.picking').action_done(cr, uid, list(picking_todo), context=context)
|
|
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
|
|
|
|
|
|
class stock_picking(osv.osv):
|
|
_inherit = "stock.picking"
|
|
_columns = {
|
|
'wave_id': fields.many2one('stock.picking.wave', 'Picking Wave', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help='Picking wave associated to this picking'),
|
|
}
|