[IMP] account: accrual never change account on the fly
Before this commit, the account on the original line was replaced by the accrual account. This could be problematic for hashed journals. Instead of having 2 different behaviors for hashed/non hashed journals, we decided to always create 2 journal entries, which is also more academic: * We don't replace something on an entry that has been posted * We don't end up with taxes on the accrual account * Accountants are used to do it this way closes odoo/odoo#42787 Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
This commit is contained in:
@@ -1669,12 +1669,11 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
'reconcile': True,
|
||||
}).id,
|
||||
})
|
||||
wizard.amend_entries()
|
||||
wizard_res = wizard.amend_entries()
|
||||
|
||||
self.assertInvoiceValues(move, [
|
||||
{
|
||||
**self.product_line_vals_1,
|
||||
'account_id': wizard.expense_accrual_account.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': 800.0,
|
||||
'debit': 400.0,
|
||||
@@ -1682,7 +1681,6 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
},
|
||||
{
|
||||
**self.product_line_vals_2,
|
||||
'account_id': wizard.expense_accrual_account.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': 160.0,
|
||||
'debit': 80.0,
|
||||
@@ -1716,12 +1714,12 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
'date': fields.Date.from_string('2017-01-01'),
|
||||
})
|
||||
|
||||
accrual_lines = move.invoice_line_ids.mapped('matched_credit_ids.credit_move_id.move_id.line_ids').sorted('date')
|
||||
accrual_lines = self.env['account.move'].browse(wizard_res['domain'][0][2]).line_ids.sorted('date')
|
||||
self.assertRecordValues(accrual_lines, [
|
||||
{'amount_currency': 320.0, 'debit': 160.0, 'credit': 0.0, 'account_id': self.product_line_vals_1['account_id'], 'reconciled': False},
|
||||
{'amount_currency': -320.0, 'debit': 0.0, 'credit': 160.0, 'account_id': wizard.expense_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': 64.0, 'debit': 32.0, 'credit': 0.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False},
|
||||
{'amount_currency': -64.0, 'debit': 0.0, 'credit': 32.0, 'account_id': wizard.expense_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': -480.0, 'debit': 0.0, 'credit': 240.0, 'account_id': self.product_line_vals_1['account_id'], 'reconciled': False},
|
||||
{'amount_currency': 480.0, 'debit': 240.0, 'credit': 0.0, 'account_id': wizard.expense_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': -96.0, 'debit': 0.0, 'credit': 48.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False},
|
||||
{'amount_currency': 96.0, 'debit': 48.0, 'credit': 0.0, 'account_id': wizard.expense_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': 480.0, 'debit': 240.0, 'credit': 0.0, 'account_id': self.product_line_vals_1['account_id'], 'reconciled': False},
|
||||
{'amount_currency': -480.0, 'debit': 0.0, 'credit': 240.0, 'account_id': wizard.expense_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': 96.0, 'debit': 48.0, 'credit': 0.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False},
|
||||
|
||||
@@ -2346,12 +2346,11 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
'reconcile': True,
|
||||
}).id,
|
||||
})
|
||||
wizard.amend_entries()
|
||||
wizard_res = wizard.amend_entries()
|
||||
|
||||
self.assertInvoiceValues(move, [
|
||||
{
|
||||
**self.product_line_vals_1,
|
||||
'account_id': wizard.revenue_accrual_account.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': -1000.0,
|
||||
'debit': 0.0,
|
||||
@@ -2359,7 +2358,6 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
},
|
||||
{
|
||||
**self.product_line_vals_2,
|
||||
'account_id': wizard.revenue_accrual_account.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': -200.0,
|
||||
'debit': 0.0,
|
||||
@@ -2395,12 +2393,12 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
'invoice_payment_ref': 'INV/2017/01/0001',
|
||||
})
|
||||
|
||||
accrual_lines = move.invoice_line_ids.mapped('matched_debit_ids.debit_move_id.move_id.line_ids').sorted('date')
|
||||
accrual_lines = self.env['account.move'].browse(wizard_res['domain'][0][2]).line_ids.sorted('date')
|
||||
self.assertRecordValues(accrual_lines, [
|
||||
{'amount_currency': -400.0, 'debit': 0.0, 'credit': 200.0, 'account_id': self.product_line_vals_1['account_id'], 'reconciled': False},
|
||||
{'amount_currency': 400.0, 'debit': 200.0, 'credit': 0.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': -80.0, 'debit': 0.0, 'credit': 40.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False},
|
||||
{'amount_currency': 80.0, 'debit': 40.0, 'credit': 0.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': 600.0, 'debit': 300.0, 'credit': 0.0, 'account_id': self.product_line_vals_1['account_id'], 'reconciled': False},
|
||||
{'amount_currency': -600.0, 'debit': 0.0, 'credit': 300.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': 120.0, 'debit': 60.0, 'credit': 0.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False},
|
||||
{'amount_currency': -120.0, 'debit': 0.0, 'credit': 60.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': -600.0, 'debit': 0.0, 'credit': 300.0, 'account_id': self.product_line_vals_1['account_id'], 'reconciled': False},
|
||||
{'amount_currency': 600.0, 'debit': 300.0, 'credit': 0.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True},
|
||||
{'amount_currency': -120.0, 'debit': 0.0, 'credit': 60.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False},
|
||||
|
||||
@@ -114,18 +114,18 @@ class AccrualAccountingWizard(models.TransientModel):
|
||||
move_data[aml.move_id]['move_vals']['original_date']['line_ids'] += [
|
||||
(0, 0, {
|
||||
'name': aml.name,
|
||||
'debit': aml.debit - reported_debit,
|
||||
'credit': aml.credit - reported_credit,
|
||||
'amount_currency': aml.amount_currency - reported_amount_currency,
|
||||
'debit': reported_credit,
|
||||
'credit': reported_debit,
|
||||
'amount_currency': -reported_amount_currency,
|
||||
'currency_id': aml.currency_id.id,
|
||||
'account_id': aml.account_id.id,
|
||||
'partner_id': aml.partner_id.id,
|
||||
}),
|
||||
(0, 0, {
|
||||
'name': _('Accrual Adjusting Entry'),
|
||||
'debit': aml.credit - reported_credit,
|
||||
'credit': aml.debit - reported_debit,
|
||||
'amount_currency': reported_amount_currency - aml.amount_currency,
|
||||
'debit': reported_debit,
|
||||
'credit': reported_credit,
|
||||
'amount_currency': reported_amount_currency,
|
||||
'currency_id': aml.currency_id.id,
|
||||
'account_id': accrual_account.id,
|
||||
'partner_id': aml.partner_id.id,
|
||||
@@ -174,7 +174,7 @@ class AccrualAccountingWizard(models.TransientModel):
|
||||
}
|
||||
|
||||
move_vals = [m for o in move_data.values() for m in o['move_vals'].values()]
|
||||
log_messages = [m for o in move_data.values() for m in o['log_messages'].values()]
|
||||
log_messages = [o['log_messages'] for o in move_data.values()]
|
||||
|
||||
record.data = json.dumps({
|
||||
'move_vals': move_vals,
|
||||
@@ -212,29 +212,25 @@ class AccrualAccountingWizard(models.TransientModel):
|
||||
data = json.loads(self.data)
|
||||
move_vals, log_messages = (data['move_vals'], data['log_messages'])
|
||||
|
||||
# Update the account of selected journal items.
|
||||
self.active_move_line_ids.write({'account_id': accrual_account.id})
|
||||
|
||||
created_moves = self.env['account.move'].create(move_vals)
|
||||
created_moves.post()
|
||||
|
||||
# Reconcile.
|
||||
index = 0
|
||||
for move in self.active_move_line_ids.mapped('move_id'):
|
||||
if self.percentage < 100:
|
||||
accrual_moves = created_moves[index:index + 2]
|
||||
index += 2
|
||||
else:
|
||||
accrual_moves = created_moves[index:index + 1]
|
||||
index += 1
|
||||
accrual_moves = created_moves[index:index + 2]
|
||||
|
||||
to_reconcile = self.active_move_line_ids.filtered(lambda line: line.move_id == move)
|
||||
to_reconcile += accrual_moves.mapped('line_ids').filtered(lambda line: line.account_id == accrual_account and not line.reconciled)
|
||||
to_reconcile = accrual_moves.mapped('line_ids').filtered(lambda line: line.account_id == accrual_account)
|
||||
to_reconcile.reconcile()
|
||||
|
||||
# Log messages.
|
||||
for created_move, log_message in zip(created_moves, log_messages):
|
||||
created_move.message_post(body=log_message)
|
||||
move.message_post(body=log_messages[index//2]['origin'] % {
|
||||
'first_id': accrual_moves[0].id,
|
||||
'first_name': accrual_moves[0].name,
|
||||
'second_id': accrual_moves[1].id,
|
||||
'second_name': accrual_moves[1].name,
|
||||
})
|
||||
accrual_moves[0].message_post(body=log_messages[index//2]['new_date'])
|
||||
accrual_moves[1].message_post(body=log_messages[index//2]['original_date'])
|
||||
index += 2
|
||||
|
||||
# open the generated entries
|
||||
action = {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"stock_in","Stock Interim (Received)","1102","account.data_account_type_current_assets","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"stock_out","Stock Interim (Delivered)","1103","account.data_account_type_current_assets","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"receivable","Account Receivable","1210","account.data_account_type_receivable","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"to_receive_rec","Products to receive","12101","account.data_account_type_current_assets","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"to_receive_rec","Products to receive","1211","account.data_account_type_current_assets","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"tax_paid","Tax Paid","1310","account.data_account_type_current_assets","l10n_generic_coa.configurable_chart_template","","False"
|
||||
"tax_receivable","Tax Receivable","1320","account.data_account_type_current_assets","l10n_generic_coa.configurable_chart_template","","False"
|
||||
"prepayments","Prepayments","1410","account.data_account_type_prepayments","l10n_generic_coa.configurable_chart_template","","False"
|
||||
@@ -12,7 +12,7 @@
|
||||
"non_current_assets","Non-current assets","1910","account.data_account_type_non_current_assets","l10n_generic_coa.configurable_chart_template","","False"
|
||||
"current_liabilities","Current Liabilities","2010","account.data_account_type_current_liabilities","l10n_generic_coa.configurable_chart_template","","False"
|
||||
"payable","Account Payable","2110","account.data_account_type_payable","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"to_receive_pay","Bills to receive","21101","account.data_account_type_current_liabilities","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"to_receive_pay","Bills to receive","2111","account.data_account_type_current_liabilities","l10n_generic_coa.configurable_chart_template","","True"
|
||||
"tax_received","Tax Received","2510","account.data_account_type_current_liabilities","l10n_generic_coa.configurable_chart_template","","False"
|
||||
"tax_payable","Tax Payable","2520","account.data_account_type_current_liabilities","l10n_generic_coa.configurable_chart_template","","False"
|
||||
"non_current_liabilities","Non-current Liabilities","2910","account.data_account_type_non_current_liabilities","l10n_generic_coa.configurable_chart_template","","False"
|
||||
|
||||
|
Reference in New Issue
Block a user