/
account_move_change_rate.py
37 lines (31 loc) · 1.32 KB
/
account_move_change_rate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
class AccountMoveChangeRate(models.TransientModel):
_name = 'account.move.change.rate'
_description = 'account.move.change.rate'
@api.model
def get_move(self):
move = self.env['account.move'].browse(
self._context.get('active_id', False))
return move
currency_rate = fields.Float(
'Currency Rate',
required=True,
digits=(16, 6),
help="Select a rate to apply on the invoice"
)
move_id = fields.Many2one(
'account.move',
default=get_move
)
@api.onchange('move_id')
def _onchange_move(self):
self.currency_rate = self.move_id.l10n_ar_currency_rate or self.move_id.computed_currency_rate
def confirm(self):
message = _("Currency rate changed from %s to %s") % (self.move_id.l10n_ar_currency_rate or self.move_id.computed_currency_rate, self.currency_rate)
self.move_id.message_post(body=message)
self.move_id.l10n_ar_currency_rate = self.currency_rate
return {'type': 'ir.actions.act_window_close'}