From 0fab06204c623c037efd9c9f0bb0b05871ff804c Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 10 May 2017 14:43:54 +0200 Subject: [PATCH] [ADD] hr_expense_check: add amount in words on check - Create an expense, approve. - Register the payment by check - Print the check The amount in words is not written. The core of the issue is that the wizard `hr.expense.register.payment.wizard` has been defined as a brand new model instead of inheriting from `account.register.payments`. Hence the Enterprise module "hr_expense_sepa" and now "hr_expense_check". opw-742305 --- addons/hr_expense_check/__init__.py | 1 + addons/hr_expense_check/__manifest__.py | 16 +++++++++ addons/hr_expense_check/models/__init__.py | 1 + addons/hr_expense_check/models/payment.py | 39 ++++++++++++++++++++++ addons/hr_expense_check/views/payment.xml | 18 ++++++++++ 5 files changed, 75 insertions(+) create mode 100644 addons/hr_expense_check/__init__.py create mode 100644 addons/hr_expense_check/__manifest__.py create mode 100644 addons/hr_expense_check/models/__init__.py create mode 100644 addons/hr_expense_check/models/payment.py create mode 100644 addons/hr_expense_check/views/payment.xml diff --git a/addons/hr_expense_check/__init__.py b/addons/hr_expense_check/__init__.py new file mode 100644 index 00000000000..bff786c0885 --- /dev/null +++ b/addons/hr_expense_check/__init__.py @@ -0,0 +1 @@ +import models diff --git a/addons/hr_expense_check/__manifest__.py b/addons/hr_expense_check/__manifest__.py new file mode 100644 index 00000000000..90320ac6f64 --- /dev/null +++ b/addons/hr_expense_check/__manifest__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Check Printing in Expenses", + 'summary': """Print amount in words on checks issued for expenses""", + 'category': 'Accounting', + 'description': """ + Print amount in words on checks issued for expenses + """, + 'category': 'Accounting & Finance', + 'version': '1.0', + 'depends': ['account_check_printing', 'hr_expense'], + 'auto_install': True, + 'data': [ + 'views/payment.xml', + ], +} diff --git a/addons/hr_expense_check/models/__init__.py b/addons/hr_expense_check/models/__init__.py new file mode 100644 index 00000000000..d33d6b388d7 --- /dev/null +++ b/addons/hr_expense_check/models/__init__.py @@ -0,0 +1 @@ +import payment diff --git a/addons/hr_expense_check/models/payment.py b/addons/hr_expense_check/models/payment.py new file mode 100644 index 00000000000..e5041d05dc9 --- /dev/null +++ b/addons/hr_expense_check/models/payment.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api + + +class HrExpenseRegisterPaymentWizard(models.TransientModel): + _inherit = "hr.expense.register.payment.wizard" + + check_amount_in_words = fields.Char(string="Amount in Words") + check_manual_sequencing = fields.Boolean(related='journal_id.check_manual_sequencing') + # Note: a check_number == 0 means that it will be attributed when the check is printed + check_number = fields.Integer(string="Check Number", readonly=True, copy=False, default=0, + help="Number of the check corresponding to this payment. If your pre-printed check are not already numbered, " + "you can manage the numbering in the journal configuration page.") + payment_method_code_2 = fields.Char(related='payment_method_id.code', + help="Technical field used to adapt the interface to the payment type selected.", + readonly=True) + + @api.onchange('journal_id') + def _onchange_journal_id(self): + if hasattr(super(HrExpenseRegisterPaymentWizard, self), '_onchange_journal_id'): + super(HrExpenseRegisterPaymentWizard, self)._onchange_journal_id() + if self.journal_id.check_manual_sequencing: + self.check_number = self.journal_id.check_sequence_id.number_next_actual + + @api.onchange('amount') + def _onchange_amount(self): + if hasattr(super(HrExpenseRegisterPaymentWizard, self), '_onchange_amount'): + super(HrExpenseRegisterPaymentWizard, self)._onchange_amount() + self.check_amount_in_words = self.env['account.payment']._get_check_amount_in_words(self.amount) + + def get_payment_vals(self): + res = super(HrExpenseRegisterPaymentWizard, self).get_payment_vals() + if self.payment_method_id == self.env.ref('account_check_printing.account_payment_method_check'): + res.update({ + 'check_amount_in_words': self.check_amount_in_words, + 'check_manual_sequencing': self.check_manual_sequencing, + }) + return res diff --git a/addons/hr_expense_check/views/payment.xml b/addons/hr_expense_check/views/payment.xml new file mode 100644 index 00000000000..8f1ce4981a6 --- /dev/null +++ b/addons/hr_expense_check/views/payment.xml @@ -0,0 +1,18 @@ + + + + hr.expense.register.payment.wizard.form.check.inherited + hr.expense.register.payment.wizard + + + + + + + + + + + + +