Skip to content
Snippets Groups Projects

Enable mass validation of monthly statements.

Merged Etienne Ferriere requested to merge topic/11.0/TG-5326 into branch/11.0
+ 68
15
@@ -182,7 +182,7 @@
def test_monthly_statement(self):
"""Test monthly statements: reports & emails."""
# Fecth an user from the security group 'account.group_account_invoice'
# Fetch an user from the security group 'account.group_account_invoice'
account_user = self.env.ref("account_report.account_user_demo")
partner = self.env.ref("base.res_partner_10")
@@ -193,15 +193,4 @@
)
self.assertEqual(len(line_to_pay), 1)
def launchMonthlyStatement():
dlg = self.env["account.monthly_statement.gen"].create(
{
"begin_date": odoo.fields.Date.today(),
"end_date": odoo.fields.Date.today(),
}
)
dlg_ret = dlg.launch() # "domain": [("id", "in", batches.ids)],
batch_ids = dlg_ret["domain"][0][2]
return batch_ids
# First run: No batches as partner not set up for monthly statements.
@@ -207,5 +196,5 @@
# First run: No batches as partner not set up for monthly statements.
self.assertFalse(launchMonthlyStatement())
self.assertFalse(self._launchMonthlyStatement())
# Configure the partner for monthly statements.
partner.has_monthly_statements = True
@@ -214,7 +203,7 @@
)
# Run again; this now finds the invoice built above.
batch_ids = launchMonthlyStatement()
batch_ids = self._launchMonthlyStatement()
self.assertEqual(len(batch_ids), 1)
batch = self.env["account.monthly_statement"].browse(batch_ids[0])
self.assertEqual(batch.account_move_line_count, 1)
@@ -223,7 +212,6 @@
self.assertEqual(batch.state, "draft")
batch.with_context(user=account_user.id).validate()
self.assertEqual(batch.state, "in_progress")
# Run queued job to process the batch.
@@ -243,6 +231,71 @@
self.assertEqual(line_action["domain"][0][2], line_to_pay.ids)
self.assertEqual(line_action["res_model"], "account.move.line")
def test_monthly_statement_mass_validation(self):
"""Test monthly statements: Mass validation."""
for partner in (
self.env.ref("base.res_partner_7")
| self.env.ref("base.res_partner_8")
| self.env.ref("base.res_partner_9")
):
invoice = self._makeInvoice(partner)
self._validateInvoices(invoice)
line_to_pay = invoice.move_id.line_ids.filtered(
lambda line: line.account_id.internal_type == "receivable"
)
self.assertEqual(len(line_to_pay), 1)
# Configure the partner for monthly statements.
partner.has_monthly_statements = True
partner.monthly_statement_kind_id = self.env.ref(
"account_report.monthly_statement_kind_1"
)
# Run again; this now finds the invoice built above.
batch_ids = self._launchMonthlyStatement()
self.assertEqual(len(batch_ids), 3)
batches = self.env["account.monthly_statement"].browse(batch_ids)
for batch in batches:
self.assertEqual(batch.account_move_line_count, 1)
self.assertEqual(batch.account_move_line_ids, line_to_pay)
self.assertAlmostEqual(batch.amount, AMOUNT)
self.assertEqual(batch.state, "draft")
server_action = self.env.ref(
"account_report."
"account_monthly_statement_mass_validate_server_action"
)
server_action.with_context(active_ids=batch_ids).run()
self.assertTrue(
all(batches.mapped(lambda r: r.state == "in_progress"))
)
# Run queued job to process the batches.
for job in batches.mapped("queue_job_ids"):
self._runQueuedJob(job)
batches.refresh()
self.assertTrue(all(batches.mapped(lambda r: r.state == "done")))
with self.assertRaises(odoo.exceptions.UserError):
server_action.with_context(active_ids=batch_ids).run()
def _launchMonthlyStatement(self):
"""Create montly statements.
"""
dlg = self.env["account.monthly_statement.gen"].create(
{
"begin_date": odoo.fields.Date.today(),
"end_date": odoo.fields.Date.today(),
}
)
dlg_ret = dlg.launch() # "domain": [("id", "in", batches.ids)],
batch_ids = dlg_ret["domain"][0][2]
return batch_ids
def _consult_account(self, account, **kwargs):
"""Consult the specified account; return extracted accounting entries.
Loading