Server IP : 127.0.0.2 / Your IP : 3.133.83.123 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/account_check_printing/models/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. import math from odoo import models, fields, api, _ from odoo.tools import amount_to_text_en, float_round from odoo.exceptions import UserError, ValidationError class AccountRegisterPayments(models.TransientModel): _inherit = "account.register.payments" 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.") @api.onchange('journal_id') def _onchange_journal_id(self): if hasattr(super(AccountRegisterPayments, self), '_onchange_journal_id'): super(AccountRegisterPayments, 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(AccountRegisterPayments, self), '_onchange_amount'): super(AccountRegisterPayments, 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(AccountRegisterPayments, 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 class AccountPayment(models.Model): _inherit = "account.payment" check_amount_in_words = fields.Char(string="Amount in Words") check_manual_sequencing = fields.Boolean(related='journal_id.check_manual_sequencing') check_number = fields.Integer(string="Check Number", readonly=True, copy=False, 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'): super(AccountPayment, 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(AccountPayment, self), '_onchange_amount'): super(AccountPayment, self)._onchange_amount() 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) if payment_method_id == self.env.ref('account_check_printing.account_payment_method_check').id: if not communication: return if len(communication) > 60: raise ValidationError(_("A check memo cannot exceed 60 characters.")) @api.model def create(self, vals): if vals['payment_method_id'] == self.env.ref('account_check_printing.account_payment_method_check').id\ and vals.get('check_manual_sequencing'): sequence = self.env['account.journal'].browse(vals['journal_id']).check_sequence_id vals.update({'check_number': sequence.next_by_id()}) return super(AccountPayment, self).create(vals) @api.multi def print_checks(self): """ Check that the recordset is valid, set the payments state to sent and call print_checks() """ # Since this method can be called via a client_action_multi, we need to make sure the received records are what we expect self = self.filtered(lambda r: r.payment_method_id.code == 'check_printing' and r.state != 'reconciled') if len(self) == 0: raise UserError(_("Payments to print as a checks must have 'Check' selected as payment method and " "not have already been reconciled")) if any(payment.journal_id != self[0].journal_id for payment in self): raise UserError(_("In order to print multiple checks at once, they must belong to the same bank journal.")) if not self[0].journal_id.check_manual_sequencing: # The wizard asks for the number printed on the first pre-printed check # so payments are attributed the number of the check the'll be printed on. last_printed_check = self.search([ ('journal_id', '=', self[0].journal_id.id), ('check_number', '!=', 0)], order="check_number desc", limit=1) next_check_number = last_printed_check and last_printed_check.check_number + 1 or 1 return { 'name': _('Print Pre-numbered Checks'), 'type': 'ir.actions.act_window', 'res_model': 'print.prenumbered.checks', 'view_type': 'form', 'view_mode': 'form', 'target': 'new', 'context': { 'payment_ids': self.ids, 'default_next_check_number': next_check_number, } } else: self.filtered(lambda r: r.state == 'draft').post() return self.do_print_checks() @api.multi def unmark_sent(self): self.write({'state': 'posted'}) @api.multi def do_print_checks(self): """ This method is a hook for l10n_xx_check_printing modules to implement actual check printing capabilities """ raise UserError(_("There is no check layout configured.\nMake sure the proper check printing module is installed" " and its configuration (in company settings > 'Configuration' tab) is correct."))