diff --git a/account_move_name_sequence/models/account_move.py b/account_move_name_sequence/models/account_move.py index 5846861fb..ea7478878 100644 --- a/account_move_name_sequence/models/account_move.py +++ b/account_move_name_sequence/models/account_move.py @@ -87,3 +87,10 @@ class AccountMove(models.Model): def _post(self, soft=True): self.flush() return super()._post(soft=soft) + + def _compute_name(self): + """Overwrite account module method in order to + avoid side effect if legacy code call it directly + like when creating entry from email. + """ + return self._compute_name_by_sequence() diff --git a/account_move_name_sequence/tests/__init__.py b/account_move_name_sequence/tests/__init__.py index 5510ca286..7f2d011b8 100644 --- a/account_move_name_sequence/tests/__init__.py +++ b/account_move_name_sequence/tests/__init__.py @@ -1,2 +1,3 @@ from . import test_account_move_name_seq from . import test_sequence_concurrency +from . import test_account_incoming_supplier_invoice diff --git a/account_move_name_sequence/tests/test_account_incoming_supplier_invoice.py b/account_move_name_sequence/tests/test_account_incoming_supplier_invoice.py new file mode 100644 index 000000000..139969ab2 --- /dev/null +++ b/account_move_name_sequence/tests/test_account_incoming_supplier_invoice.py @@ -0,0 +1,87 @@ +import json + +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountIncomingSupplierInvoice(AccountTestInvoicingCommon): + """Testing creating account move fetching mail.alias""" + + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + + cls.env["ir.config_parameter"].sudo().set_param( + "mail.catchall.domain", "test-company.odoo.com" + ) + + cls.internal_user = cls.env["res.users"].create( + { + "name": "Internal User", + "login": "internal.user@test.odoo.com", + "email": "internal.user@test.odoo.com", + } + ) + + cls.supplier_partner = cls.env["res.partner"].create( + { + "name": "Your Supplier", + "email": "supplier@other.company.com", + "supplier_rank": 10, + } + ) + + cls.journal = cls.company_data["default_journal_purchase"] + + journal_alias = cls.env["mail.alias"].create( + { + "alias_name": "test-bill", + "alias_model_id": cls.env.ref("account.model_account_move").id, + "alias_defaults": json.dumps( + { + "move_type": "in_invoice", + "company_id": cls.env.user.company_id.id, + "journal_id": cls.journal.id, + } + ), + } + ) + cls.journal.write({"alias_id": journal_alias.id}) + + def test_supplier_invoice_mailed_from_supplier(self): + """this test is mainly inspired from + addons.account.tests.test_account_incoming_supplier_invoice + python module but we make sure account move is draft without + name + """ + message_parsed = { + "message_id": "message-id-dead-beef", + "subject": "Incoming bill", + "from": "%s <%s>" + % (self.supplier_partner.name, self.supplier_partner.email), + "to": "%s@%s" + % (self.journal.alias_id.alias_name, self.journal.alias_id.alias_domain), + "body": "You know, that thing that you bought.", + "attachments": [b"Hello, invoice"], + } + + invoice = self.env["account.move"].message_new( + message_parsed, {"move_type": "in_invoice", "journal_id": self.journal.id} + ) + + message_ids = invoice.message_ids + self.assertEqual( + len(message_ids), 1, "Only one message should be posted in the chatter" + ) + self.assertEqual( + message_ids.body, + "
Vendor Bill Created
", + "Only the invoice creation should be posted", + ) + + following_partners = invoice.message_follower_ids.mapped("partner_id") + self.assertEqual(following_partners, self.env.user.partner_id) + self.assertEqual(invoice.state, "draft") + self.assertEqual(invoice.name, "/")