From 82dc0cb7b91ae59beae7e1c865b670afc5958b31 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 30 Mar 2020 11:46:27 +0000 Subject: [PATCH] [IMP] account: soft post entries in the future Add an easy way to not post the entries in the future when calling post() on it, but rather set it to be auto-posted at accounting date. This is useful when we are creating a lot of entries in batch and some might be in the future, some in the past, and we don't want to separate that in two batch every time. (asset, accrual, transfer,... ) --- .../account/models/account_bank_statement.py | 2 +- addons/account/models/account_move.py | 67 +++++++++++++------ .../models/account_partial_reconcile.py | 2 +- addons/account/models/account_payment.py | 2 +- addons/account/tests/common.py | 2 +- addons/account/tests/test_account_account.py | 4 +- .../tests/test_account_bank_statement.py | 8 +-- .../tests/test_account_journal_dashboard.py | 4 +- .../account/tests/test_account_move_entry.py | 42 ++++++------ .../tests/test_account_move_in_invoice.py | 6 +- .../tests/test_account_move_out_invoice.py | 10 +-- .../tests/test_account_move_partner_count.py | 2 +- .../test_account_move_payments_widget.py | 18 ++--- .../tests/test_account_move_reconcile.py | 20 +++--- addons/account/tests/test_account_payment.py | 2 +- .../tests/test_account_payment_register.py | 6 +- addons/account/tests/test_invoice_taxes.py | 10 +-- addons/account/tests/test_reconciliation.py | 28 ++++---- .../test_reconciliation_matching_rules.py | 6 +- addons/account/tests/test_tax_report.py | 2 +- addons/account/tests/test_transfer_wizard.py | 4 +- addons/account/views/account_move_views.xml | 10 ++- .../wizard/account_validate_account_move.py | 6 +- .../wizard/account_validate_move_view.xml | 3 + .../account/wizard/wizard_tax_adjustments.py | 2 +- .../models/account_payment.py | 2 +- .../tests/test_print_check.py | 4 +- .../tests/test_out_debit_note.py | 4 +- addons/account_edi/models/account_move.py | 8 +-- .../account_edi_facturx/tests/test_facturx.py | 4 +- .../tests/test_delivery_stock_move.py | 4 +- addons/hr_expense/models/hr_expense.py | 4 +- addons/l10n_ar/models/account_move.py | 8 +-- .../l10n_ch/tests/test_l10n_ch_isr_print.py | 4 +- addons/l10n_ch/tests/test_swissqr.py | 6 +- addons/l10n_cl/models/account_move.py | 6 +- addons/l10n_de/models/datev.py | 4 +- addons/l10n_fi/tests/test_get_reference.py | 8 +-- .../demo/account_invoice_demo.xml | 2 +- addons/l10n_id_efaktur/models/account_move.py | 4 +- addons/l10n_in/models/account_invoice.py | 8 +-- addons/l10n_it_edi/models/account_invoice.py | 7 +- .../models/account_move.py | 5 +- addons/membership/tests/test_membership.py | 2 +- addons/payment/models/payment_acquirer.py | 4 +- addons/point_of_sale/models/pos_order.py | 2 +- addons/point_of_sale/models/pos_session.py | 2 +- .../tests/test_point_of_sale_flow.py | 4 +- .../models/account_move.py | 8 +-- .../tests/test_product_margin.py | 2 +- addons/purchase/tests/test_access_rights.py | 2 +- .../tests/test_purchase_order_report.py | 2 +- .../purchase_stock/models/account_invoice.py | 6 +- ...st_anglo_saxon_valuation_reconciliation.py | 10 +-- .../tests/test_purchase_order.py | 4 +- .../tests/test_stockvaluation.py | 24 +++---- addons/sale/models/account_invoice.py | 8 +-- addons/sale/tests/test_reinvoice.py | 10 +-- addons/sale/tests/test_sale_order.py | 2 +- addons/sale/tests/test_sale_refund.py | 10 +-- addons/sale/tests/test_sale_to_invoice.py | 4 +- addons/sale_mrp/tests/test_sale_mrp_flow.py | 2 +- .../tests/test_anglo_saxon_valuation.py | 46 ++++++------- ...st_anglo_saxon_valuation_reconciliation.py | 8 +-- addons/sale_stock/tests/test_sale_stock.py | 4 +- .../tests/test_project_overview.py | 2 +- addons/sale_timesheet/tests/test_reinvoice.py | 10 +-- addons/sale_timesheet/tests/test_reporting.py | 4 +- .../sale_timesheet/tests/test_sale_service.py | 2 +- .../tests/test_sale_timesheet.py | 8 +-- .../tests/test_pingen_send.py | 2 +- addons/stock_account/models/account_move.py | 10 +-- addons/stock_account/models/product.py | 8 +-- addons/stock_account/models/stock_move.py | 2 +- ...o_saxon_valuation_reconciliation_common.py | 2 +- .../stock_valuation_layer_revaluation.py | 2 +- .../tests/test_stockvaluation.py | 4 +- .../models/stock_landed_cost.py | 2 +- .../tests/test_stock_landed_costs_purchase.py | 2 +- .../tests/test_stockvaluationlayer.py | 17 +++-- 80 files changed, 319 insertions(+), 284 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 692a572904d..1e9b91eb314 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -391,7 +391,7 @@ class AccountBankStatement(models.Model): statement._set_next_sequence() self.write({'state': 'posted'}) - self.line_ids.move_id.post() + self.line_ids.move_id._post(soft=False) def button_validate(self): if any(statement.state != 'posted' or not statement.all_lines_reconciled for statement in self): diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 4c5e0046e26..621cbb22b23 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2,11 +2,10 @@ from odoo import api, fields, models, _ from odoo.exceptions import RedirectWarning, UserError, ValidationError, AccessError -from odoo.tools import float_is_zero, float_repr, float_compare, date_utils, email_split, email_escape_char, email_re +from odoo.tools import float_compare, date_utils, email_split, email_re from odoo.tools.misc import formatLang, format_date, get_lang from datetime import date, timedelta -from itertools import groupby from itertools import zip_longest from hashlib import sha256 from json import dumps @@ -14,6 +13,7 @@ from json import dumps import ast import json import re +import warnings #forbidden fields INTEGRITY_HASH_MOVE_FIELDS = ('date', 'journal_id', 'company_id') @@ -228,7 +228,7 @@ class AccountMove(models.Model): help="The journal entry from which this tax cash basis journal entry has been created.") # ==== Auto-post feature fields ==== - auto_post = fields.Boolean(string='Post Automatically', default=False, + auto_post = fields.Boolean(string='Post Automatically', default=False, copy=False, help='If this checkbox is ticked, this entry will be automatically posted at its date.') # ==== Reverse feature fields ==== @@ -2226,7 +2226,7 @@ class AccountMove(models.Model): # Reconcile moves together to cancel the previous one. if cancel: - reverse_moves.with_context(move_reverse_cancel=cancel).post() + reverse_moves.with_context(move_reverse_cancel=cancel)._post(soft=False) for move, reverse_move in zip(self, reverse_moves): accounts = move.mapped('line_ids.account_id') \ .filtered(lambda account: account.reconcile or account.internal_type == 'liquidity') @@ -2288,10 +2288,40 @@ class AccountMove(models.Model): return move def post(self): + warnings.warn( + "RedirectWarning method 'post()' is a deprecated alias to 'action_post()' or _post()", + DeprecationWarning + ) + return self.action_post() + + def _post(self, soft=True): + """Post/Validate the documents. + + Posting the documents will give it a number, and check that the document is + complete (some fields might not be required if not posted but are required + otherwise). + If the journal is locked with a hash table, it will be impossible to change + some fields afterwards. + + :param soft (bool): if True, future documents are not immediately posted, + but are set to be auto posted automatically at the set accounting date. + Nothing will be performed on those documents before the accounting date. + :return Model: the documents that have been posted + """ + if soft: + future_moves = self.filtered(lambda move: move.date > fields.Date.today()) + future_moves.auto_post = True + for move in future_moves: + msg = _('This move will be posted at the accounting date: %(date)s', date=format_date(self.env, move.date)) + move.message_post(body=msg) + to_post = self - future_moves + else: + to_post = self + # `user_has_group` won't be bypassed by `sudo()` since it doesn't change the user anymore. if not self.env.su and not self.env.user.has_group('account.group_account_invoice'): raise AccessError(_("You don't have the access rights to post an invoice.")) - for move in self: + for move in to_post: if not move.line_ids.filtered(lambda line: not line.display_type): raise UserError(_('You need to add a line before posting.')) if move.auto_post and move.date > fields.Date.today(): @@ -2323,16 +2353,13 @@ class AccountMove(models.Model): move.with_context(check_move_validity=False)._onchange_currency() # Create the analytic lines in batch is faster as it leads to less cache invalidation. - self.mapped('line_ids').create_analytic_lines() - self.write({ + to_post.mapped('line_ids').create_analytic_lines() + to_post.write({ 'state': 'posted', 'posted_before': True, }) - for move in self: - if move.auto_post and move.date > fields.Date.today(): - raise UserError(_("This move is configured to be auto-posted on %s", move.date.strftime(get_lang(self.env).date_format))) - + for move in to_post: move.message_subscribe([p.id for p in [move.partner_id] if p not in move.sudo().message_partner_ids]) # Compute 'ref' for 'out_invoice'. @@ -2345,7 +2372,7 @@ class AccountMove(models.Model): to_write['line_ids'].append((1, line.id, {'name': to_write['payment_reference']})) move.write(to_write) - for move in self: + for move in to_post: if move.is_sale_document() \ and move.journal_id.sale_activity_type_id \ and (move.journal_id.sale_activity_user_id or move.invoice_user_id).id not in (self.env.ref('base.user_root').id, False): @@ -2356,21 +2383,21 @@ class AccountMove(models.Model): user_id=move.journal_id.sale_activity_user_id.id or move.invoice_user_id.id, ) - for move in self: + for move in to_post: if move.is_sale_document(): move.partner_id._increase_rank('customer_rank') elif move.is_purchase_document(): move.partner_id._increase_rank('supplier_rank') # Trigger action for paid invoices in amount is zero - self.filtered( + to_post.filtered( lambda m: m.is_invoice(include_receipts=True) and m.currency_id.is_zero(m.amount_total) ).action_invoice_paid() # Force balance check since nothing prevents another module to create an incorrect entry. # This is performed at the very end to avoid flushing fields before the whole processing. - self._check_balanced() - return True + to_post._check_balanced() + return to_post def _auto_compute_invoice_reference(self): ''' Hook to be overridden to set custom conditions for auto-computed invoice references. @@ -2389,7 +2416,7 @@ class AccountMove(models.Model): return action def action_post(self): - return self.post() + return self._post(soft=False) def js_assign_outstanding_line(self, line_id): ''' Called by the 'payment' widget to reconcile a suggested journal item to the present @@ -2629,7 +2656,7 @@ class AccountMove(models.Model): ('date', '<=', fields.Date.today()), ('auto_post', '=', True), ]) - records.post() + records._post() # offer the possibility to duplicate thanks to a button instead of a hidden menu, which is more visible def action_duplicate(self): @@ -4374,7 +4401,7 @@ class AccountMoveLine(models.Model): involved_partials += exchange_diff_partials results['partials'] += exchange_diff_partials - exchange_move.post() + exchange_move._post(soft=False) # ==== Create the full reconcile ==== @@ -4477,7 +4504,7 @@ class AccountMoveLine(models.Model): #post all the writeoff moves at once if writeoff_moves: - writeoff_moves.post() + writeoff_moves._post() # Return the writeoff move.line which is to be reconciled return line_to_reconcile diff --git a/addons/account/models/account_partial_reconcile.py b/addons/account/models/account_partial_reconcile.py index 2deec394a77..ef9d8f4891e 100644 --- a/addons/account/models/account_partial_reconcile.py +++ b/addons/account/models/account_partial_reconcile.py @@ -597,7 +597,7 @@ class AccountPartialReconcile(models.Model): moves_to_create.append(move_vals) moves = self.env['account.move'].create(moves_to_create) - moves.post() + moves._post(soft=False) # Reconcile the tax lines being on a reconcile tax basis transfer account. for line, move_index, sequence in to_reconcile_after: diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index c3ece2d28f6..6780cebb709 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -717,7 +717,7 @@ class AccountPayment(models.Model): def action_post(self): ''' draft -> posted ''' - self.move_id.post() + self.move_id._post(soft=False) def action_cancel(self): ''' draft -> cancelled ''' diff --git a/addons/account/tests/common.py b/addons/account/tests/common.py index 5561005589d..701a56d0d63 100644 --- a/addons/account/tests/common.py +++ b/addons/account/tests/common.py @@ -532,7 +532,7 @@ class TestAccountReconciliationCommon(AccountTestInvoicingCommon): invoice = self.env['account.move'].with_context(default_move_type=type).create(invoice_vals) if auto_validate: - invoice.post() + invoice.action_post() return invoice def create_invoice(self, type='out_invoice', invoice_amount=50, currency_id=None): diff --git a/addons/account/tests/test_account_account.py b/addons/account/tests/test_account_account.py index 3247feff6f0..8b7b22bc74f 100644 --- a/addons/account/tests/test_account_account.py +++ b/addons/account/tests/test_account_account.py @@ -52,7 +52,7 @@ class TestAccountAccount(AccountTestInvoicingCommon): }), ], }) - move.post() + move.action_post() self.assertRecordValues(move.line_ids, [ {'reconciled': False, 'amount_residual': 0.0, 'amount_residual_currency': 0.0}, @@ -115,7 +115,7 @@ class TestAccountAccount(AccountTestInvoicingCommon): }), ], }) - move.post() + move.action_post() # Set the account as reconcile and partially reconcile something. account.reconcile = True diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index 878158bb490..60e96694c0a 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -761,7 +761,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): # You can't set the journal entry in an unconsistent state. with self.assertRaises(UserError), self.cr.savepoint(): - st_line.move_id.post() + st_line.move_id.action_post() def test_statement_line_move_onchange_1(self): ''' Test the consistency between the account.bank.statement.line and the generated account.move.lines @@ -935,7 +935,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): ], }, ]) - test_invoices.post() + test_invoices.action_post() statement.button_post() counterpart_lines = test_invoices.mapped('line_ids').filtered(lambda line: line.account_internal_type in ('receivable', 'payable')) @@ -1198,7 +1198,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): }), ] }) - test_move.post() + test_move.action_post() test_line_1 = test_move.line_ids.filtered(lambda line: line.account_id == receivable_acc_1) test_line_2 = test_move.line_ids.filtered(lambda line: line.account_id == receivable_acc_2) @@ -1403,7 +1403,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): }), ] }) - test_move.post() + test_move.action_post() test_line_1 = test_move.line_ids.filtered(lambda line: line.name == 'test line 1') test_line_2 = test_move.line_ids.filtered(lambda line: line.name == 'test line 2') diff --git a/addons/account/tests/test_account_journal_dashboard.py b/addons/account/tests/test_account_journal_dashboard.py index 316b8a0ee84..6bb127b672c 100644 --- a/addons/account/tests/test_account_journal_dashboard.py +++ b/addons/account/tests/test_account_journal_dashboard.py @@ -49,7 +49,7 @@ class TestAccountJournalDashboard(AccountTestInvoicingCommon): self.assertIn('0.00', dashboard_data['sum_waiting']) # Check Both - invoice.post() + invoice.action_post() dashboard_data = journal.get_journal_dashboard_datas() self.assertEqual(dashboard_data['number_draft'], 1) @@ -59,7 +59,7 @@ class TestAccountJournalDashboard(AccountTestInvoicingCommon): self.assertIn('81.72', dashboard_data['sum_waiting']) # Check waiting payment - refund.post() + refund.action_post() dashboard_data = journal.get_journal_dashboard_datas() self.assertEqual(dashboard_data['number_draft'], 0) diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index 61bbd3dee9e..b0e6eb642a5 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -69,7 +69,7 @@ class TestAccountMove(AccountTestInvoicingCommon): self.test_move.line_ids[0].account_id = custom_account def test_misc_fiscalyear_lock_date_1(self): - self.test_move.post() + self.test_move.action_post() # Set the lock date after the journal entry date. self.test_move.company_id.fiscalyear_lock_date = fields.Date.from_string('2017-01-01') @@ -143,7 +143,7 @@ class TestAccountMove(AccountTestInvoicingCommon): self.assertEqual(copy_move.date, copy_move.company_id.fiscalyear_lock_date + relativedelta(days=1)) def test_misc_fiscalyear_lock_date_2(self): - self.test_move.post() + self.test_move.action_post() # Create a bank statement to get a balance in the suspense account. statement = self.env['account.bank.statement'].create({ @@ -160,7 +160,7 @@ class TestAccountMove(AccountTestInvoicingCommon): self.test_move.company_id.fiscalyear_lock_date = fields.Date.from_string('2017-01-01') def test_misc_tax_lock_date_1(self): - self.test_move.post() + self.test_move.action_post() # Set the tax lock date after the journal entry date. self.test_move.company_id.tax_lock_date = fields.Date.from_string('2017-01-01') @@ -249,7 +249,7 @@ class TestAccountMove(AccountTestInvoicingCommon): copy_move = self.test_move.copy() # /!\ The date is changed automatically to the next available one during the post. - copy_move.post() + copy_move.action_post() # You can't change the date to one being in a locked period. with self.assertRaises(UserError), self.cr.savepoint(): @@ -297,7 +297,7 @@ class TestAccountMove(AccountTestInvoicingCommon): # lines[1] = 'move 1 counterpart line' # lines[2] = 'move 1 receivable line' # lines[3] = 'move 2 counterpart line' - draft_moves.post() + draft_moves.action_post() lines = draft_moves.mapped('line_ids').sorted('balance') (lines[0] + lines[2]).reconcile() @@ -352,23 +352,23 @@ class TestAccountMove(AccountTestInvoicingCommon): # We don't recompute user's input when posting self.test_move.name = 'MyMISC/2020/0000001' - self.test_move.post() + self.test_move.action_post() self.assertEqual(self.test_move.name, 'MyMISC/2020/0000001') # Has been posted, and it doesn't change anymore self.test_move.button_draft() self.test_move.date = '2020-01-02' - self.test_move.post() + self.test_move.action_post() self.assertEqual(self.test_move.name, 'MyMISC/2020/0000001') def test_journal_sequence(self): self.assertEqual(self.test_move.name, 'MISC/2016/01/0001') - self.test_move.post() + self.test_move.action_post() self.assertEqual(self.test_move.name, 'MISC/2016/01/0001') copy1 = self.test_move.copy() self.assertEqual(copy1.name, '/') - copy1.post() + copy1.action_post() self.assertEqual(copy1.name, 'MISC/2016/01/0002') copy2 = self.test_move.copy() @@ -378,7 +378,7 @@ class TestAccountMove(AccountTestInvoicingCommon): self.assertEqual(copy2.name, 'MISC2/2016/01/0001') with Form(copy2) as move_form: # It is editable in the form move_form.name = 'MyMISC/2099/0001' - copy2.post() + copy2.action_post() self.assertEqual(copy2.name, 'MyMISC/2099/0001') copy3 = copy2.copy() @@ -386,22 +386,22 @@ class TestAccountMove(AccountTestInvoicingCommon): with self.assertRaises(AssertionError): with Form(copy2) as move_form: # It is not editable in the form move_form.name = 'MyMISC/2099/0002' - copy3.post() + copy3.action_post() self.assertEqual(copy3.name, 'MyMISC/2099/0002') copy3.name = 'MISC2/2016/00002' copy4 = copy2.copy() - copy4.post() + copy4.action_post() self.assertEqual(copy4.name, 'MISC2/2016/00003') copy5 = copy2.copy() copy5.date = '2021-02-02' - copy5.post() + copy5.action_post() self.assertEqual(copy5.name, 'MISC2/2021/00001') copy5.name = 'N\'importe quoi?' copy6 = copy5.copy() - copy6.post() + copy6.action_post() self.assertEqual(copy6.name, 'N\'importe quoi?1') def test_journal_sequence_format(self): @@ -428,7 +428,7 @@ class TestAccountMove(AccountTestInvoicingCommon): next_move_month.date = '2016-04-12' next_move_year.date = '2017-03-12' next_moves = (next_move + next_move_month + next_move_year) - next_moves.post() + next_moves.action_post() for sequence_init, sequence_next, sequence_next_month, sequence_next_year in sequences: init_move.name = sequence_init @@ -444,7 +444,7 @@ class TestAccountMove(AccountTestInvoicingCommon): for c in range(2, 25): copy = self.test_move.copy() copy.name = "/" - copy.post() + copy.action_post() self.assertEqual(copy.name, f"{prefix}{c}") def test_journal_sequence_multiple_type(self): @@ -458,7 +458,7 @@ class TestAccountMove(AccountTestInvoicingCommon): (refund + refund2).move_type = 'out_refund' all = (entry + entry2 + invoice + invoice2 + refund + refund2) all.name = False - all.post() + all.action_post() self.assertEqual(entry.name, 'MISC/2016/01/0002') self.assertEqual(entry2.name, 'MISC/2016/01/0003') self.assertEqual(invoice.name, 'INV/2016/01/0001') @@ -471,7 +471,7 @@ class TestAccountMove(AccountTestInvoicingCommon): other_moves.unlink() # Do not interfere when trying to get the highest name for new periods self.test_move.name = '00000876-G 0002/2020' next = self.test_move.copy() - next.post() + next.action_post() self.assertEqual(next.name, '00000876-G 0002/2021') # Wait, I didn't want this! next.journal_id.sequence_override_regex = r'^(?P\d*)(?P.*?)(?P(\d{4})?)(?P)$' @@ -481,7 +481,7 @@ class TestAccountMove(AccountTestInvoicingCommon): next = next = self.test_move.copy() next.date = "2017-05-02" - next.post() + next.action_post() self.assertEqual(next.name, '00000001-G 0002/2017') def test_journal_sequence_ordering(self): @@ -497,7 +497,7 @@ class TestAccountMove(AccountTestInvoicingCommon): # that entry is actualy the first one of the period, so it already has a name # set it to '/' so that it is recomputed at post to be ordered correctly. copies[0].name = '/' - copies.post() + copies.action_post() # Ordered by date self.assertEqual(copies[0].name, 'XMISC/2019/00002') @@ -565,7 +565,7 @@ class TestAccountMove(AccountTestInvoicingCommon): partner = self.env['res.partner'].create({'name': 'Belouga'}) move.partner_id = partner - move.post() + move.action_post() self.assertEqual(move.message_partner_ids, self.env.user.partner_id | existing_partners | partner) def test_misc_move_onchange(self): diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 511e34983de..69c85523809 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -1112,7 +1112,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): ], self.move_vals) def test_in_invoice_create_refund(self): - self.invoice.post() + self.invoice.action_post() move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=self.invoice.ids).create({ 'date': fields.Date.from_string('2019-02-01'), @@ -1215,7 +1215,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): move_form.currency_id = self.currency_data['currency'] move_form.save() - self.invoice.post() + self.invoice.action_post() # The currency rate changed from 1/3 to 1/2. move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=self.invoice.ids).create({ @@ -1651,7 +1651,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): }), ] }) - move.post() + move.action_post() wizard = self.env['account.accrual.accounting.wizard']\ .with_context(active_model='account.move.line', active_ids=move.invoice_line_ids.ids).create({ diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 53a29cfda99..b18edefe04e 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -1578,7 +1578,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): }) def test_out_invoice_create_refund(self): - self.invoice.post() + self.invoice.action_post() move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=self.invoice.ids).create({ 'date': fields.Date.from_string('2019-02-01'), @@ -1682,7 +1682,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): move_form.currency_id = self.currency_data['currency'] move_form.save() - self.invoice.post() + self.invoice.action_post() # The currency rate changed from 1/3 to 1/2. move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=self.invoice.ids).create({ @@ -1963,7 +1963,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): ], }) - move.post() + move.action_post() self.assertInvoiceValues(move, [ { @@ -2064,7 +2064,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): # - As the date changed, the currency rate has changed (1/3 => 1/2). move.company_id.tax_lock_date = fields.Date.from_string('2016-12-31') - move.post() + move.action_post() self.assertInvoiceValues(move, [ { @@ -2328,7 +2328,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): }), ] }) - move.post() + move.action_post() wizard = self.env['account.accrual.accounting.wizard']\ .with_context(active_model='account.move.line', active_ids=move.invoice_line_ids.ids).create({ diff --git a/addons/account/tests/test_account_move_partner_count.py b/addons/account/tests/test_account_move_partner_count.py index 5da8e35a8ec..88eab61d167 100644 --- a/addons/account/tests/test_account_move_partner_count.py +++ b/addons/account/tests/test_account_move_partner_count.py @@ -23,7 +23,7 @@ class TestAccountMovePartnerCount(AccountTestInvoicingCommon): 'partner_id': self.partner_a.id, 'invoice_line_ids': [(0, 0, {'name': 'aaaa', 'price_unit': 100.0})], }, - ]).post() + ]).action_post() self.assertEqual(self.partner_a.supplier_rank, 1) self.assertEqual(self.partner_a.customer_rank, 1) diff --git a/addons/account/tests/test_account_move_payments_widget.py b/addons/account/tests/test_account_move_payments_widget.py index 9f3ba3f4674..f4c0d9fffa3 100644 --- a/addons/account/tests/test_account_move_payments_widget.py +++ b/addons/account/tests/test_account_move_payments_widget.py @@ -33,7 +33,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), ], }) - cls.payment_2016_curr_1.post() + cls.payment_2016_curr_1.action_post() cls.payment_2016_curr_2 = cls.env['account.move'].create({ 'date': '2016-01-01', @@ -42,7 +42,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 1550.0, 'currency_id': cls.curr_2.id, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), ], }) - cls.payment_2016_curr_2.post() + cls.payment_2016_curr_2.action_post() cls.payment_2017_curr_2 = cls.env['account.move'].create({ 'date': '2017-01-01', @@ -51,7 +51,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 950.0, 'currency_id': cls.curr_2.id, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), ], }) - cls.payment_2017_curr_2.post() + cls.payment_2017_curr_2.action_post() cls.payment_2016_curr_3 = cls.env['account.move'].create({ 'date': '2016-01-01', @@ -60,7 +60,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 3050.0, 'currency_id': cls.curr_3.id, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), ], }) - cls.payment_2016_curr_3.post() + cls.payment_2016_curr_3.action_post() cls.payment_2017_curr_3 = cls.env['account.move'].create({ 'date': '2017-01-01', @@ -69,7 +69,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 1950.0, 'currency_id': cls.curr_3.id, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), ], }) - cls.payment_2017_curr_3.post() + cls.payment_2017_curr_3.action_post() # ------------------------------------------------------------------------- # HELPERS @@ -123,7 +123,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): 'currency_id': self.curr_1.id, 'invoice_line_ids': [(0, 0, {'name': '/', 'price_unit': 2500.0})], }) - out_invoice.post() + out_invoice.action_post() # Vendor bill of 2500.0 in curr_1. in_invoice = self.env['account.move'].create({ @@ -134,7 +134,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): 'currency_id': self.curr_1.id, 'invoice_line_ids': [(0, 0, {'name': '/', 'price_unit': 2500.0})], }) - in_invoice.post() + in_invoice.action_post() expected_amounts = { self.payment_2016_curr_1.id: 500.0, @@ -159,7 +159,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): 'currency_id': self.curr_2.id, 'invoice_line_ids': [(0, 0, {'name': '/', 'price_unit': 7500.0})], }) - out_invoice.post() + out_invoice.action_post() # Vendor bill of 2500.0 in curr_1. in_invoice = self.env['account.move'].create({ @@ -170,7 +170,7 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): 'currency_id': self.curr_2.id, 'invoice_line_ids': [(0, 0, {'name': '/', 'price_unit': 7500.0})], }) - in_invoice.post() + in_invoice.action_post() expected_amounts = { self.payment_2016_curr_1.id: 1500.0, diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index 76b5b51cb17..cf4edd1f371 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -240,7 +240,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): (0, 0, {'debit': 0.0, 'credit': 500.0, 'account_id': account_id}), ] }) - move.post() + move.action_post() line_1 = move.line_ids.filtered(lambda line: line.debit == 1000.0) line_2 = move.line_ids.filtered(lambda line: line.debit == 200.0) @@ -344,7 +344,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): } ]) - moves.post() + moves.action_post() line_1 = moves.line_ids.filtered(lambda line: line.debit == 1200.0) line_2 = moves.line_ids.filtered(lambda line: line.debit == 120.0) @@ -478,7 +478,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): } ]) - moves.post() + moves.action_post() line_1 = moves.line_ids.filtered(lambda line: line.debit == 1200.0) line_2 = moves.line_ids.filtered(lambda line: line.debit == 780.0) @@ -751,7 +751,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (cash_basis_move + payment_move).post() + (cash_basis_move + payment_move).action_post() # Initial amounts by accounts: @@ -968,7 +968,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (cash_basis_move + payment_move).post() + (cash_basis_move + payment_move).action_post() # Initial amounts by accounts: @@ -1186,7 +1186,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (cash_basis_move + payment_move + end_move).post() + (cash_basis_move + payment_move + end_move).action_post() self.assertAmountsGroupByAccount([ # Account Balance Amount Currency @@ -1301,7 +1301,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (cash_basis_move + payment_move).post() + (cash_basis_move + payment_move).action_post() self.assertAmountsGroupByAccount([ # Account Balance Amount Currency @@ -1399,7 +1399,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (invoice_move + payment_move).post() + (invoice_move + payment_move).action_post() receivable_lines = (invoice_move + payment_move).line_ids\ .filtered(lambda line: line.account_id == self.extra_receivable_account_1) @@ -1507,7 +1507,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (invoice_move + refund_move).post() + (invoice_move + refund_move).action_post() receivable_lines = (invoice_move + refund_move).line_ids\ .filtered(lambda line: line.account_id == self.extra_receivable_account_1) @@ -1605,7 +1605,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): ] }) - (invoice_move + payment_move).post() + (invoice_move + payment_move).action_post() receivable_lines = (invoice_move + payment_move).line_ids\ .filtered(lambda line: line.account_id == self.extra_receivable_account_1) diff --git a/addons/account/tests/test_account_payment.py b/addons/account/tests/test_account_payment.py index e991d57c4c1..147643e975d 100644 --- a/addons/account/tests/test_account_payment.py +++ b/addons/account/tests/test_account_payment.py @@ -476,7 +476,7 @@ class TestAccountPayment(AccountTestInvoicingCommon): }) payment.action_post() - invoice.post() + invoice.action_post() (counterpart_lines + invoice.line_ids.filtered(lambda line: line.account_internal_type == 'receivable'))\ .reconcile() diff --git a/addons/account/tests/test_account_payment_register.py b/addons/account/tests/test_account_payment_register.py index ba6e6c6c63c..db51a0efde6 100644 --- a/addons/account/tests/test_account_payment_register.py +++ b/addons/account/tests/test_account_payment_register.py @@ -51,7 +51,7 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): 'currency_id': cls.currency_data['currency'].id, 'invoice_line_ids': [(0, 0, {'product_id': cls.product_a.id, 'price_unit': 1000.0})], }) - cls.out_invoice_1.post() + cls.out_invoice_1.action_post() cls.out_invoice_2 = cls.env['account.move'].create({ 'move_type': 'out_invoice', 'date': '2017-01-01', @@ -60,7 +60,7 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): 'currency_id': cls.currency_data['currency'].id, 'invoice_line_ids': [(0, 0, {'product_id': cls.product_a.id, 'price_unit': 2000.0})], }) - (cls.out_invoice_1 + cls.out_invoice_2).post() + (cls.out_invoice_1 + cls.out_invoice_2).action_post() # Vendor bills, in_invoice_1 + in_invoice_2 are sharing the same batch but not in_invoice_3. cls.in_invoice_1 = cls.env['account.move'].create({ @@ -85,7 +85,7 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): 'currency_id': cls.currency_data['currency'].id, 'invoice_line_ids': [(0, 0, {'product_id': cls.product_a.id, 'price_unit': 3000.0})], }) - (cls.in_invoice_1 + cls.in_invoice_2 + cls.in_invoice_3).post() + (cls.in_invoice_1 + cls.in_invoice_2 + cls.in_invoice_3).action_post() def test_register_payment_single_batch_grouped_keep_open_lower_amount(self): ''' Pay 800.0 with 'open' as payment difference handling on two customer invoices (1000 + 2000). ''' diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py index b61db994e7c..5bd600f1f1e 100644 --- a/addons/account/tests/test_invoice_taxes.py +++ b/addons/account/tests/test_invoice_taxes.py @@ -101,7 +101,7 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): (121, self.percent_tax_1_incl), (100, self.percent_tax_2), ]) - invoice.post() + invoice.action_post() self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [ {'name': self.percent_tax_1.name, 'tax_base_amount': 100, 'price_unit': 21, 'tax_ids': []}, {'name': self.percent_tax_1_incl.name, 'tax_base_amount': 100, 'price_unit': 21, 'tax_ids': []}, @@ -126,7 +126,7 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): (121, self.percent_tax_1_incl + self.percent_tax_2), (100, self.percent_tax_2), ]) - invoice.post() + invoice.action_post() self.assertRecordValues(invoice.line_ids.filtered('tax_line_id').sorted(lambda x: x.price_unit), [ {'name': self.percent_tax_1_incl.name, 'tax_base_amount': 100, 'price_unit': 21, 'tax_ids': [self.percent_tax_2.id]}, {'name': self.percent_tax_2.name, 'tax_base_amount': 221, 'price_unit': 26.52, 'tax_ids': []}, @@ -150,7 +150,7 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): (121, self.group_tax), (100, self.percent_tax_2), ]) - invoice.post() + invoice.action_post() self.assertRecordValues(invoice.line_ids.filtered('tax_line_id').sorted(lambda x: x.price_unit), [ {'name': self.percent_tax_1_incl.name, 'tax_base_amount': 100, 'price_unit': 21, 'tax_ids': [self.percent_tax_2.id]}, {'name': self.percent_tax_2.name, 'tax_base_amount': 221, 'price_unit': 26.52, 'tax_ids': []}, @@ -224,7 +224,7 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): # Test invoice repartition invoice = self._create_invoice([(100, tax)], inv_type='out_invoice') - invoice.post() + invoice.action_post() self.assertEqual(len(invoice.line_ids), 4, "There should be 4 account move lines created for the invoice: payable, base and 2 tax lines") inv_base_line = invoice.line_ids.filtered(lambda x: not x.tax_repartition_line_id and x.account_id.user_type_id.type != 'receivable') @@ -240,7 +240,7 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): # Test refund repartition refund = self._create_invoice([(100, tax)], inv_type='out_refund') - refund.post() + refund.action_post() self.assertEqual(len(refund.line_ids), 4, "There should be 4 account move lines created for the refund: payable, base and 2 tax lines") ref_base_line = refund.line_ids.filtered(lambda x: not x.tax_repartition_line_id and x.account_id.user_type_id.type != 'receivable') diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index c7350c25701..b904e0b8cd9 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -26,7 +26,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): (0, 0, {'quantity': 1, 'price_unit': 50.0, 'name': 'test'}) ], }) - move.post() + move.action_post() # Create a bank statement of 40 EURO. bank_stmt = self.env['account.bank.statement'].create({ @@ -94,7 +94,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): }) ] }) - invoice.post() + invoice.action_post() # We create a bank statement with two lines of 1.00 USD each. statement = self.env['account.bank.statement'].create({ 'journal_id': self.bank_journal_usd_id, @@ -175,7 +175,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): 'line_ids': [(0,0, debit_line_vals), (0, 0, credit_line_vals)] } move = self.env['account.move'].create(vals) - move.post() + move.action_post() return move.id move_list_vals = [ ('1', -1.83, 0, self.currency_swiss_id), @@ -241,7 +241,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): 'line_ids': [(0,0, debit_line_vals), (0, 0, credit_line_vals)] } move_ids += self.env['account.move'].create(vals) - move_ids.post() + move_ids.action_post() account_move_line = move_ids.mapped('line_ids').filtered(lambda l: l.account_id == self.account_rcv) writeoff_vals = [{ @@ -312,7 +312,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): (0, 0, {'product_id': self.product.id, 'quantity': 1, 'price_unit': 50.0}) ], }) - (invoice_a + invoice_b).post() + (invoice_a + invoice_b).action_post() # Preparing Payments # One partial for invoice_a (fully assigned to it) @@ -609,7 +609,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): (0, 0, {'quantity': 1, 'price_unit': 100.0, 'name': 'product that cost 100'}) ], }) - invoice_cust_1.post() + invoice_cust_1.action_post() aml = invoice_cust_1.invoice_line_ids[0] self.assertEqual(aml.credit, 50.0) ##### @@ -742,7 +742,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): 'tax_repartition_line_id': self.tax_cash_basis.invoice_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax').id, 'tax_base_amount': 100, }) - purchase_move.post() + purchase_move.action_post() reverse_date = fields.Date.today() + timedelta(days=+7) revertWidget = self.env['account.move.reversal'].create({ @@ -780,7 +780,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): 'credit': 11, 'move_id': general_move1.id, }) - general_move1.post() + general_move1.action_post() general_move2 = self.env['account.move'].create({ 'name': 'general2', 'journal_id': self.general_journal.id, @@ -797,7 +797,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): 'debit': 10, 'move_id': general_move2.id, }) - general_move2.post() + general_move2.action_post() general_move3 = self.env['account.move'].create({ 'name': 'general3', 'journal_id': self.general_journal.id, @@ -814,7 +814,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): 'debit': 1, 'move_id': general_move3.id, }) - general_move3.post() + general_move3.action_post() to_reconcile = ((general_move1 + general_move2 + general_move3) .mapped('line_ids') .filtered(lambda l: l.account_id.id == account_rcv.id)) @@ -866,7 +866,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): ] }) - move_balance.post() + move_balance.action_post() move_balance_receiv = move_balance.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') (inv1_receivable + inv2_receivable + pay_receivable + move_balance_receiv).reconcile() @@ -934,7 +934,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): ] }) - move_balance.post() + move_balance.action_post() move_balance_receiv = move_balance.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') (inv1_receivable + inv2_receivable + pay_receivable + move_balance_receiv).reconcile() @@ -1015,7 +1015,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): ] }) - move_balance.post() + move_balance.action_post() move_balance_receiv = move_balance.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') (inv1_receivable + inv2_receivable + pay_receivable + move_balance_receiv).reconcile() @@ -1331,7 +1331,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon): (0, False, {'debit': 0.05, 'account_id': self.diff_expense_account.id, 'name': 'Balance WriteOff'}), ] }) - move_balance.post() + move_balance.action_post() move_balance_receiv = move_balance.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') (inv1_receivable + payment_receivable + move_balance_receiv).reconcile() diff --git a/addons/account/tests/test_reconciliation_matching_rules.py b/addons/account/tests/test_reconciliation_matching_rules.py index bb68dab220b..34bffa76fed 100644 --- a/addons/account/tests/test_reconciliation_matching_rules.py +++ b/addons/account/tests/test_reconciliation_matching_rules.py @@ -126,7 +126,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): invoice_line_form.price_unit = amount invoice_line_form.tax_ids.clear() invoice = invoice_form.save() - invoice.post() + invoice.action_post() lines = invoice.line_ids return lines.filtered(lambda l: l.account_id.user_type_id.type in ('receivable', 'payable')) @@ -420,7 +420,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): 'credit': 10, }) - move.post() + move.action_post() move_reversed = move._reverse_moves() self.assertTrue(move_reversed.exists()) @@ -619,7 +619,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): }), ], }) - move.post() + move.action_post() move_line_1 = move.line_ids.filtered(lambda line: line.debit == 100.0) move_line_2 = move.line_ids.filtered(lambda line: line.debit == 14.0) diff --git a/addons/account/tests/test_tax_report.py b/addons/account/tests/test_tax_report.py index eb81364760d..ff16eba5300 100644 --- a/addons/account/tests/test_tax_report.py +++ b/addons/account/tests/test_tax_report.py @@ -165,7 +165,7 @@ class TaxReportTest(AccountTestInvoicingCommon): (0, 0, {'quantity': 1, 'price_unit': 42, 'tax_ids': [(6, 0, test_tax.ids)]}), ], }) - test_invoice.post() + test_invoice.action_post() self.assertTrue(any(line.tax_tag_ids == self.tax_report_line_1_55.tag_ids[0] for line in test_invoice.line_ids), "The test invoice should contain a tax line with tag 55") tag_name_before = self.tax_report_line_1_55.tag_name diff --git a/addons/account/tests/test_transfer_wizard.py b/addons/account/tests/test_transfer_wizard.py index 760981438a4..76a393f790d 100644 --- a/addons/account/tests/test_transfer_wizard.py +++ b/addons/account/tests/test_transfer_wizard.py @@ -122,7 +122,7 @@ class TestTransferWizard(AccountTestInvoicingCommon): }), ] }) - cls.move_1.post() + cls.move_1.action_post() cls.move_2 = cls.env['account.move'].create({ 'journal_id': cls.journal.id, @@ -186,7 +186,7 @@ class TestTransferWizard(AccountTestInvoicingCommon): }), ] }) - cls.move_2.post() + cls.move_2.action_post() def test_transfer_wizard_reconcile(self): diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 18aa8075699..09f700adb78 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -486,10 +486,10 @@