[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) <bib@odoo.com>
Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com>
This commit is contained in:
Anh Thao Pham (pta)
2024-02-20 07:52:07 +00:00
parent 4fcc15556d
commit 5b0d5b7f6a
2 changed files with 40 additions and 1 deletions
-1
View File
@@ -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 '',
@@ -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)