From 5b0d5b7f6a2168e2dec11765eabb0dadb8ef5744 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Tue, 30 Jan 2024 15:12:30 +0000 Subject: [PATCH] [FIX] purchase: do not populate salesperson of bill from PO Steps to reproduce: - Install Accounting and Purchase - Create a PO with Purchase Representative different from current user (e.g. Marc Demo) 1) - Mark the product as received - Create a bill from PO 2) - Go to Accounting - Create a bill - Select the PO in Auto-Complete field - Save the bill Issue: The Purchase Representative of the PO is set as Salesperson (hidden field) of the bill. He should not. In the second case, by adding the purchase representative as Salesperson of the bill, he is also added as a follower of the bill and he receives a notification about being assigned to the bill. opw-3677713 closes odoo/odoo#154669 X-original-commit: 07cf6c0e320cd719ea5b6531c2c84f55d8627722 Signed-off-by: Brice Bartoletti (bib) Signed-off-by: Anh Thao Pham (pta) --- addons/purchase/models/purchase_order.py | 1 - .../purchase/tests/test_purchase_invoice.py | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/addons/purchase/models/purchase_order.py b/addons/purchase/models/purchase_order.py index 3ab5279db49..0f701344515 100644 --- a/addons/purchase/models/purchase_order.py +++ b/addons/purchase/models/purchase_order.py @@ -643,7 +643,6 @@ class PurchaseOrder(models.Model): 'move_type': move_type, 'narration': self.notes, 'currency_id': self.currency_id.id, - 'invoice_user_id': self.user_id and self.user_id.id or self.env.user.id, 'partner_id': partner_invoice.id, 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id._get_fiscal_position(partner_invoice)).id, 'payment_reference': self.partner_ref or '', diff --git a/addons/purchase/tests/test_purchase_invoice.py b/addons/purchase/tests/test_purchase_invoice.py index 7183a5b5620..8734480f097 100644 --- a/addons/purchase/tests/test_purchase_invoice.py +++ b/addons/purchase/tests/test_purchase_invoice.py @@ -989,3 +989,43 @@ class TestInvoicePurchaseMatch(TestPurchaseToInvoiceCommon): move_form.purchase_vendor_bill_id = self.env['purchase.bill.union'].browse(-purchase_order.id).exists() payment_reference = move_form._values['payment_reference'] self.assertEqual(payment_reference, expected_value, "The payment reference should be %s" % expected_value) + + def test_invoice_user_id_on_bill(self): + """ + Test that the invoice_user_id field is False when creating a vendor bill from a PO + or when using Auto-Complete feature of a vendor bill. + """ + group_purchase_user = self.env.ref('purchase.group_purchase_user') + group_employee = self.env.ref('base.group_user') + group_partner_manager = self.env.ref('base.group_partner_manager') + purchase_user = self.env['res.users'].with_context(no_reset_password=True).create({ + 'name': 'Purchase user', + 'login': 'purchaseUser', + 'email': 'pu@odoo.com', + 'groups_id': [Command.set([group_purchase_user.id, group_employee.id, group_partner_manager.id])], + }) + po1 = self.env['purchase.order'].with_context(tracking_disable=True).create({ + 'partner_id': self.partner_a.id, + 'user_id': purchase_user.id, + 'order_line': [ + Command.create({ + 'product_id': self.product_order.id, + 'product_qty': 1.0, + 'price_unit': self.product_order.list_price, + 'taxes_id': False, + }), + ] + }) + po2 = po1.copy() + po1.button_confirm() + po2.button_confirm() + # creating bill from PO + po1.order_line.qty_received = 1 + po1.action_create_invoice() + invoice1 = po1.invoice_ids + self.assertFalse(invoice1.invoice_user_id) + # creating bill with Auto_complete feature + move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice')) + move_form.purchase_vendor_bill_id = self.env['purchase.bill.union'].browse(-po2.id) + invoice2 = move_form.save() + self.assertFalse(invoice2.invoice_user_id)