diff options
| author | Laurent Smet <las@odoo.com> | 2019-10-29 12:21:27 +0000 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2020-04-10 09:47:24 +0000 |
| commit | caeb782841fc5a7ad71a196e2c9ee67644ef9074 (patch) | |
| tree | 28103bc29ab4f0d98162095f607c4c6ab1433f25 /addons/account_check_printing/models | |
| parent | b4d1360ed1d71c8fda44ca0c3b1a80d5a112b93f (diff) | |
[IMP] account,*: Improve bank statements/payments workflow
- Create journal entries as soon as bank/cash statement lines are created, temporary booked on a suspense account set on the journal.
- Simplify the management of "blue" lines in the reconciliation widget. A "blue" line is now a journal item using a temporary liquidity account (outstanding payment/receipt accounts, set on the journal).
- Adapt and simplify the bank reconciliation report.
- Remove the bank reconciliation threshold date. The reconciliation report will show the not already reconciled journal entries using a liquidity account and the not already reconciled journal entries using a temporary liquidity account. Without accounting, an account.payment will involve directly the liquidity account and then, will be considered as a statement line directly.
- Remove the post_at bank reconciliation feature. The "paid" state will be set on the invoices only if reconciled with a journal entry involving the journal's liquidity account.
With invoicing, the payment will do that so the "in_payment" state should never be shown up.
With accounting, only the statement lines have the power to move an invoice to the "paid" state.
- Fix various corner cases about the management of multi-currency in bank statement lines.
- Fix the conversion dates in multi-currency: Since the bank/cash is always used on the statement lines, it will use always the real "bank" date instead of the fictive payment one.
- Ensure the 'reconcile' method will raise an error if the involved moves are not posted.
related enterprise PR odoo/enterprise#7019
closes odoo/odoo#41301
--task: 2092096
Related: odoo/upgrade#1018
Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
Diffstat (limited to 'addons/account_check_printing/models')
| -rw-r--r-- | addons/account_check_printing/models/account_payment.py | 90 |
1 files changed, 36 insertions, 54 deletions
diff --git a/addons/account_check_printing/models/account_payment.py b/addons/account_check_printing/models/account_payment.py index eeb098c2f45..1034cf84ada 100644 --- a/addons/account_check_printing/models/account_payment.py +++ b/addons/account_check_printing/models/account_payment.py @@ -7,31 +7,38 @@ from odoo.tools.misc import formatLang, format_date INV_LINES_PER_STUB = 9 -class AccountPaymentRegister(models.TransientModel): - _inherit = "account.payment.register" - - def _prepare_payment_vals(self, invoices): - res = super(AccountPaymentRegister, self)._prepare_payment_vals(invoices) - if self.payment_method_id == self.env.ref('account_check_printing.account_payment_method_check'): - currency_id = self.env['res.currency'].browse(res['currency_id']) - res.update({ - 'check_amount_in_words': currency_id.amount_to_text(res['amount']), - }) - 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', readonly=1) - check_number = fields.Char(string="Check Number", readonly=True, copy=False, + check_amount_in_words = fields.Char(string="Amount in Words", store=True, readonly=False, + compute='_compute_check_amount_in_words') + check_manual_sequencing = fields.Boolean(related='journal_id.check_manual_sequencing') + check_number = fields.Char(string="Check Number", store=True, readonly=True, + compute='_compute_check_number', 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.") - check_number_int = fields.Integer(string="Check Number Integer", store=True, compute='_compute_check_number') + check_number_int = fields.Integer(string="Check Number Integer", store=True, + compute='_compute_check_number_int') + + @api.depends('payment_method_id', 'currency_id', 'amount') + def _compute_check_amount_in_words(self): + for pay in self: + if pay.currency_id and pay.payment_method_id == self.env.ref('account_check_printing.account_payment_method_check'): + pay.check_amount_in_words = pay.currency_id.amount_to_text(pay.amount) + else: + pay.check_amount_in_words = False + + @api.depends('journal_id') + def _compute_check_number(self): + for pay in self: + if pay.journal_id.check_manual_sequencing: + pay.check_number = pay.journal_id.check_sequence_id.number_next_actual + else: + pay.check_number = False @api.depends('check_number') - def _compute_check_number(self): + def _compute_check_number_int(self): # store check number as int to avoid doing a lot of checks and transformations # when calculating next_check_number for record in self: @@ -42,29 +49,8 @@ class AccountPayment(models.Model): number = 0 record.check_number_int = number - @api.onchange('amount', 'currency_id') - def _onchange_amount(self): - res = super(AccountPayment, self)._onchange_amount() - self.check_amount_in_words = self.currency_id.amount_to_text(self.amount) if self.currency_id else '' - return res - - @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 - - 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.")) - - def post(self): - res = super(AccountPayment, self).post() + def action_post(self): + res = super(AccountPayment, self).action_post() payment_method_check = self.env.ref('account_check_printing.account_payment_method_check') for payment in self.filtered(lambda p: p.payment_method_id == payment_method_check and p.check_manual_sequencing): sequence = payment.journal_id.check_sequence_id @@ -105,8 +91,8 @@ class AccountPayment(models.Model): self.filtered(lambda r: r.state == 'draft').post() return self.do_print_checks() - def unmark_sent(self): - self.write({'state': 'posted'}) + def action_unmark_sent(self): + self.write({'is_move_sent': False}) def do_print_checks(self): check_layout = self[0].company_id.account_check_printing_layout @@ -115,13 +101,9 @@ class AccountPayment(models.Model): report_action = self.env.ref(check_layout, False) if not report_action: raise UserError(_("Something went wrong with Check Layout, please select another layout in Invoicing/Accounting Settings and try again.")) - self.write({'state': 'sent'}) + self.write({'is_move_sent': True}) return report_action.report_action(self) - def set_check_amount_in_words(self): - for payment in self: - payment.check_amount_in_words = payment.currency_id.amount_to_text(payment.amount) if payment.currency_id else '' - ####################### #CHECK PRINTING METHODS ####################### @@ -132,15 +114,15 @@ class AccountPayment(models.Model): multi_stub = self.company_id.account_check_printing_multi_stub return { 'sequence_number': self.check_number if (self.journal_id.check_manual_sequencing and self.check_number != 0) else False, - 'payment_date': format_date(self.env, self.payment_date), + 'date': format_date(self.env, self.date), 'partner_id': self.partner_id, 'partner_name': self.partner_id.name, 'currency': self.currency_id, 'state': self.state, 'amount': formatLang(self.env, self.amount, currency_obj=self.currency_id) if i == 0 else 'VOID', 'amount_in_word': self._check_fill_line(self.check_amount_in_words) if i == 0 else 'VOID', - 'memo': self.communication, - 'stub_cropped': not multi_stub and len(self.invoice_ids) > INV_LINES_PER_STUB, + 'memo': self.ref, + 'stub_cropped': not multi_stub and len(self.move_id._get_reconciled_invoices()) > INV_LINES_PER_STUB, # If the payment does not reference an invoice, there is no stub line to display 'stub_lines': p, } @@ -158,12 +140,12 @@ class AccountPayment(models.Model): """ The stub is the summary of paid invoices. It may spill on several pages, in which case only the check on first page is valid. This function returns a list of stub lines per page. """ - if len(self.reconciled_invoice_ids) == 0: + if len(self.move_id._get_reconciled_invoices()) == 0: return None multi_stub = self.company_id.account_check_printing_multi_stub - invoices = self.reconciled_invoice_ids.sorted(key=lambda r: r.invoice_date_due) + invoices = self.move_id._get_reconciled_invoices().sorted(key=lambda r: r.invoice_date_due) debits = invoices.filtered(lambda r: r.move_type == 'in_invoice') credits = invoices.filtered(lambda r: r.move_type == 'in_refund') @@ -201,10 +183,10 @@ class AccountPayment(models.Model): # Find the account.partial.reconcile which are common to the invoice and the payment if invoice.move_type in ['in_invoice', 'out_refund']: invoice_sign = 1 - invoice_payment_reconcile = invoice.line_ids.mapped('matched_debit_ids').filtered(lambda r: r.debit_move_id in self.move_line_ids) + invoice_payment_reconcile = invoice.line_ids.mapped('matched_debit_ids').filtered(lambda r: r.debit_move_id in self.line_ids) else: invoice_sign = -1 - invoice_payment_reconcile = invoice.line_ids.mapped('matched_credit_ids').filtered(lambda r: r.credit_move_id in self.move_line_ids) + invoice_payment_reconcile = invoice.line_ids.mapped('matched_credit_ids').filtered(lambda r: r.credit_move_id in self.line_ids) if self.currency_id != self.journal_id.company_id.currency_id: amount_paid = abs(sum(invoice_payment_reconcile.mapped('amount_currency'))) |
