[IMP] Domain on model instead of view + no production order without consume lines
authorJosse Colpaert <jco@odoo.com>
Fri, 22 Aug 2014 15:28:04 +0000 (17:28 +0200)
committerJosse Colpaert <jco@odoo.com>
Wed, 3 Sep 2014 17:18:17 +0000 (19:18 +0200)
addons/mrp/mrp.py
addons/mrp/mrp_view.xml

index a8c39c7..356326d 100644 (file)
@@ -198,9 +198,9 @@ class mrp_bom(osv.osv):
         'type': fields.selection([('normal', 'Normal'), ('phantom', 'Set')], 'BoM Type', required=True,
                 help= "Set: When processing a sales order for this product, the delivery order will contain the raw materials, instead of the finished product."),
         'position': fields.char('Internal Reference', help="Reference to a position in an external plan."),
-        'product_tmpl_id': fields.many2one('product.template', 'Product', required=True),
+        'product_tmpl_id': fields.many2one('product.template', 'Product', domain="[('type', '!=', 'service')]", required=True),
         'product_id': fields.many2one('product.product', 'Product Variant',
-            domain="[('product_tmpl_id','=',product_tmpl_id)]",
+            domain="['&', ('product_tmpl_id','=',product_tmpl_id), ('type','!=', 'service')]",
             help="If a product variant is defined the BOM is available only for this product."),
         'bom_line_ids': fields.one2many('mrp.bom.line', 'bom_id', 'BoM Lines', copy=True),
         'product_qty': fields.float('Product Quantity', required=True, digits_compute=dp.get_precision('Product Unit of Measure')),
@@ -1155,6 +1155,9 @@ class mrp_production(osv.osv):
                     stock_moves.append(stock_move_id)
             if stock_moves:
                 self.pool.get('stock.move').action_confirm(cr, uid, stock_moves, context=context)
+            else:
+                raise osv.except_osv(_('Error!'),
+                        _('It does not make sense to create a production order without any physical product to consume'))
             production.write({'state': 'confirmed'}, context=context)
         return 0
 
index 81c7885..7659dc1 100644 (file)
                 <form string="Bill of Material">
                     <group>
                         <group>
-                            <field name="product_tmpl_id" domain="[('type', '!=', 'service')]" on_change="onchange_product_tmpl_id(product_tmpl_id, product_qty, context)"/>
-                            <field name="product_id" domain="[('type', '!=', 'service')]"/>
+                            <field name="product_tmpl_id" on_change="onchange_product_tmpl_id(product_tmpl_id, product_qty, context)"/>
+                            <field name="product_id"/>
                             <label for="product_qty" string="Quantity"/>
                             <div>
                                 <field name="product_qty" class="oe_inline" on_change="onchange_product_tmpl_id(product_tmpl_id, product_qty, context)"/>