From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/account_check_printing/wizard/__init__.py | 4 +++ .../wizard/print_prenumbered_checks.py | 30 ++++++++++++++++++++++ .../wizard/print_prenumbered_checks_views.xml | 22 ++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 addons/account_check_printing/wizard/__init__.py create mode 100644 addons/account_check_printing/wizard/print_prenumbered_checks.py create mode 100644 addons/account_check_printing/wizard/print_prenumbered_checks_views.xml (limited to 'addons/account_check_printing/wizard') diff --git a/addons/account_check_printing/wizard/__init__.py b/addons/account_check_printing/wizard/__init__.py new file mode 100644 index 00000000..2cdbcdb8 --- /dev/null +++ b/addons/account_check_printing/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import print_prenumbered_checks diff --git a/addons/account_check_printing/wizard/print_prenumbered_checks.py b/addons/account_check_printing/wizard/print_prenumbered_checks.py new file mode 100644 index 00000000..84d4f10a --- /dev/null +++ b/addons/account_check_printing/wizard/print_prenumbered_checks.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import re +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class PrintPreNumberedChecks(models.TransientModel): + _name = 'print.prenumbered.checks' + _description = 'Print Pre-numbered Checks' + + next_check_number = fields.Char('Next Check Number', required=True) + + @api.constrains('next_check_number') + def _check_next_check_number(self): + for check in self: + if check.next_check_number and not re.match(r'^[0-9]+$', check.next_check_number): + raise ValidationError(_('Next Check Number should only contains numbers.')) + + def print_checks(self): + check_number = int(self.next_check_number) + number_len = len(self.next_check_number or "") + payments = self.env['account.payment'].browse(self.env.context['payment_ids']) + payments.filtered(lambda r: r.state == 'draft').action_post() + payments.filtered(lambda r: r.state == 'posted' and not r.is_move_sent).write({'is_move_sent': True}) + for payment in payments: + payment.check_number = '%0{}d'.format(number_len) % check_number + check_number += 1 + return payments.do_print_checks() diff --git a/addons/account_check_printing/wizard/print_prenumbered_checks_views.xml b/addons/account_check_printing/wizard/print_prenumbered_checks_views.xml new file mode 100644 index 00000000..b593440c --- /dev/null +++ b/addons/account_check_printing/wizard/print_prenumbered_checks_views.xml @@ -0,0 +1,22 @@ + + + + + Print Pre-numbered Checks + print.prenumbered.checks + +
+

Please enter the number of the first pre-printed check that you are about to print on.

+

This will allow to save on payments the number of the corresponding check.

+ + + + +
+
+
+ +
-- cgit v1.2.3