diff --git a/bankayma_account/models/account_move.py b/bankayma_account/models/account_move.py index f29833dd6..da7279fef 100644 --- a/bankayma_account/models/account_move.py +++ b/bankayma_account/models/account_move.py @@ -356,6 +356,7 @@ def _portal_create_vendor_bill(self, post_data, uploaded_files): } ) invoice.invoice_line_ids.write(line_vals) + invoice.invoice_line_ids.invalidate_recordset() attachments = self.env["ir.attachment"] for uploaded_file in uploaded_files.getlist("upload"): attachments += self.env["ir.attachment"].create( diff --git a/bankayma_account/tests/test_bankayma_account_portal.py b/bankayma_account/tests/test_bankayma_account_portal.py index 72c34b5f9..b6567943b 100644 --- a/bankayma_account/tests/test_bankayma_account_portal.py +++ b/bankayma_account/tests/test_bankayma_account_portal.py @@ -6,7 +6,7 @@ from werkzeug.datastructures import MultiDict -from odoo.tests.common import TransactionCase +from odoo.tests.common import Form, TransactionCase class TestBankaymaAccountPortal(TransactionCase): @@ -17,7 +17,7 @@ def test_vendor_bill(self): [("company_id", "=", self.env.company.id)], limit=1 ) fpos.bankayma_tax_id = self.env["account.tax"].search( - [("type_tax_use", "=", "purchase")], limit=1 + [("type_tax_use", "=", "purchase"), ("sequence", ">=", 0)], limit=1 ) fpos.bankayma_deduct_tax = True invoice = ( @@ -51,6 +51,17 @@ def test_vendor_bill(self): ] ) self.assertTrue(attachment) - self.assertEqual(len(invoice.invoice_line_ids.tax_ids), 2) - self.assertIn(fpos.bankayma_tax_id, invoice.invoice_line_ids.tax_ids) + taxes = invoice.invoice_line_ids.tax_ids + self.assertEqual(len(taxes), 2) + self.assertEqual(fpos.bankayma_tax_id, invoice.invoice_line_ids.tax_ids[-1:]) + self.assertEqual(invoice.invoice_line_ids.tax_ids[:1].sequence, -1) self.assertTrue(invoice.partner_id.bankayma_vendor_max_amount, 424242) + with Form(invoice) as invoice_form: + invoice_form.invoice_line_ids.product_id = self.env[ + "product.product" + ].search( + [ + ("id", "!=", invoice.invoice_line_ids.product_id.id), + ] + ) + self.assertEqual(taxes, invoice.invoice_line_ids.tax_ids)