openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #06660
[Merge] lp:~openerp-dev/openobject-addons/trunk-button-move-pso into lp:~openerp-dev/openobject-addons/trunk-account-asset
Priyesh (Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-button-move-pso 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-button-move-pso/+merge/60756
Added new button creating move and move lines and linked that move to the depreciation line
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-button-move-pso/+merge/60756
Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openobject-addons/trunk-button-move-pso into lp:~openerp-dev/openobject-addons/trunk-account-asset.
=== modified file 'account_asset/account_asset.py'
--- account_asset/account_asset.py 2011-05-11 06:47:44 +0000
+++ account_asset/account_asset.py 2011-05-12 10:16:28 +0000
@@ -29,11 +29,11 @@
_columns = {
'name': fields.char('Asset category', size=64, required=True, select=1),
'note': fields.text('Note'),
- 'journal_analytic_id': fields.many2one('account.analytic.journal', 'Analytic journal'), #FIXME:add in the form view with group = analytic
+ 'journal_analytic_id': fields.many2one('account.analytic.journal', 'Analytic journal'), #FIXME:add in the form view with group = analytic
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic account'), #FIXME:add in the form view with group = analytic
'account_asset_id': fields.many2one('account.account', 'Asset Account', required=True),
'account_depreciation_id': fields.many2one('account.account', 'Depreciation Account', required=True),
- 'account_expense_depreciation_id': fields.many2one('account.account', 'Depr. Expense Account',),#FIXME: required=True + add in the form view
+ 'account_expense_depreciation_id': fields.many2one('account.account', 'Depr. Expense Account', required=True),#FIXME: required=True + add in the form view
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'company_id': fields.many2one('res.company', 'Company'),
}
@@ -76,14 +76,14 @@
SELECT a.id as id, COALESCE(MAX(l.date),a.purchase_date) AS date
FROM account_asset_asset a
LEFT JOIN account_move_line l ON (l.asset_id = a.id)
- WHERE a.id IN %s
+ WHERE a.id IN %s
GROUP BY a.id, a.purchase_date """, (tuple(ids),))
return dict(cr.fetchall())
def compute_depreciation_board(self, cr, uid,ids, context=None):
depreciation_lin_obj = self.pool.get('account.asset.depreciation.line')
for asset in self.browse(cr, uid, ids, context=context):
- old_depreciation_line_ids = depreciation_lin_obj.search(cr, uid, [('asset_id', '=', asset.id), ('move_line_id', '=', False)])
+ 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)
@@ -286,8 +286,53 @@
'remaining_value': fields.float('Amount to Depreciate', required=True),
'depreciated_value': fields.float('Amount Already Depreciated', required=True),
'depreciation_date': fields.char('Depreciation Date', size=64, select=1),
- 'move_line_id': fields.many2one('account.move.line', 'Depreciation Entry'),
+ 'move_id': fields.many2one('account.move', 'Depreciation Entry'),
}
+
+ def create_move(self, cr, uid,ids, context=None):
+ asset_obj = self.pool.get('account.asset.asset')
+ period_obj = self.pool.get('account.period')
+ move_obj = self.pool.get('account.move')
+ move_line_obj = self.pool.get('account.move.line')
+ for line in self.browse(cr, uid, ids, context=context):
+ depreciation_date = asset_obj._get_last_depreciation_date(cr, uid, [line.asset_id.id], context=context)[line.asset_id.id]
+ period_ids = period_obj.find(cr, uid, depreciation_date, context=context)
+ move_vals = {
+ 'name': line.name,
+ 'date': depreciation_date,
+ 'period_id': period_ids and period_ids[0] or False,
+ 'journal_id': line.asset_id.category_id.journal_id.id,
+ }
+ move_id = move_obj.create(cr, uid, move_vals, context=context)
+ move_line_obj.create(cr, uid, {
+ 'name': line.name,
+ 'move_id': move_id,
+ 'account_id': line.asset_id.category_id.account_expense_depreciation_id.id,
+ 'debit': 0.0,
+ 'credit': line.amount,
+ 'period_id': period_ids and period_ids[0] or False,
+ 'journal_id': line.asset_id.category_id.journal_id.id,
+ 'partner_id': line.asset_id.partner_id.id,
+ 'currency_id': line.asset_id.currency_id.id,
+ 'analytic_account_id': line.asset_id.category_id.account_analytic_id.id,
+ 'date': depreciation_date,
+ })
+ move_line_obj.create(cr, uid, {
+ 'name': line.name,
+ 'move_id': move_id,
+ 'account_id': line.asset_id.category_id.account_depreciation_id.id,
+ 'credit': 0.0,
+ 'debit': line.amount,
+ 'period_id': period_ids and period_ids[0] or False,
+ 'journal_id': line.asset_id.category_id.journal_id.id,
+ 'partner_id': line.asset_id.partner_id.id,
+ 'currency_id': line.asset_id.currency_id.id,
+ 'analytic_account_id': line.asset_id.category_id.account_analytic_id.id,
+ 'date': depreciation_date,
+ })
+ self.write(cr, uid, line.id, {'move_id': move_id}, context=context)
+ return True
+
account_asset_depreciation_line()
#class account_asset_property(osv.osv):
=== modified file 'account_asset/account_asset_view.xml'
--- account_asset/account_asset_view.xml 2011-05-10 18:52:09 +0000
+++ account_asset/account_asset_view.xml 2011-05-12 10:16:28 +0000
@@ -88,6 +88,8 @@
<field name="amount"/>
<field name="depreciated_value"/>
<field name="remaining_value"/>
+ <field name="move_id" invisible="1"/>
+ <button name="create_move" attrs="{'invisible':[('move_id','!=',False)]}" icon="gtk-execute" string="Create Move" type="object"/>
</tree>
<graph type="bar">
<field name="name"/>
Follow ups