From 8fdf046df2f3656ff16f048f54fbc00870120af9 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 10 May 2017 14:26:32 +0200 Subject: [PATCH] [REF] account_check_printing: avoid duplicated code Small refactoring necessary for the following commit, to avoid duplicated code. opw-742305 --- .../models/account_payment.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/addons/account_check_printing/models/account_payment.py b/addons/account_check_printing/models/account_payment.py index 13b9e39cb22..ef33dc05ae4 100644 --- a/addons/account_check_printing/models/account_payment.py +++ b/addons/account_check_printing/models/account_payment.py @@ -29,13 +29,7 @@ class AccountRegisterPayments(models.TransientModel): def _onchange_amount(self): if hasattr(super(AccountRegisterPayments, self), '_onchange_amount'): super(AccountRegisterPayments, self)._onchange_amount() - # TODO: merge, refactor and complete the amount_to_text and amount_to_text_en classes - check_amount_in_words = amount_to_text_en.amount_to_text(math.floor(self.amount), lang='en', currency='') - check_amount_in_words = check_amount_in_words.replace(' and Zero Cent', '') # Ugh - decimals = self.amount % 1 - if decimals >= 10**-2: - check_amount_in_words += _(' and %s/100') % str(int(round(float_round(decimals*100, precision_rounding=1)))) - self.check_amount_in_words = check_amount_in_words + self.check_amount_in_words = self.env['account.payment']._get_check_amount_in_words(self.amount) def get_payment_vals(self): res = super(AccountRegisterPayments, self).get_payment_vals() @@ -56,6 +50,15 @@ class AccountPayment(models.Model): help="The selected journal is configured to print check numbers. If your pre-printed check paper already has numbers " "or if the current numbering is wrong, you can change it in the journal configuration page.") + def _get_check_amount_in_words(self, amount): + # TODO: merge, refactor and complete the amount_to_text and amount_to_text_en classes + check_amount_in_words = amount_to_text_en.amount_to_text(math.floor(amount), lang='en', currency='') + check_amount_in_words = check_amount_in_words.replace(' and Zero Cent', '') # Ugh + decimals = amount % 1 + if decimals >= 10**-2: + check_amount_in_words += _(' and %s/100') % str(int(round(float_round(decimals*100, precision_rounding=1)))) + return check_amount_in_words + @api.onchange('journal_id') def _onchange_journal_id(self): if hasattr(super(AccountPayment, self), '_onchange_journal_id'): @@ -67,12 +70,7 @@ class AccountPayment(models.Model): def _onchange_amount(self): if hasattr(super(AccountPayment, self), '_onchange_amount'): super(AccountPayment, self)._onchange_amount() - check_amount_in_words = amount_to_text_en.amount_to_text(math.floor(self.amount), lang='en', currency='') - check_amount_in_words = check_amount_in_words.replace(' and Zero Cent', '') # Ugh - decimals = self.amount % 1 - if decimals >= 10**-2: - check_amount_in_words += _(' and %s/100') % str(int(round(float_round(decimals*100, precision_rounding=1)))) - self.check_amount_in_words = check_amount_in_words + self.check_amount_in_words = self._get_check_amount_in_words(self.amount) def _check_communication(self, payment_method_id, communication): super(AccountPayment, self)._check_communication(payment_method_id, communication)