[IMP] stock: rehabilited the constraint check on traceability of lots. Improved it...
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 7 Jan 2014 10:39:15 +0000 (11:39 +0100)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 7 Jan 2014 10:39:15 +0000 (11:39 +0100)
bzr revid: qdp-launchpad@openerp.com-20140107103915-bx9spjoclrlhalbr

addons/mrp/mrp_view.xml
addons/mrp/product.py
addons/mrp/stock.py
addons/stock/__openerp__.py
addons/stock/product.py
addons/stock/stock.py
addons/stock/stock_view.xml
addons/stock/wizard/__init__.py
addons/stock/wizard/stock_change_product_qty.py [deleted file]
addons/stock/wizard/stock_change_product_qty_view.xml [deleted file]

index d89e62d..b07f732 100644 (file)
             <field name="model">product.product</field>
             <field name="inherit_id" ref="product.product_normal_form_view"/>
             <field name="arch" type="xml">
-                 <xpath expr="//group[@name='procurement_uom']" position="after">
+                <xpath expr="//group[@name='procurement_uom']" position="after">
                     <group name="delay" string="Delays" attrs="{'invisible':[('type','=','service')]}">
                         <label for="produce_delay" />
                         <div attrs="{'invisible':[('type','=','service')]}">
                         </div>                        
                     </group>                
                 </xpath>
+                 <xpath expr="//group[@name='lot']" position="inside">
+                    <field name="track_production" groups="stock.group_production_lot" attrs="{'invisible': [('track_all', '=', True)]}"/>
+                </xpath>
             </field>
         </record>
         
index dcba1d1..c6b2376 100644 (file)
@@ -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 = {
index 45097bb..33f629e 100644 (file)
@@ -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.
index 9e286fa..140d1c4 100644 (file)
@@ -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',
index 06a57fe..6ca53a5 100644 (file)
@@ -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'),
index 1141f16..a1b6588 100644 (file)
@@ -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
index f112739..58f5205 100644 (file)
                         <field name="virtual_available" class="oe_inline"/>
                     </group>
                     <group name="lot" groups="stock.group_tracking_lot,stock.group_production_lot" string="Lots">
-                        <field name="track_production" groups="stock.group_production_lot"/>
-                        <field name="track_incoming" groups="stock.group_tracking_lot"/>
-                        <field name="track_outgoing" groups="stock.group_tracking_lot"/>
+                        <field name="track_all" groups="stock.group_tracking_lot"/>
+                        <field name="track_incoming" groups="stock.group_tracking_lot" attrs="{'invisible': [('track_all', '=', True)]}"/>
+                        <field name="track_outgoing" groups="stock.group_tracking_lot" attrs="{'invisible': [('track_all', '=', True)]}"/>
                     </group>
                 </group>
             </field>
index a29f320..eace40b 100644 (file)
@@ -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 (file)
index 3b40557..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-#    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 <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-
-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 (file)
index 18c548b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<openerp>
-    <data>
-        <record id="view_change_product_quantity" model="ir.ui.view">
-            <field name="name">Change Product Quantity</field>
-            <field name="model">stock.change.product.qty</field>
-            <field name="arch" type="xml">
-                <form string="Update Product Quantity" version="7.0">
-                    <group>
-                        <field name="new_quantity" />
-                        <field name="product_id" invisible="1"/>
-                        <field name="location_id" groups="stock.group_locations"/>
-                        <field name="lot_id"  context="{'search_default_product_id':product_id,'default_product_id':product_id}" groups="stock.group_tracking_lot"/>
-                    </group>
-                    <footer>
-                        <button name="change_product_qty" string="_Apply" type="object" class="oe_highlight"/>
-                        or
-                        <button string="Cancel" class="oe_link" special="cancel" />
-                    </footer>
-                </form>
-            </field>
-        </record>
-
-        <record id="action_view_change_product_quantity" model="ir.actions.act_window">
-            <field name="name">Update Product Quantity</field>
-            <field name="type">ir.actions.act_window</field>
-            <field name="res_model">stock.change.product.qty</field>
-            <field name="view_type">form</field>
-            <field name="view_mode">form</field>
-            <field name="view_id" ref="view_change_product_quantity"/>
-            <field name="target">new</field>
-        </record>
-
-    </data>
-</openerp>
-