From 929f6288ec00429c7c4d7a7762007098e60ada68 Mon Sep 17 00:00:00 2001 From: "Maximilien (malb)" Date: Fri, 5 May 2023 12:45:48 +0000 Subject: [PATCH] [REV] purchase: ensure all vendor bills are gathered from purchase order With the recent change made in this task: https://www.odoo.com/web#id=3279233&menu_id=4720&cids=1&action=333&active_id=967&model=project.task&view_type=form The following commit can be reverted. (@Whenrow confirm to me that this commit is no longer useful). https://github.com/odoo/odoo/commit/e3101d92187946b2bd539e05956e4e83cd9c9097 opw-3214033 Part-of: odoo/odoo#120628 --- addons/purchase/models/purchase.py | 4 -- addons/purchase/tests/test_access_rights.py | 41 --------------------- 2 files changed, 45 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index e5dec5ece81..b0c226d7483 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -669,11 +669,7 @@ class PurchaseOrder(models.Model): immediately. """ if not invoices: - # Invoice_ids may be filtered depending on the user. To ensure we get all - # invoices related to the purchase order, we read them in sudo to fill the - # cache. self.invalidate_model(['invoice_ids']) - self.sudo().fetch(['invoice_ids']) invoices = self.invoice_ids result = self.env['ir.actions.act_window']._for_xml_id('account.action_move_in_invoice_type') diff --git a/addons/purchase/tests/test_access_rights.py b/addons/purchase/tests/test_access_rights.py index 886ec1396bb..5fe67001083 100644 --- a/addons/purchase/tests/test_access_rights.py +++ b/addons/purchase/tests/test_access_rights.py @@ -96,47 +96,6 @@ class TestPurchaseInvoice(AccountTestInvoicingCommon): vendor_bill_user1 = Form(vendor_bill_user2.with_user(self.purchase_user)) vendor_bill_user1 = vendor_bill_user1.save() - def test_read_purchase_order_2(self): - """ Check that a 2 purchase users with open the vendor bill the same - way even with a 'own documents only' record rule. """ - - # edit the account.move record rule for purchase user in order to ensure - # a user can only see his own invoices - rule = self.env.ref('purchase.purchase_user_account_move_rule') - rule.domain_force = "['&', ('move_type', 'in', ('in_invoice', 'in_refund', 'in_receipt')), ('invoice_user_id', '=', user.id)]" - - # create a purchase and make a vendor bill from it as purchase user 2 - purchase_user_2 = self.purchase_user.copy({ - 'name': 'Purchase user 2', - 'login': 'purchaseUser2', - 'email': 'pu2@odoo.com', - }) - - purchase_order_form = Form(self.env['purchase.order'].with_user(purchase_user_2)) - purchase_order_form.partner_id = self.vendor - with purchase_order_form.order_line.new() as line: - line.name = self.product.name - line.product_id = self.product - line.product_qty = 4 - line.price_unit = 5 - - purchase_order_user2 = purchase_order_form.save() - purchase_order_user2.button_confirm() - - purchase_order_user2.order_line.qty_received = 4 - purchase_order_user2.action_create_invoice() - vendor_bill_user2 = purchase_order_user2.invoice_ids - - # check user 1 cannot read the invoice - with self.assertRaises(AccessError): - Form(vendor_bill_user2.with_user(self.purchase_user)) - - # Check that calling 'action_view_invoice' return the same action despite the record rule - action_user_1 = purchase_order_user2.with_user(self.purchase_user).action_view_invoice() - purchase_order_user2.invalidate_recordset() - action_user_2 = purchase_order_user2.with_user(purchase_user_2).action_view_invoice() - self.assertEqual(action_user_1, action_user_2) - def test_double_validation(self): """Only purchase managers can approve a purchase order when double validation is enabled"""