fix(fusion_accounting_bank_rec): test factory adapts to V19 Community semantics
After Enterprise's account_accountant is uninstalled, account.bank.statement.journal_id reverts to its V19 Community definition \u2014 a read-only computed field derived from line_ids.journal_id. Direct writes are silently dropped (which is what was happening: 55 tests errored with 'null value in column journal_id' because the test's statement had no journal, and the line factory was reading statement.journal_id (False) and passing that to the line create). Fix: - make_bank_statement now bootstraps the statement with one zero-amount line carrying journal_id, so the computed journal_id resolves correctly. - make_bank_line no longer routes journal through the statement \u2014 journal_id is set directly on the line (which is V19 Community's intended path; lines can exist standalone without a statement). This is a test-only change; runtime behaviour is unchanged. Real users creating bank lines via the UI already use the correct path. Made-with: Cursor
This commit is contained in:
@@ -29,30 +29,50 @@ def make_bank_journal(env, *, name='Test Bank', code=None):
|
||||
|
||||
|
||||
def make_bank_statement(env, *, journal=None, name='Test Statement', date_=None):
|
||||
"""Create a bank statement. Auto-creates a bank journal if not provided."""
|
||||
"""Create a bank statement.
|
||||
|
||||
NOTE: in V19 Community, ``account.bank.statement.journal_id`` is a
|
||||
read-only computed field derived from ``line_ids.journal_id`` — direct
|
||||
writes are silently dropped. Enterprise's ``account_accountant`` used to
|
||||
override this to make it writable; without Enterprise we have to derive
|
||||
the journal from a line. We attach a single token line at create time
|
||||
(later removed/replaced by the test) to bootstrap the journal.
|
||||
"""
|
||||
journal = journal or make_bank_journal(env)
|
||||
return env['account.bank.statement'].create({
|
||||
'name': name,
|
||||
'date': date_ or date.today(),
|
||||
'line_ids': [(0, 0, {
|
||||
'journal_id': journal.id,
|
||||
'date': date_ or date.today(),
|
||||
'payment_ref': 'Statement bootstrap line',
|
||||
'amount': 0.0,
|
||||
})],
|
||||
})
|
||||
|
||||
|
||||
def make_bank_line(env, *, journal=None, statement=None, amount=100.00,
|
||||
partner=None, memo='Test line', date_=None):
|
||||
"""Create a bank statement line. Creates statement if not provided.
|
||||
"""Create a bank statement line. Creates a journal (and optionally a
|
||||
statement) if not provided.
|
||||
|
||||
Most-common factory in tests. Defaults give a $100 line with no partner."""
|
||||
if not statement:
|
||||
statement = make_bank_statement(env, journal=journal, date_=date_)
|
||||
return env['account.bank.statement.line'].create({
|
||||
'statement_id': statement.id,
|
||||
'journal_id': statement.journal_id.id,
|
||||
In V19 Community, lines can exist standalone — a statement is not
|
||||
required. We create one only if the test explicitly passes ``statement=``.
|
||||
"""
|
||||
if statement and not journal:
|
||||
journal = statement.journal_id
|
||||
if not journal:
|
||||
journal = make_bank_journal(env)
|
||||
vals = {
|
||||
'journal_id': journal.id,
|
||||
'date': date_ or date.today(),
|
||||
'payment_ref': memo,
|
||||
'amount': amount,
|
||||
'partner_id': partner.id if partner else False,
|
||||
})
|
||||
}
|
||||
if statement:
|
||||
vals['statement_id'] = statement.id
|
||||
return env['account.bank.statement.line'].create(vals)
|
||||
|
||||
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user