Skip to content

Commit 6fb128e

Browse files
smetlclbr-odoo
authored andcommitted
[IMP] account: Add test ensuring peppol status updated automatically
When creating a SO on e-commerce leading to an automatic invoice, the invoice is automatically sent using Peppol upon the payment. This test ensures the peppol status of the partner is updated during the process. task_id: 5025176 closes #239962 X-original-commit: 897dd0c Signed-off-by: Claire Bretton (clbr) <clbr@odoo.com>
1 parent 3d8c06f commit 6fb128e

File tree

3 files changed

+86
-21
lines changed

3 files changed

+86
-21
lines changed

addons/account/tests/common.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,42 @@ def _register_payment(cls, record, **kwargs):
787787
._create_payments()
788788
)
789789

790+
@contextmanager
791+
def mocked_get_payment_method_information(self, code='none'):
792+
self.ensure_installed('account_payment')
793+
794+
Method_get_payment_method_information = self.env['account.payment.method']._get_payment_method_information
795+
796+
def _get_payment_method_information(*args, **kwargs):
797+
res = Method_get_payment_method_information()
798+
res[code] = {'mode': 'electronic', 'type': ('bank',)}
799+
return res
800+
801+
with patch.object(self.env.registry['account.payment.method'], '_get_payment_method_information', _get_payment_method_information):
802+
yield
803+
804+
@classmethod
805+
def _create_dummy_payment_method_for_provider(cls, provider, journal, **kwargs):
806+
cls.ensure_installed('account_payment')
807+
808+
code = kwargs.get('code', 'none')
809+
810+
with cls.mocked_get_payment_method_information(cls, code):
811+
payment_method = cls.env['account.payment.method'].sudo().create({
812+
'name': 'Dummy method',
813+
'code': code,
814+
'payment_type': 'inbound',
815+
**kwargs,
816+
})
817+
provider.journal_id = journal
818+
return payment_method
819+
790820
@classmethod
791821
def _create_sale_order(cls, confirm=True, **values):
792822
cls.ensure_installed('sale')
793823

824+
cls._prepare_record_kwargs('sale.order', values)
825+
794826
sale_order = cls.env['sale.order'].create([{
795827
'partner_id': cls.partner_a.id,
796828
'order_line': [

addons/account_payment/tests/common.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ class AccountPaymentCommon(PaymentCommon, AccountTestInvoicingCommon):
1212
@classmethod
1313
def setUpClass(cls):
1414
super().setUpClass()
15-
with cls.mocked_get_payment_method_information(cls):
16-
cls.dummy_provider_method = cls.env['account.payment.method'].sudo().create({
17-
'name': 'Dummy method',
18-
'code': 'none',
19-
'payment_type': 'inbound'
20-
})
21-
cls.dummy_provider.journal_id = cls.company_data['default_journal_bank']
15+
cls.dummy_provider_method = cls._create_dummy_payment_method_for_provider(
16+
provider=cls.dummy_provider,
17+
journal=cls.company_data['default_journal_bank'],
18+
)
2219

2320
cls.account = cls.outbound_payment_method_line.payment_account_id
2421
cls.invoice = cls.env['account.move'].create({
@@ -47,17 +44,3 @@ def setUpClass(cls):
4744
def setUp(self):
4845
self.enable_post_process_patcher = False
4946
super().setUp()
50-
51-
#=== Utils ===#
52-
53-
@contextmanager
54-
def mocked_get_payment_method_information(self):
55-
Method_get_payment_method_information = self.env['account.payment.method']._get_payment_method_information
56-
57-
def _get_payment_method_information(*args, **kwargs):
58-
res = Method_get_payment_method_information()
59-
res['none'] = {'mode': 'electronic', 'type': ('bank',)}
60-
return res
61-
62-
with patch.object(self.env.registry['account.payment.method'], '_get_payment_method_information', _get_payment_method_information):
63-
yield

addons/account_peppol/tests/test_peppol_messages.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from requests import PreparedRequest, Response, Session
88

9+
from odoo import Command
910
from odoo.exceptions import UserError
1011
from odoo.tests.common import tagged, freeze_time
1112
from odoo.tools.misc import file_open
@@ -596,3 +597,52 @@ def test_compute_available_peppol_eas_multi_partner(self):
596597
partners._compute_available_peppol_eas()
597598
for partner in partners:
598599
self.assertFalse('odemo' in partner.available_peppol_eas)
600+
601+
def test_automatic_invoicing_auto_update_partner_peppol_status(self):
602+
self.ensure_installed('sale')
603+
tax = self.percent_tax(21.0)
604+
product = self._create_product(lst_price=100.0, taxes_id=tax)
605+
partner = self.env['res.partner'].create({
606+
'name': 'partner_be',
607+
'street': "Rue des Bourlottes 9",
608+
'zip': "1367",
609+
'city': "Ramillies",
610+
'vat': 'BE0477472701',
611+
'company_registry': '0477472701',
612+
'invoice_sending_method': 'peppol',
613+
'invoice_edi_format': 'ubl_bis3',
614+
'company_id': self.env.company.id,
615+
'country_id': self.env.ref('base.be').id,
616+
})
617+
self.env.user.group_ids |= self.env.ref('sales_team.group_sale_salesman')
618+
619+
self.env['ir.config_parameter'].sudo().set_param('sale.automatic_invoice', True)
620+
so = self._create_sale_order_one_line(product_id=product, partner_id=partner)
621+
622+
payment_method = self.env.ref('payment.payment_method_unknown')
623+
624+
dummy_provider = self.env['payment.provider'].create({
625+
'name': "Dummy Provider",
626+
'code': 'none',
627+
'state': 'test',
628+
'is_published': True,
629+
'payment_method_ids': [Command.set(payment_method.ids)],
630+
'allow_tokenization': True,
631+
})
632+
self._create_dummy_payment_method_for_provider(
633+
provider=dummy_provider,
634+
journal=self.company_data['default_journal_bank'],
635+
)
636+
transaction = self.env['payment.transaction'].create({
637+
'payment_method_id': payment_method.id,
638+
'amount': so.amount_total,
639+
'state': 'done',
640+
'provider_id': dummy_provider.id,
641+
'currency_id': so.currency_id.id,
642+
'reference': so.name,
643+
'partner_id': partner.id,
644+
'sale_order_ids': [Command.set(so.ids)],
645+
})
646+
transaction.sudo()._post_process()
647+
648+
self.assertRecordValues(partner, [{'peppol_verification_state': 'valid'}])

0 commit comments

Comments
 (0)