[IMP] Adapt mrp workflow and moves + Differ between Bose speakers and Custom Computer
authorJosse Colpaert <jco@odoo.com>
Tue, 26 Aug 2014 10:10:05 +0000 (12:10 +0200)
committerJosse Colpaert <jco@odoo.com>
Wed, 3 Sep 2014 17:18:17 +0000 (19:18 +0200)
addons/mrp/mrp.py
addons/mrp/mrp_workflow.xml
addons/mrp/stock.py
addons/product/product_demo.xml
addons/product/product_image_demo.xml
addons/stock/procurement_demo.xml
addons/stock/stock.py
addons/stock/stock_demo.xml
addons/website_sale/data/demo.xml

index 356326d..9151c15 100644 (file)
@@ -509,7 +509,7 @@ class mrp_production(osv.osv):
         for production in self.browse(cr, uid, ids, context=context):
             res[production.id] = True
             states = [x.state != 'assigned' for x in production.move_lines if x]
-            if any(states) or len(states) == 0:
+            if any(states) or len(states) == 0: #When no moves, ready_production will be False, but test_ready will pass
                 res[production.id] = False
         return res
 
@@ -831,6 +831,8 @@ class mrp_production(osv.osv):
         dicts = {}
         # Find product qty to be consumed and consume it
         for scheduled in production.product_lines:
+            if scheduled.product_id.type == 'service':
+                continue
             product_id = scheduled.product_id.id
 
             consumed_qty = consumed_data.get(product_id, 0.0)
@@ -1018,11 +1020,12 @@ class mrp_production(osv.osv):
         return res
 
     def test_ready(self, cr, uid, ids):
-        res = False
+        res = True
         for production in self.browse(cr, uid, ids):
-            if production.ready_production:
-                res = True
+            if production.move_lines and not production.ready_production:
+                res = False
         return res
+
     
     
     def _make_production_produce_line(self, cr, uid, production, context=None):
@@ -1155,9 +1158,6 @@ 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
 
@@ -1165,9 +1165,12 @@ class mrp_production(osv.osv):
         """
         Checks the availability on the consume lines of the production order
         """
+        from openerp import workflow
         move_obj = self.pool.get("stock.move")
         for production in self.browse(cr, uid, ids, context=context):
             move_obj.action_assign(cr, uid, [x.id for x in production.move_lines], context=context)
+            if self.pool.get('mrp.production').test_ready(cr, uid, [production.id]):
+                workflow.trg_validate(uid, 'mrp.production', production.id, 'moves_ready', cr)
 
 
     def force_production(self, cr, uid, ids, *args):
@@ -1175,9 +1178,12 @@ class mrp_production(osv.osv):
         @param *args: Arguments
         @return: True
         """
+        from openerp import workflow
         move_obj = self.pool.get('stock.move')
         for order in self.browse(cr, uid, ids):
             move_obj.force_assign(cr, uid, [x.id for x in order.move_lines])
+            if self.pool.get('mrp.production').test_ready(cr, uid, [order.id]):
+                workflow.trg_validate(uid, 'mrp.production', order.id, 'moves_ready', cr)
         return True
 
 
index ce565f9..c22b908 100644 (file)
@@ -56,9 +56,7 @@
         <record id="prod_trans_picking_ready" model="workflow.transition">
             <field name="act_from" ref="prod_act_confirmed"/>
             <field name="act_to" ref="prod_act_ready"/>
-            <field name="trigger_model">stock.move</field>
-            <field name="trigger_expr_id">consume_lines_get()</field>
-            <field name="condition">test_ready()</field>
+            <field name="signal">moves_ready</field>
         </record>
         <record id="prod_trans_ready_in_production" model="workflow.transition">
             <field name="act_from" ref="prod_act_ready"/>
index 270ccc7..fcd2ae6 100644 (file)
@@ -228,9 +228,12 @@ class StockMove(osv.osv):
             ids = [ids]
         res = super(StockMove, self).write(cr, uid, ids, vals, context=context)
         from openerp import workflow
-        for move in self.browse(cr, uid, ids, context=context):
-            if move.raw_material_production_id and move.raw_material_production_id.state == 'confirmed':
-                workflow.trg_trigger(uid, 'stock.move', move.id, cr)
+        if vals.get('state') == 'assigned':
+            moves = self.browse(cr, uid, ids, context=context)
+            orders = list(set([x.raw_material_production_id.id for x in moves if x.raw_material_production_id and x.raw_material_production_id.state == 'confirmed']))
+            for order_id in orders:
+                if self.pool.get('mrp.production').test_ready(cr, uid, [order_id]):
+                    workflow.trg_validate(uid, 'mrp.production', order_id, 'moves_ready', cr)
         return res
 
 class stock_warehouse(osv.osv):
index 763c762..093a25b 100644 (file)
@@ -225,11 +225,11 @@ FaceTime HD Camera, 1.2 MP Photos</field>
 
         <!-- -->
 
-        <record id="product_product_5" model="product.product">
+        <record id="product_product_5b" model="product.product">
             <field name="name">Bose Mini Bluetooth Speaker</field>
             <field name="categ_id" ref="accessories"/>
-            <field name="standard_price">600.0</field>
-            <field name="list_price">147.0</field>
+            <field name="standard_price">140.0</field>
+            <field name="list_price">247.0</field>
             <field name="type">consu</field>
             <field name="uom_id" ref="product_uom_unit"/>
             <field name="uom_po_id" ref="product_uom_unit"/>
@@ -239,6 +239,18 @@ FaceTime HD Camera, 1.2 MP Photos</field>
         </record>
 
 
+        <record id="product_product_5" model="product.product">
+            <field name="name">PC Assemble + Custom (PC on Demand) </field>
+            <field name="categ_id" ref="accessories"/>
+            <field name="standard_price">600.0</field>
+            <field name="list_price">147.0</field>
+            <field name="type">consu</field>
+            <field name="uom_id" ref="product_uom_unit"/>
+            <field name="uom_po_id" ref="product_uom_unit"/>
+            <field name="description">Custom computer assembled on order based on customer's requirement.</field>
+            <field name="default_code">B3423</field>
+        </record>
+
         <record id="product_product_6" model="product.product">
             <field name="name">iPad Mini</field>
             <field name="categ_id" ref="ipad"/>
index a9d8e7b..697b313 100644 (file)
         </record>
 
         <record id="product_product_5" model="product.product">
+            <field name="image" type="base64" file="product/static/img/product_product_5-image.jpg"/>
+        </record>
+
+        <record id="product_product_5b" model="product.product">
             <field name="image" type="base64" file="product/static/img/product_product_5-image.png"/>
         </record>
 
index e0cd40a..26fbc81 100644 (file)
@@ -8,12 +8,16 @@
 
         <record id="product.product_product_4" model="product.product">
             <field name="type">product</field>
-
         </record>
+
         <record id="product.product_product_5" model="product.product">
             <field name="type">product</field>
         </record>
 
+        <record id="product.product_product_5b" model="product.product">
+            <field name="type">product</field>
+        </record>
+
         <record id="product.product_product_6" model="product.product">
             <field name="type">product</field>
         </record>
index bbfa193..70c7001 100644 (file)
@@ -2395,7 +2395,6 @@ class stock_move(osv.osv):
         defaults = {
             'product_uom_qty': uom_qty,
             'product_uos_qty': uos_qty,
-            'state': move.state,
             'procure_method': 'make_to_stock',
             'restrict_lot_id': restrict_lot_id,
             'restrict_partner_id': restrict_partner_id,
index 64148c3..5bada91 100644 (file)
@@ -60,7 +60,7 @@
             <field name="location_id" ref="stock_location_14"/>
         </record>
         <record id="stock_inventory_line_15" model="stock.inventory.line">
-            <field name="product_id" ref="product.product_product_5"/>
+            <field name="product_id" ref="product.product_product_5b"/>
             <field name="product_uom_id" ref="product.product_uom_unit"/>
             <field name="inventory_id" ref="stock_inventory_0"/>
             <field name="product_qty">8.0</field>
index 952497b..e72db17 100644 (file)
@@ -60,7 +60,7 @@
             </field>
         </record>
 
-        <record id="product.product_product_5" model="product.product">
+        <record id="product.product_product_5b" model="product.product">
             <field name="website_published" eval="True"/>
             <field name="website_size_x">2</field>
             <field name="website_style_ids" eval="[(6,0,[ref('website_sale.image_promo')])]"/>
@@ -688,7 +688,7 @@ Weight: 1.1 ounces</field>
         <record id="product.product_product_4_product_template" model="product.template">
             <field name="public_categ_ids" eval="[(6,0,[ref('product.Computer_all_in_one')])]"/>
         </record>
-        <record id="product.product_product_5_product_template" model="product.template">
+        <record id="product.product_product_5b_product_template" model="product.template">
             <field name="public_categ_ids" eval="[(6,0,[ref('product.Speakers')])]"/>
         </record>
         <record id="product.product_product_6_product_template" model="product.template">