[ADD] account: convert account_change_currency wizard to osv_memory wizard
bzr revid: psi@tinyerp.co.in-20100414111400-retnjyhy5wmvbwh3
This commit is contained in:
parent
9645d154fd
commit
ddcdd48fee
|
@ -64,6 +64,7 @@ module named account_voucherss
|
|||
'wizard/account_fiscalyear_close_view.xml',
|
||||
'wizard/account_state_open_view.xml',
|
||||
'wizard/account_journal_select_view.xml',
|
||||
'wizard/account_change_currency_view.xml',
|
||||
'project/wizard/project_account_analytic_line_view.xml',
|
||||
'account_view.xml',
|
||||
'account_end_fy.xml',
|
||||
|
|
|
@ -120,6 +120,6 @@
|
|||
<wizard id="wizard_general_journal" menu="False" model="account.journal.period" name="account.general.journal.report" string="Print General Journal" />
|
||||
<menuitem icon="STOCK_PRINT" action="wizard_general_journal" id="menu_general_journal" parent="account.menu_generic_report" type="wizard" />-->
|
||||
|
||||
<wizard id="wizard_invoice_currency_change" model="account.invoice" name="account.invoice.currency_change" string="Change Currency" groups="base.group_user"/>
|
||||
<!-- <wizard id="wizard_invoice_currency_change" model="account.invoice" name="account.invoice.currency_change" string="Change Currency" groups="base.group_user"/>-->
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -56,7 +56,7 @@ import wizard_statement_from_invoice
|
|||
import account_print_journal
|
||||
import account_central_journal
|
||||
import account_general_journal
|
||||
import wizard_change_currency
|
||||
import account_change_currency
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: 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 osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_change_currency(osv.osv_memory):
|
||||
_name = 'account.change.currency'
|
||||
_description = 'Change Currency'
|
||||
_columns = {
|
||||
'currency_id': fields.many2one('res.currency', 'New Currency', required=True),
|
||||
}
|
||||
|
||||
def view_init(self, cr , uid , fields_list, context=None):
|
||||
obj_inv = self.pool.get('account.invoice')
|
||||
if context is None:
|
||||
context = {}
|
||||
state = obj_inv.browse(cr, uid, context['active_id']).state
|
||||
if obj_inv.browse(cr, uid, context['active_id']).state != 'draft':
|
||||
raise osv.except_osv(_('Error'), _('You can not change currency for Open Invoice !'))
|
||||
pass
|
||||
|
||||
def change_currency(self, cr, uid, ids, context=None):
|
||||
obj_inv = self.pool.get('account.invoice')
|
||||
obj_inv_line = self.pool.get('account.invoice.line')
|
||||
obj_currency = self.pool.get('res.currency')
|
||||
if context is None:
|
||||
context = {}
|
||||
data = self.read(cr, uid, ids)[0]
|
||||
new_currency = data['currency_id']
|
||||
|
||||
for invoice in obj_inv.browse(cr, uid, context['active_ids'], context=context):
|
||||
if invoice.currency_id.id == new_currency:
|
||||
continue
|
||||
|
||||
for line in invoice.invoice_line:
|
||||
rate = obj_currency.browse(cr, uid, new_currency).rate
|
||||
new_price = 0
|
||||
if invoice.company_id.currency_id.id == invoice.currency_id.id:
|
||||
new_price = line.price_unit * rate
|
||||
|
||||
if invoice.company_id.currency_id.id != invoice.currency_id.id and invoice.company_id.currency_id.id == new_currency:
|
||||
old_rate = invoice.currency_id.rate
|
||||
new_price = line.price_unit / old_rate
|
||||
|
||||
if invoice.company_id.currency_id.id != invoice.currency_id.id and invoice.company_id.currency_id.id != new_currency:
|
||||
old_rate = invoice.currency_id.rate
|
||||
new_price = (line.price_unit / old_rate ) * rate
|
||||
|
||||
obj_inv_line.write(cr, uid, [line.id], {'price_unit' : new_price})
|
||||
obj_inv.write(cr, uid, [invoice.id], {'currency_id' : new_currency})
|
||||
return {}
|
||||
|
||||
account_change_currency()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_account_change_currency" model="ir.ui.view">
|
||||
<field name="name">Change Currency</field>
|
||||
<field name="model">account.change.currency</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Invoice Currency">
|
||||
<field name="currency_id"/>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="2" col="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="change_currency" string="Change Currency" type="object" icon="gtk-go-forward"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_change_currency" model="ir.actions.act_window">
|
||||
<field name="name">Change Currency</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">account.change.currency</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_account_change_currency"/>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.values" id="account_change_currency">
|
||||
<field name="model_id" ref="account.model_account_invoice" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Change Currency</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_account_change_currency'))"/>
|
||||
<field name="key">action</field>
|
||||
<field name="model">account.invoice</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,106 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
import wizard
|
||||
import pooler
|
||||
|
||||
class wizard_change_currency(wizard.interface):
|
||||
'''
|
||||
OpenERP Wizard
|
||||
'''
|
||||
form = '''<?xml version="1.0"?>
|
||||
<form string="Invoice Currency">
|
||||
<field name="currency_id"/>
|
||||
</form>'''
|
||||
|
||||
message = '''<?xml version="1.0"?>
|
||||
<form string="Invoice Currency">
|
||||
<label string="You can not change currency for Open Invoice !"/>
|
||||
</form>'''
|
||||
|
||||
fields = {
|
||||
'currency_id': {'string': 'New Currency', 'type': 'many2one', 'relation': 'res.currency', 'required':True},
|
||||
}
|
||||
|
||||
def _get_defaults(self, cr, user, data, context):
|
||||
#TODO : initlize required data
|
||||
|
||||
return data['form']
|
||||
|
||||
def _change_currency(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
inv_obj = pool.get('account.invoice')
|
||||
inv_line_obj = pool.get('account.invoice.line')
|
||||
curr_obj = pool.get('res.currency')
|
||||
|
||||
invoice_ids = data['ids']
|
||||
new_currency = data['form']['currency_id']
|
||||
|
||||
for invoice in inv_obj.browse(cr, uid, invoice_ids, context=context):
|
||||
if invoice.currency_id.id == new_currency:
|
||||
continue
|
||||
|
||||
for line in invoice.invoice_line:
|
||||
rate = curr_obj.browse(cr, uid, new_currency).rate
|
||||
new_price = 0
|
||||
if invoice.company_id.currency_id.id == invoice.currency_id.id:
|
||||
new_price = line.price_unit * rate
|
||||
|
||||
if invoice.company_id.currency_id.id != invoice.currency_id.id and invoice.company_id.currency_id.id == new_currency:
|
||||
old_rate = invoice.currency_id.rate
|
||||
new_price = line.price_unit / old_rate
|
||||
|
||||
if invoice.company_id.currency_id.id != invoice.currency_id.id and invoice.company_id.currency_id.id != new_currency:
|
||||
old_rate = invoice.currency_id.rate
|
||||
new_price = (line.price_unit / old_rate ) * rate
|
||||
|
||||
inv_line_obj.write(cr, uid, [line.id], {'price_unit':new_price})
|
||||
inv_obj.write(cr, uid, [invoice.id], {'currency_id':new_currency})
|
||||
return {}
|
||||
|
||||
def _check_what_next(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
inv_obj = pool.get('account.invoice')
|
||||
if inv_obj.browse(cr, uid, data['id']).state != 'draft':
|
||||
return 'message'
|
||||
|
||||
return 'change'
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'choice', 'next_state': _check_what_next},
|
||||
},
|
||||
'change': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch': form, 'fields': fields, 'state': (('end', 'Cancel', 'gtk-cancel'), ('next', 'Change Currency', 'gtk-go-forward'))},
|
||||
},
|
||||
'next': {
|
||||
'actions': [_change_currency],
|
||||
'result': {'type': 'state', 'state': 'end'},
|
||||
},
|
||||
'message': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch': message, 'fields': {}, 'state': [('end', 'Ok', 'gtk-cancel')]},
|
||||
},
|
||||
}
|
||||
wizard_change_currency('account.invoice.currency_change')
|
Loading…
Reference in New Issue