From a0558ad4fde2da10fe717723b663398031e8bc4e Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Tue, 7 Jan 2014 11:39:15 +0100 Subject: [PATCH] [IMP] stock: rehabilited the constraint check on traceability of lots. Improved it by allowing to track all operations (included the internal -> internal ones). Refactored in order to move the track_production field in mrp, where it's meaningful. Removed also a unused/deprecated wizard to change qty on a move bzr revid: qdp-launchpad@openerp.com-20140107103915-bx9spjoclrlhalbr --- addons/mrp/mrp_view.xml | 5 +- addons/mrp/product.py | 1 + addons/mrp/stock.py | 4 + addons/stock/__openerp__.py | 1 - addons/stock/product.py | 2 +- addons/stock/stock.py | 34 +++--- addons/stock/stock_view.xml | 6 +- addons/stock/wizard/__init__.py | 1 - .../stock/wizard/stock_change_product_qty.py | 109 ------------------ .../wizard/stock_change_product_qty_view.xml | 36 ------ 10 files changed, 28 insertions(+), 171 deletions(-) delete mode 100644 addons/stock/wizard/stock_change_product_qty.py delete mode 100644 addons/stock/wizard/stock_change_product_qty_view.xml diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index d89e62d2391..b07f7328067 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -543,7 +543,7 @@ product.product - + + + + diff --git a/addons/mrp/product.py b/addons/mrp/product.py index dcba1d191be..c6b2376770d 100644 --- a/addons/mrp/product.py +++ b/addons/mrp/product.py @@ -28,6 +28,7 @@ class product_product(osv.osv): _columns = { "bom_ids": fields.one2many('mrp.bom', 'product_id','Bill of Materials', domain=[('bom_id','=',False)]), "produce_delay": fields.float('Manufacturing Lead Time', help="Average delay in days to produce this product. In the case of multi-level BOM, the manufacturing lead times of the components will be added."), + 'track_production': fields.boolean('Track Manufacturing Lots', help="Forces to specify a Serial Number for all moves containing this product and generated by a Manufacturing Order"), } _defaults = { diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 45097bb1a9d..33f629eb176 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -32,6 +32,10 @@ class StockMove(osv.osv): 'raw_material_production_id': fields.many2one('mrp.production', 'Production Order for Raw Materials', select=True), } + def check_tracking(self, cr, uid, move, lot_id, context=None): + super(StockMove, self).check_tracking(cr, uid, move, lot_id, context=context) + if move.product_id.track_production and (move.location_id.usage == 'production' or move.location_dest_id.usage == 'production') and not lot_id: + raise osv.except_osv(_('Warning!'), _('You must assign a serial number for the product %s') % (move.product_id.name)) def _action_explode(self, cr, uid, move, context=None): """ Explodes pickings. diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index 9e286faf81c..140d1c48ecf 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -73,7 +73,6 @@ Dashboard / Reports for Warehouse Management will include: 'stock_data.xml', 'stock_data.yml', 'wizard/stock_move_view.xml', - 'wizard/stock_change_product_qty_view.xml', 'wizard/stock_inventory_merge_view.xml', 'wizard/stock_location_product_view.xml', 'wizard/stock_inventory_line_split_view.xml', diff --git a/addons/stock/product.py b/addons/stock/product.py index 06a57feddfe..6ca53a5ad0d 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -206,9 +206,9 @@ class product_product(osv.osv): "Shop, or any of its children.\n" "Otherwise, this includes goods leaving any Stock " "Location with 'internal' type."), - 'track_production': fields.boolean('Track Manufacturing Lots', help="Forces to specify a Serial Number for all moves containing this product and generated by a Manufacturing Order"), 'track_incoming': fields.boolean('Track Incoming Lots', help="Forces to specify a Serial Number for all moves containing this product and coming from a Supplier Location"), 'track_outgoing': fields.boolean('Track Outgoing Lots', help="Forces to specify a Serial Number for all moves containing this product and going to a Customer Location"), + 'track_all': fields.boolean('Full Lots Traceability', help="Forces to specify a Serial Number on each and every operation related to this product"), 'location_id': fields.dummy(string='Location', relation='stock.location', type='many2one'), 'warehouse_id': fields.dummy(string='Warehouse', relation='stock.warehouse', type='many2one'), 'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Minimum Stock Rules'), diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 1141f169a84..a1b6588cfe7 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -572,27 +572,8 @@ class stock_quant(osv.osv): raise osv.except_osv(_('Error'), _('You cannot move product %s to a location of type view %s.') % (record.product_id.name, record.location_id.name)) return True - # FP Note: rehab this, with the auto creation algo - # def _check_tracking(self, cr, uid, ids, context=None): - # """ Checks if serial number is assigned to stock move or not. - # @return: True or False - # """ - # for move in self.browse(cr, uid, ids, context=context): - # if not move.lot_id and \ - # (move.state == 'done' and \ - # ( \ - # (move.product_id.track_production and move.location_id.usage == 'production') or \ - # (move.product_id.track_production and move.location_dest_id.usage == 'production') or \ - # (move.product_id.track_incoming and move.location_id.usage == 'supplier') or \ - # (move.product_id.track_outgoing and move.location_dest_id.usage == 'customer') or \ - # (move.product_id.track_incoming and move.location_id.usage == 'inventory') \ - # )): - # return False - # return True - _constraints = [ (_check_location, 'You cannot move products to a location of the type view.', ['location_id']) - #(_check_tracking, 'You must assign a serial number for this product.', ['prodlot_id']), ] @@ -1711,6 +1692,19 @@ class stock_move(osv.osv): """ return self.write(cr, uid, ids, {'state': 'confirmed'}) + def check_tracking(self, cr, uid, move, lot_id, context=None): + """ Checks if serial number is assigned to stock move or not and raise an error if it had to. + """ + check = False + if move.product_id.track_all: + check = True + elif move.product_id.track_incoming and move.location_id.usage in ('supplier', 'transit', 'inventory') and move.location_dest_id.usage == 'internal': + check = True + elif move.product_id.track_outgoing and move.location_dest_id.usage in ('customer', 'transit', 'inventory') and move.location_id.usage == 'internal': + check = True + if check and not lot_id: + raise osv.except_osv(_('Warning!'), _('You must assign a serial number for the product %s') % (move.product_id.name)) + def action_assign(self, cr, uid, ids, context=None): """ Checks the product type and accordingly writes the state. """ @@ -1802,6 +1796,7 @@ class stock_move(osv.osv): fallback_domain = [('reservation_id', '=', False)] #first, process the move per linked operation first because it may imply some specific domains to consider for record in move.linked_move_operation_ids: + self.check_tracking(cr, uid, move, record.operation_id.lot_id.id, context=context) dom = main_domain + self.pool.get('stock.move.operation.link').get_specific_domain(cr, uid, record, context=context) quants = quant_obj.quants_get_prefered_domain(cr, uid, move.location_id, move.product_id, record.qty, domain=dom, prefered_domain=prefered_domain, fallback_domain=fallback_domain, restrict_lot_id=move.restrict_lot_id.id, restrict_partner_id=move.restrict_partner_id.id, context=context) package_id = False @@ -1815,6 +1810,7 @@ class stock_move(osv.osv): qty -= record.qty #then if the total quantity processed this way isn't enough, process the remaining quantity without any specific domain if qty > 0: + self.check_tracking(cr, uid, move, move.restrict_lot_id.id, context=context) quants = quant_obj.quants_get_prefered_domain(cr, uid, move.location_id, move.product_id, qty, domain=main_domain, prefered_domain=prefered_domain, fallback_domain=fallback_domain, restrict_lot_id=move.restrict_lot_id.id, restrict_partner_id=move.restrict_partner_id.id, context=context) quant_obj.quants_move(cr, uid, quants, move, context=context) #unreserve the quants and make them available for other operations/moves diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index f1127391431..58f5205ab69 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1944,9 +1944,9 @@ - - - + + + diff --git a/addons/stock/wizard/__init__.py b/addons/stock/wizard/__init__.py index a29f3207ca1..eace40b8327 100644 --- a/addons/stock/wizard/__init__.py +++ b/addons/stock/wizard/__init__.py @@ -24,7 +24,6 @@ import stock_inventory_merge import stock_inventory_line_split import stock_location_product import stock_return_picking -import stock_change_product_qty import make_procurement_product import mrp_procurement import orderpoint_procurement diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py deleted file mode 100644 index 3b40557884a..00000000000 --- a/addons/stock/wizard/stock_change_product_qty.py +++ /dev/null @@ -1,109 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp.osv import fields, osv, orm -import openerp.addons.decimal_precision as dp -from openerp.tools.translate import _ -from openerp import tools - -class stock_change_product_qty(osv.osv_memory): - _name = "stock.change.product.qty" - _description = "Change Product Quantity" - _columns = { - 'product_id' : fields.many2one('product.product', 'Product'), - 'new_quantity': fields.float('New Quantity on Hand', digits_compute=dp.get_precision('Product Unit of Measure'), required=True, help='This quantity is expressed in the Default Unit of Measure of the product.'), - 'lot_id': fields.many2one('stock.production.lot', 'Serial Number', domain="[('product_id','=',product_id)]"), - 'location_id': fields.many2one('stock.location', 'Location', required=True, domain="[('usage', '=', 'internal')]"), - } - - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): - if context is None: context = {} - fvg = super(stock_change_product_qty, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) - product_id = context and context.get('active_id', False) or False - - if view_type == 'form' and (context.get('active_model') == 'product.product') and product_id: - prod_obj = self.pool.get('product.product').browse(cr, uid, product_id, context=context) - fvg['fields']['lot_id']['required'] = prod_obj.track_production - - return fvg - - def default_get(self, cr, uid, fields, context): - """ To get default values for the object. - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param fields: List of fields for which we want default values - @param context: A standard dictionary - @return: A dictionary which of fields with values. - """ - product_id = context and context.get('active_id', False) or False - res = super(stock_change_product_qty, self).default_get(cr, uid, fields, context=context) - - if 'new_quantity' in fields: - res.update({'new_quantity': 1}) - if 'product_id' in fields: - res.update({'product_id': product_id}) - if 'location_id' in fields: - try: - model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') - self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context) - except (orm.except_orm, ValueError): - location_id = False - res.update({'location_id': location_id}) - return res - - def change_product_qty(self, cr, uid, ids, context=None): - """ Changes the Product Quantity by making a Physical Inventory. - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param ids: List of IDs selected - @param context: A standard dictionary - @return: - """ - if context is None: - context = {} - - rec_id = context and context.get('active_id', False) - assert rec_id, _('Active ID is not set in Context') - - inventry_obj = self.pool.get('stock.inventory') - inventry_line_obj = self.pool.get('stock.inventory.line') - prod_obj_pool = self.pool.get('product.product') - - res_original = prod_obj_pool.browse(cr, uid, rec_id, context=context) - for data in self.browse(cr, uid, ids, context=context): - if data.new_quantity < 0: - raise osv.except_osv(_('Warning!'), _('Quantity cannot be negative.')) - inventory_id = inventry_obj.create(cr , uid, {'name': _('INV: %s') % tools.ustr(res_original.name)}, context=context) - line_data ={ - 'inventory_id' : inventory_id, - 'product_qty' : data.new_quantity, - 'location_id' : data.location_id.id, - 'product_id' : rec_id, - 'product_uom_id' : res_original.uom_id.id, - 'prod_lot_id' : data.lot_id.id - } - inventry_line_obj.create(cr , uid, line_data, context=context) - inventry_obj.action_done(cr, uid, [inventory_id], context=context) - return {} - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/wizard/stock_change_product_qty_view.xml b/addons/stock/wizard/stock_change_product_qty_view.xml deleted file mode 100644 index 18c548b2c65..00000000000 --- a/addons/stock/wizard/stock_change_product_qty_view.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - Change Product Quantity - stock.change.product.qty - -
- - - - - - -
-
-
-
-
- - - Update Product Quantity - ir.actions.act_window - stock.change.product.qty - form - form - - new - - -
-
-