[MIG] account_chorus_notify: migrate to 18.0

This commit is contained in:
Stéphan Sainléger
2026-08-04 12:02:47 +02:00
parent adeae4235d
commit ab50455ad3
7 changed files with 226 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import test_chorus_notify

View File

@@ -0,0 +1,100 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import Command, fields
from odoo.tests.common import TransactionCase
class TestChorusNotify(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.company = cls.env.ref('base.main_company')
cls.partner = cls.env['res.partner'].create({
'name': 'Test Vendor',
'company_id': cls.company.id,
})
cls.expense_account = cls.env['account.account'].create({
'code': '6TEST001',
'name': 'Test Expense',
'account_type': 'expense',
})
cls.journal = cls.env['account.journal'].create({
'name': 'Test Purchase',
'type': 'purchase',
'code': 'PURCH',
})
cls.flow = cls.env['chorus.flow'].create({
'name': 'TEST-FLOW-001',
'date': fields.Date.today(),
'company_id': cls.company.id,
})
cls.invoice = cls.env['account.move'].create({
'move_type': 'in_invoice',
'journal_id': cls.journal.id,
'partner_id': cls.partner.id,
'invoice_date': fields.Date.today(),
'chorus_flow_id': cls.flow.id,
'invoice_line_ids': [Command.create({
'name': 'Test line',
'price_unit': 100,
'quantity': 1,
'account_id': cls.expense_account.id,
})],
})
def _patch_chorus_api(self, status):
self.patch(
type(self.env['res.company']),
'_chorus_get_api_params',
lambda self, raise_if_ko=True: {'dummy': True},
)
self.patch(
type(self.env['chorus.flow']),
'_chorus_api_consulter_cr',
lambda self, api_params, session=None: (
{'status': status, 'notes': ''}, session,
),
)
def _assert_rejection_message(self, invoice, flow_name, expected=True):
messages = invoice.message_ids.filtered(
lambda m: 'Chorus flow n°%s rejected.' % flow_name in (m.body or '')
)
if expected:
self.assertTrue(
messages,
"A rejection message should be posted on invoice %s" % invoice.name,
)
else:
self.assertFalse(
messages,
"No rejection message expected on invoice %s" % invoice.name,
)
def test_flow_rejected_notifies_invoice(self):
self._patch_chorus_api('IN_REJETE')
self.flow.update_flow_status()
self.assertEqual(self.flow.status, 'IN_REJETE')
self._assert_rejection_message(self.invoice, 'TEST-FLOW-001')
def test_flow_accepted_does_not_notify(self):
self._patch_chorus_api('IN_INTEGRE')
self.flow.update_flow_status()
self.assertEqual(self.flow.status, 'IN_INTEGRE')
self._assert_rejection_message(self.invoice, 'TEST-FLOW-001', expected=False)
def test_flow_rejected_no_invoices(self):
flow2 = self.env['chorus.flow'].create({
'name': 'TEST-FLOW-002',
'date': fields.Date.today(),
'company_id': self.company.id,
})
self._patch_chorus_api('IN_REJETE')
flow2.update_flow_status()
self.assertEqual(flow2.status, 'IN_REJETE')