Ujjvala Collins (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-account-asset-change_duration_wizard-uco
 into lp:~openerp-dev/openobject-addons/trunk-account-asset.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-asset-change_duration_wizard-uco/+merge/65786

[IMP] account_asset:
----------------------------------
-> change duration wizard (on asset form, when it's running) is not working. 
This should has the effect of storing the old values in history lines, with a 
comment on the reason the user changed. Check what the community did for that 
(ref: account-asset pad)

Improvements I did:
----------------------------------
* Converted old style wizard to osv_memory wizard.

* Added Ending date field on the wizard as it is needed when Time method is 
Ending date and it is also there on Asset history object.

* Made some usability changes in Asset view.

* Checked community branch for the same wizard but they have used totally 
different concept than us, so haven't adopted their changes.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-asset-change_duration_wizard-uco/+merge/65786
Your team OpenERP R&D Team is requested to review the proposed merge of 
lp:~openerp-dev/openobject-addons/trunk-account-asset-change_duration_wizard-uco
 into lp:~openerp-dev/openobject-addons/trunk-account-asset.
=== modified file 'account_asset/__openerp__.py'
--- account_asset/__openerp__.py	2011-05-09 09:51:57 +0000
+++ account_asset/__openerp__.py	2011-06-24 13:24:35 +0000
@@ -39,9 +39,10 @@
     "update_xml" : [
         "security/ir.model.access.csv",
         "account_asset_wizard.xml",
+        "wizard/account_asset_change_duration_view.xml",
         "account_asset_view.xml",
         "account_asset_invoice_view.xml",
-	"account_asset_report_view.xml",
+	    "account_asset_report_view.xml",
         "report/account_asset_report_view.xml",
 	#modif
     ],

=== modified file 'account_asset/account_asset_view.xml'
--- account_asset/account_asset_view.xml	2011-06-23 15:15:03 +0000
+++ account_asset/account_asset_view.xml	2011-06-24 13:24:35 +0000
@@ -78,17 +78,18 @@
                     <field name="purchase_date"/>
                     <group colspan="2" col="2">
                         <separator string="Depreciation Dates" colspan="2" />
-                        <button 
-                             name="%(wizard_asset_modify)d" 
-                             states="open" 
-                             string="Change duration" 
-                             type="action" 
-                             colspan="2"/>
-                        <newline/>
                         <field name="method_time" on_change="onchange_method_time(method_time)"/>
                         <field name="method_delay" attrs="{'invisible':[('method_time','=','end')]}"/>
                         <field name="method_period"/>
-                        <field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','=','delay')]}"/> 
+                        <field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','=','delay')]}"/>
+                        <newline/>
+                        <button 
+                             name="%(action_asset_modify)d" 
+                             states="open" 
+                             string="Change Duration" 
+                             type="action"
+                             icon="terp-stock_effects-object-colorize" 
+                             colspan="2"/> 
                     </group>
                     <group colspan="2" col="2">
                         <separator string="Depreciation Method" colspan="2" />

=== modified file 'account_asset/wizard/__init__.py'
--- account_asset/wizard/__init__.py	2011-03-30 13:25:27 +0000
+++ account_asset/wizard/__init__.py	2011-06-24 13:24:35 +0000
@@ -18,9 +18,9 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 #
 ##############################################################################
-
+import account_asset_change_duration
 import wizard_asset_compute
 import wizard_asset_close
-import wizard_asset_modify
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 

=== renamed file 'account_asset/wizard/wizard_asset_modify.py' => 'account_asset/wizard/account_asset_change_duration.py'
--- account_asset/wizard/wizard_asset_modify.py	2011-03-30 13:25:27 +0000
+++ account_asset/wizard/account_asset_change_duration.py	2011-06-24 13:24:35 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #    
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
+#    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
@@ -18,70 +18,77 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 #
 ##############################################################################
-
-import wizard
-import pooler
-
-asset_end_arch = '''<?xml version="1.0"?>
-<form string="Modify asset">
-    <separator string="Asset properties to modify" colspan="4"/>
-    <field name="name" colspan="4"/>
-    <field name="method_delay"/>
-    <field name="method_period"/>
-    <separator string="Notes" colspan="4"/>
-    <field name="note" nolabel="1" colspan="4"/>
-</form>'''
-
-asset_end_fields = {
-    'name': {'string':'Reason', 'type':'char', 'size':64, 'required':True},
-    'method_delay': {'string':'Number of interval', 'type':'float'},
-    'method_period': {'string':'Period per interval', 'type':'float'},
-    'note': {'string':'Notes', 'type':'text'},
-}
-
-def _asset_default(self, cr, uid, data, context={}):
-    pool = pooler.get_pool(cr.dbname)
-    prop = pool.get('account.asset.property').browse(cr, uid, data['id'], context)
-    return {
-        'name': prop.name,
-        'method_delay': prop.method_delay,
-        'method_period': prop.method_period
-    }
-
-def _asset_modif(self, cr, uid, data, context={}):
-    pool = pooler.get_pool(cr.dbname)
-    prop = pool.get('account.asset.property').browse(cr, uid, data['id'], context)
-    pool.get('account.asset.property.history').create(cr, uid, {
-        'asset_property_id': data['id'],
-        'name': prop.name,
-        'method_delay': prop.method_delay,
-        'method_period': prop.method_period,
-        'note': data['form']['note'],
-    }, context)
-    pool.get('account.asset.property').write(cr, uid, [data['id']], {
-        'name': data['form']['name'],
-        'method_delay': data['form']['method_delay'],
-        'method_period': data['form']['method_period'],
-    }, context)
-    return {}
-
-
-class wizard_asset_modify(wizard.interface):
-    states = {
-        'init': {
-            'actions': [_asset_default],
-            'result': {'type':'form', 'arch':asset_end_arch, 'fields':asset_end_fields, 'state':[
-                ('end','Cancel'),
-                ('asset_modify','Modify asset')
-            ]}
-        },
-        'asset_modify': {
-            'actions': [_asset_modif],
-            'result': {'type' : 'state', 'state': 'end'}
-        }
-    }
-wizard_asset_modify('account.asset.modify')
-
+import time
+from osv import osv,fields
+
+class asset_modify(osv.osv_memory):
+    _name = 'asset.modify'
+    _description = 'Modify Asset'
+
+    _columns = {
+        'name': fields.char('Reason', size=64, required=True),
+        'method_delay': fields.float('Number of interval'),
+        'method_period': fields.float('Period per interval'),
+        'method_end': fields.date('Ending date'),
+        'note': fields.text('Notes'),
+    }
+    
+    def default_get(self, cr, uid, fields, context=None):
+        """ 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. 
+        """ 
+        asset_obj = self.pool.get('account.asset.asset')
+        res = super(asset_modify, self).default_get(cr, uid, fields, context=context)
+        asset_id = context.get('active_id', False)
+        asset = asset_obj.browse(cr, uid, asset_id, context=context)
+        if 'name' in fields:
+            res.update({'name': asset.name})
+        if 'method_delay' in fields and asset.method_time == 'delay':
+            res.update({'method_delay': asset.method_delay})
+        if 'method_period' in fields:
+            res.update({'method_period': asset.method_period})
+        if 'method_end' in fields and asset.method_time == 'end':
+            res.update({'method_end': asset.method_end})
+        return res
+    
+    def modify(self, cr, uid, ids, context=None):
+        """ Modifies the duration of asset for calculating depreciation
+        and maintains the history of old values.
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: List of Ids 
+        @param context: A standard dictionary 
+        @return: Close the wizard. 
+        """ 
+        asset_obj = self.pool.get('account.asset.asset')
+        history_obj = self.pool.get('account.asset.history')
+        asset_id = context.get('active_id', False)
+        asset = asset_obj.browse(cr, uid, asset_id, context=context)
+        data = self.browse(cr, uid, ids[0], context=context)
+        history_obj.create(cr, uid, {
+            'asset_id': asset_id,
+            'name': asset.name,
+            'method_delay': asset.method_delay,
+            'method_period': asset.method_period,
+            'method_end': asset.method_end,
+            'user_id': uid,
+            'date': time.strftime('%Y-%m-%d'),
+            'note': data.note,
+        }, context=context)
+        asset_obj.write(cr, uid, [asset_id], {
+            'name': data.name,
+            'method_delay': data.method_delay,
+            'method_period': data.method_period,
+            'method_end': data.method_end,
+        }, context=context)
+        return {'type': 'ir.actions.act_window_close'}
+
+asset_modify()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-

=== added file 'account_asset/wizard/account_asset_change_duration_view.xml'
--- account_asset/wizard/account_asset_change_duration_view.xml	1970-01-01 00:00:00 +0000
+++ account_asset/wizard/account_asset_change_duration_view.xml	2011-06-24 13:24:35 +0000
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+    
+        <record model="ir.ui.view" id="asset_modify_form">
+	        <field name="name">wizard.asset.modify.form</field>
+	        <field name="model">asset.modify</field>
+	        <field name="type">form</field>
+	        <field name="arch" type="xml">
+			    <form string="Modify Asset">
+			        <group colspan="4" col="4">
+					    <separator string="Asset properties to modify" colspan="4"/>
+					    <field name="name" colspan="4"/>
+					    <field name="method_period"/>
+					    <group colspan="2" col="2">
+                            <field name="method_delay" attrs="{'invisible': [('method_end','!=',False)]}"/>
+                            <field name="method_end" attrs="{'invisible': [('method_delay','!=',0.0)]}"/>
+                        </group>
+					    <separator string="Notes" colspan="4"/>
+					    <field name="note" nolabel="1" colspan="4"/>
+                    </group>
+                    <newline/>
+                    <group colspan="4" col="4">
+                        <separator string ="" colspan="4"/>
+                        <newline/>
+                        <group colspan="2" col="2"/>
+                        <button special="cancel" string="Cancel" icon="gtk-cancel"/>
+                        <button name="modify" string="Modify" type="object" icon="terp-check"/>
+                     </group>
+				</form>
+			</field>
+	    </record>
+	    
+	    <record id="action_asset_modify" model="ir.actions.act_window">
+             <field name="name">Modify Asset</field>
+             <field name="res_model">asset.modify</field>
+             <field name="type">ir.actions.act_window</field>
+             <field name="view_type">form</field>
+             <field name="view_mode">tree,form</field>
+             <field name="view_id" ref="asset_modify_form"/>
+             <field name="target">new</field>
+       </record>
+	
+	</data>
+</openerp>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to