[IMP] mrp: Improve 'Change Standard Price' wizard to change price of Parent product...
authoruco <uco@tinyerp.com>
Sat, 10 Jul 2010 09:20:07 +0000 (14:50 +0530)
committeruco <uco@tinyerp.com>
Sat, 10 Jul 2010 09:20:07 +0000 (14:50 +0530)
bzr revid: uco@tinyerp.com-20100710092007-yp8j0mjzxbf6hqj5

addons/mrp/__openerp__.py
addons/mrp/product.py
addons/mrp/wizard/__init__.py
addons/mrp/wizard/mrp_change_standard_price.py [new file with mode: 0644]
addons/mrp/wizard/mrp_change_standard_price_view.xml [new file with mode: 0644]

index 3065516..5fc5456 100644 (file)
@@ -69,6 +69,7 @@
         'wizard/change_production_qty_view.xml',
         'wizard/mrp_price_view.xml',
         'wizard/mrp_workcenter_load_view.xml',
+        'wizard/mrp_change_standard_price_view.xml',
 #        'wizard/mrp_track_prod_view.xml',
         'mrp_view.xml',
         'mrp_wizard.xml',
index 8954d23..1af0bd6 100644 (file)
@@ -63,11 +63,12 @@ class product_product(osv.osv):
         """
         res = super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context=context)
         bom_obj = self.pool.get('mrp.bom')
+        change = context.get('change_parent_price', False)
         def _compute_price(bom):
             price = 0.0
-            if bom.bom_id :
-                if bom.bom_id.bom_lines :
-                    for bom_line in bom.bom_id.bom_lines :
+            if bom.bom_id and change:
+                if bom.bom_id.bom_lines:
+                    for bom_line in bom.bom_id.bom_lines:
                         prod_price = self.read(cr, uid, bom_line.product_id.id, ['standard_price'])['standard_price']
                         price += bom_line.product_qty * prod_price
 
index aa4408e..be14888 100644 (file)
@@ -24,6 +24,7 @@ import mrp_price
 import mrp_workcenter_load
 #import mrp_track_prod
 import change_production_qty
+import mrp_change_standard_price
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
diff --git a/addons/mrp/wizard/mrp_change_standard_price.py b/addons/mrp/wizard/mrp_change_standard_price.py
new file mode 100644 (file)
index 0000000..0a5a054
--- /dev/null
@@ -0,0 +1,48 @@
+# -*- 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 osv import fields, osv
+
+class change_standard_price(osv.osv_memory):
+    _inherit = "stock.change.standard.price"
+    _description = "Change Standard Price"
+    
+    _columns = {
+        'change_parent_price': fields.boolean('Change Parent Price'),
+    }
+    
+    
+    def change_price(self, cr, uid, ids, context):
+        """ Changes the Standard Price of Parent Product according to BoM 
+            only when the field 'change_parent_price' is True.
+            And creates an account move accordingly.
+        @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:
+        """
+        res = self.browse(cr, uid, ids) 
+        context.update({'change_parent_price': res[0].change_parent_price})
+        return super(change_standard_price, self).change_price(cr, uid, ids, context=context)
+    
+change_standard_price()
diff --git a/addons/mrp/wizard/mrp_change_standard_price_view.xml b/addons/mrp/wizard/mrp_change_standard_price_view.xml
new file mode 100644 (file)
index 0000000..6c9b205
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="view_change_standard_price_inherit" model="ir.ui.view">
+            <field name="name">Change Standard Price (Inherit)</field>
+            <field name="model">stock.change.standard.price</field>
+            <field name="inherit_id" ref="stock.view_change_standard_price"/>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+              <field name="new_price" position="after">                 
+                    <field name="change_parent_price"/>
+              </field>
+            </field>
+        </record>
+
+    </data>
+</openerp>