[IMP] account_asset: asset compute wizard upgrading to osv memory + fixing in the same wizard

bzr revid: qdp-launchpad@openerp.com-20110710004535-fg9r6zv0twq4c1q3
This commit is contained in:
Quentin (OpenERP) 2011-07-10 02:45:35 +02:00
parent 0c8ee36516
commit 1bfecd11d7
4 changed files with 38 additions and 91 deletions

View File

@ -39,17 +39,14 @@
"security/ir.model.access.csv",
"account_asset_wizard.xml",
"wizard/account_asset_change_duration_view.xml",
"wizard/wizard_asset_compute_view.xml",
"account_asset_view.xml",
"account_asset_invoice_view.xml",
"report/account_asset_report_view.xml",
#modif
],
# "translations" : {
# "fr": "i18n/french_fr.csv"
# },
"active": False,
"installable": True,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -283,7 +283,7 @@ class account_asset_asset(osv.osv):
period_obj = self.pool.get('account.period')
depreciation_obj = self.pool.get('account.asset.depreciation.line')
period = period_obj.browse(cr, uid, period_id, context=context)
depreciation_ids = depreciation_obj.search(cr, uid, [('asset_id', 'in', ids), ('depreciation_date','<',period.date_stop), ('depreciation_date', '>', period.date_start)], context=context)
depreciation_ids = depreciation_obj.search(cr, uid, [('asset_id', 'in', ids), ('depreciation_date', '<', period.date_stop), ('depreciation_date', '>', period.date_start), ('move_check', '=', False)], context=context)
return depreciation_obj.create_move(cr, uid, depreciation_ids, context=context)
def create(self, cr, uid, vals, context=None):
@ -336,16 +336,16 @@ class account_asset_depreciation_line(osv.osv):
context.update({'date': depreciation_date})
amount = currency_obj.compute(cr, uid, current_currency, company_currency, line.amount, context=context)
sign = line.asset_id.category_id.journal_id.type = 'purchase' and 1 or -1
asset_name = line.asset_id.name
reference = line.name
move_vals = {
'name': line.name,
'name': asset_name,
'date': depreciation_date,
'ref': line.name,
'ref': reference,
'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)
asset_name = line.asset_id.name
reference = line.name
journal_id = line.asset_id.category_id.journal_id.id
partner_id = line.asset_id.partner_id.id
move_line_obj.create(cr, uid, {

View File

@ -8,13 +8,6 @@
name="account.asset.compute"
keyword="tree_but_action"
id="wizard_asset_compute"/>
<menuitem
parent="account.menu_finance_periodical_processing"
action="wizard_asset_compute"
type="wizard"
id="menu_wizard_asset_compute"/>
<wizard
string="Modify asset"
model="account.asset.asset"

View File

@ -19,85 +19,42 @@
#
##############################################################################
import wizard
import pooler
from osv import osv, fields
from tools.translate import _
asset_end_arch = '''<?xml version="1.0"?>
<form string="Compute assets">
<separator string="Generated entries" colspan="4"/>
<field name="move_ids" readonly="1" nolabel="1"/>
</form>'''
asset_end_fields = {
'move_ids': {'string':'Entries', 'type': 'one2many', 'relation':'account.move'},
}
asset_ask_form = '''<?xml version="1.0"?>
<form string="Compute assets">
<field name="period_id"/>
</form>'''
asset_ask_fields = {
'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
}
def _asset_compute(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
ass_obj = pool.get('account.asset.asset')
ids = ass_obj.search(cr, uid, [('state','=','open')], context=context)
ids_create = ass_obj._compute_entries(cr, uid, ids, data['form']['period_id'], context=context)
self.move_ids = ids_create
return {'move_ids': ids_create}
def _asset_open(self, cr, uid, data, context):
value = {
'name': 'Created moves',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move',
'view_id': False,
'type': 'ir.actions.act_window'
class asset_depreciation_confirmation_wizard(osv.osv_memory):
_name = "asset.depreciation.confirmation.wizard"
_description = "asset.depreciation.confirmation.wizard"
_columns = {
'period_id': fields.many2one('account.period', 'Period', required=True, help="Choose the period for which you want to automatically post the depreciation lines of running assets"),
}
def _get_period(self, cr, uid, context=None):
periods = self.pool.get('account.period').find(cr, uid)
if periods:
return periods[0]
return False
_defaults = {
'period_id': _get_period,
}
if data['form']['move_ids']:
value['domain']= "[('id','in',["+','.join(map(str,self.move_ids))+"])]"
else:
value['domain']= "[('id','=', False)]"
return value
def _get_period(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
ids = pool.get('account.period').find(cr, uid, context=context)
period_id = False
if len(ids):
period_id = ids[0]
return {'period_id': period_id}
class wizard_asset_compute(wizard.interface):
states = {
'init': {
'actions': [_get_period],
'result': {'type':'form', 'arch':asset_ask_form, 'fields':asset_ask_fields, 'state':[
('end','Cancel'),
('asset_compute','Compute assets')
]}
},
'asset_compute': {
'actions': [_asset_compute],
'result': {'type' : 'form', 'arch': asset_end_arch, 'fields':asset_end_fields, 'state':[
('end','Close'),
('asset_open','Open entries')
]}
},
'asset_open': {
'actions': [],
'result': {'type':'action', 'action': _asset_open, 'state':'end'}
def asset_compute(self, cr, uid, ids, context):
ass_obj = self.pool.get('account.asset.asset')
asset_ids = ass_obj.search(cr, uid, [('state','=','open')], context=context)
data = self.browse(cr, uid, ids, context=context)
period_id = data[0].period_id.id
created_move_ids = ass_obj._compute_entries(cr, uid, asset_ids, period_id, context=context)
return {
'name': _('Created Asset Moves'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move',
'view_id': False,
'domain': "[('id','in',["+','.join(map(str,created_move_ids))+"])]",
'type': 'ir.actions.act_window',
}
}
wizard_asset_compute('account.asset.compute')
asset_depreciation_confirmation_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: