Bharat Devnani (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-account-asset-add-date-field-bde into 
lp:~openerp-dev/openobject-addons/trunk-account-asset.

Requested reviews:
  Bharat Devnani (Open ERP) (bde-openerp)
  qdp (OpenERP) (qdp)
  Mustufa Rangwala (Open ERP) (mra-tinyerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-asset-add-date-field-bde/+merge/62604

Hello Sir,

I have added the feature of ending period: choose a date and the number of 
month between 2 depreciations.


Thanks & Regards,
Devnani Bharat R.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-asset-add-date-field-bde/+merge/62604
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-account-asset.
=== modified file 'account_asset/account_asset.py'
--- account_asset/account_asset.py	2011-05-27 14:50:49 +0000
+++ account_asset/account_asset.py	2011-06-01 11:56:48 +0000
@@ -105,7 +105,23 @@
             old_depreciation_line_ids = depreciation_lin_obj.search(cr, uid, [('asset_id', '=', asset.id), ('move_id', '=', False)])
             if old_depreciation_line_ids:
                 depreciation_lin_obj.unlink(cr, uid, old_depreciation_line_ids, context=context)
-            undone_dotation_number = asset.method_delay - len(asset.account_move_line_ids)
+            purchase_date = datetime.strptime(asset.purchase_date, '%Y-%m-%d')
+            ending_period_date = datetime.strptime(asset.ending_period_date, '%Y-%m-%d')
+            if asset.method_time == 'end':
+                undone_dotation_number = 0
+                depreciation_date = purchase_date
+                while True:                    
+                    day = depreciation_date.day
+                    month = depreciation_date.month
+                    year = depreciation_date.year
+                    if depreciation_date <= ending_period_date:
+                        newMonths =  month + asset.method_period
+                        depreciation_date = datetime(year + (newMonths / 12), newMonths % 12, day)
+                        undone_dotation_number += 1
+                    else:
+                        break
+            elif asset.method_time == 'delay':
+                undone_dotation_number = asset.method_delay - len(asset.account_move_line_ids)
             residual_amount = asset.value_residual
             depreciation_date = datetime.strptime(self._get_last_depreciation_date(cr, uid, [asset.id], context)[asset.id], '%Y-%m-%d')
             day = depreciation_date.day
@@ -139,7 +155,6 @@
             'state':'open'
         }, context)
 
-    
 
     def _amount_residual(self, cr, uid, ids, name, args, context={}):
         cr.execute("""SELECT
@@ -159,21 +174,20 @@
         'period_id': fields.many2one('account.period', 'First Period', required=True, readonly=True, states={'draft':[('readonly',False)]}),
         'account_move_line_ids': fields.one2many('account.move.line', 'asset_id', 'Entries', readonly=True, states={'draft':[('readonly',False)]}),
 
-        'name': fields.char('Asset', size=64, required=True, select=1),
-        'code': fields.char('Reference ', size=16, select=1),
-        'purchase_value': fields.float('Gross value ', required=True, size=16, select=1),
-        'currency_id': fields.many2one('res.currency','Currency',required=True,size=5,select=1),
+        'name': fields.char('Asset', size=64, required=True, select=1, readonly=True, states={'draft':[('readonly',False)]}),
+        'code': fields.char('Reference ', size=16, select=1, readonly=True, states={'draft':[('readonly',False)]}),
+        'purchase_value': fields.float('Gross value ', required=True, size=16, select=1, readonly=True, states={'draft':[('readonly',False)]}),
+        'currency_id': fields.many2one('res.currency','Currency',required=True,size=5,select=1, readonly=True, states={'draft':[('readonly',False)]}),
         'company_id': fields.many2one('res.company', 'Company', required=True),
         'note': fields.text('Note'),
-        'category_id': fields.many2one('account.asset.category', 'Asset category',required=True, change_default=True),
+        'category_id': fields.many2one('account.asset.category', 'Asset category',required=True, change_default=True, readonly=True, states={'draft':[('readonly',False)]}),
         'localisation': fields.char('Localisation', size=32, select=2),
         'parent_id': fields.many2one('account.asset.asset', 'Parent Asset'),
         'child_ids': fields.one2many('account.asset.asset', 'parent_id', 'Children Assets'),
-        'purchase_date': fields.date('Purchase Date', required=True),
+        'purchase_date': fields.date('Purchase Date', required=True , readonly=True, states={'draft':[('readonly',False)]}),
         'state': fields.selection([('draft','Draft'),('open','Running'),('close','Close')], 'state', required=True),
         'active': fields.boolean('Active', select=2),
-        'partner_id': fields.many2one('res.partner', 'Partner'),
-
+        'partner_id': fields.many2one('res.partner', 'Partner', readonly=True, states={'draft':[('readonly',False)]}),
         'method': fields.selection([('linear','Linear'),('progressif','Progressive')], 'Computation method', required=True, readonly=True, states={'draft':[('readonly',False)]}),
         'method_delay': fields.integer('During (interval)', readonly=True, states={'draft':[('readonly',False)]}),
         'method_period': fields.integer('Depre. all (period)', readonly=True, states={'draft':[('readonly',False)]}),
@@ -181,10 +195,11 @@
         'method_progress_factor': fields.float('Progressif Factor', readonly=True, states={'draft':[('readonly',False)]}),
         'value_residual': fields.function(_amount_residual, method=True, digits_compute=dp.get_precision('Account'), string='Residual Value'),
         'method_time': fields.selection([('delay','Delay'),('end','Ending Period')], 'Time Method', required=True, readonly=True, states={'draft':[('readonly',False)]}),
-        'prorata':fields.boolean('Prorata Temporis', Readonly="True", help='Indicates that the accounting entries for this asset have to be done from the purchase date instead of the first January'),
+        'prorata':fields.boolean('Prorata Temporis', Readonly="True", help='Indicates that the accounting entries for this asset have to be done from the purchase date instead of the first January', readonly=True, states={'draft':[('readonly',False)]}),
         'history_ids': fields.one2many('account.asset.history', 'asset_id', 'History', readonly=True),
         'depreciation_line_ids': fields.one2many('account.asset.depreciation.line', 'asset_id', 'Depreciation Lines', readonly=True,),
         'salvage_value': fields.float('Salvage Value', digits_compute=dp.get_precision('Account'), help="It is the amount you plan to have that you cannot depreciate."),
+        'ending_period_date': fields.date("Ending Period Date", readonly=True, states={'draft':[('readonly',False)]}, help="Depreciation lines will be calculated up to a given date"),
     }
     _defaults = {
         'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'account.asset.code'),
@@ -193,9 +208,9 @@
         'state': lambda obj, cr, uid, context: 'draft',
         'period_id': _get_period,
         'method': lambda obj, cr, uid, context: 'linear',
+        'method_period': lambda obj, cr, uid, context: 12,
         'method_delay': lambda obj, cr, uid, context: 5,
         'method_time': lambda obj, cr, uid, context: 'delay',
-        'method_period': lambda obj, cr, uid, context: 12,
         'method_progress_factor': lambda obj, cr, uid, context: 0.3,
         'currency_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
         'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'account.asset.asset',context=context),

=== modified file 'account_asset/account_asset_view.xml'
--- account_asset/account_asset_view.xml	2011-05-27 13:49:30 +0000
+++ account_asset/account_asset_view.xml	2011-06-01 11:56:48 +0000
@@ -19,6 +19,7 @@
                     <separator string="Depreciation Dates" colspan="2" />
                     <field name="method_time"/>
                     <field name="method_delay"/>
+                    <field name="method_period" attrs="{'invisible':[('method_time','=','end')]}"/>
                     <field name="method_period" attrs="{'invisible':[('method_time','=','end')]}"/>                
                 </group>
                 <group colspan="2" col="2">
@@ -77,20 +78,22 @@
                     <field name="partner_id"/>
                     <field name="purchase_date"/>
                     <separator string="Depreciation duration" colspan="4"/>
-                    <button 
-                         name="%(wizard_asset_modify)d" 
-                         states="open" 
-                         string="Change duration" 
-                         type="action" 
+                    <button
+                         name="%(wizard_asset_modify)d"
+                         states="open"
+                         string="Change duration"
+                         type="action"
                          colspan="2"/>
                     <newline/>
                     <field name="method"/>
                     <field name="method_progress_factor" attrs="{'invisible':[('method','=','linear')]}"/>
                     <newline/>
                     <field name="method_time"/>
-                    <field name="method_period" attrs="{'invisible':[('method_time','=','end')]}"/>
+                    <field name="method_period"/>
                     <field name="prorata" colspan="1"/>
-                    <field name="method_delay"/>
+                    <field name="method_delay" attrs="{'invisible':[('method_time','=','end')]}"/>
+                    <label colspan="2"/>
+                    <field name="ending_period_date" attrs="{'invisible':[('method_time','=','delay')],'required':[('method_time','in', ('end'))]}"/>
                     <newline/>
                  </page>
                  <page string="Depreciation board">
@@ -118,7 +121,7 @@
                  </page>
                  <page string="Notes">
                     <field name="note" nolabel="1"/>
-                 </page>    
+                 </page>
               </notebook>
               <field name="state" readonly="1"/>
               <group colspan="2" col="2">

_______________________________________________
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