[FIX] purchase: stop adding useless vendor to product vendor list
Current behavior: When you create a contact and a delivery adress for this contact. If you add the delivery adress as a vendor to a product, and purchase this product from the delivery adress, the contact will be added to the product vendor list. Steps to reproduce: - Create contact C - Create delivery adress D for C - Create product P - Add D as a vendor to P - Create PO for P from D, and confirm it - Go to P, and check the vendor list (C is there) opw-3177309 closes odoo/odoo#117902 X-original-commit: 67031d2b3d7d52297d18a69c76b4f747b17142e3 Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
@@ -523,7 +523,8 @@ class PurchaseOrder(models.Model):
|
||||
for line in self.order_line:
|
||||
# Do not add a contact as a supplier
|
||||
partner = self.partner_id if not self.partner_id.parent_id else self.partner_id.parent_id
|
||||
if line.product_id and partner not in line.product_id.seller_ids.partner_id and len(line.product_id.seller_ids) <= 10:
|
||||
already_seller = (partner | self.partner_id) & line.product_id.seller_ids.mapped('partner_id')
|
||||
if line.product_id and not already_seller and len(line.product_id.seller_ids) <= 10:
|
||||
# Convert the price in the right currency.
|
||||
currency = partner.property_purchase_currency_id or self.env.company.currency_id
|
||||
price = self.currency_id._convert(line.price_unit, currency, line.company_id, line.date_order or fields.Date.today(), round=False)
|
||||
|
||||
@@ -333,3 +333,42 @@ class TestPurchase(AccountTestInvoicingCommon):
|
||||
po_line.product_id = product
|
||||
purchase_order_coco = po_form.save()
|
||||
self.assertEqual(purchase_order_coco.order_line.price_unit, currency_rate.rate * product.standard_price, "Value shouldn't be rounded 🍫")
|
||||
|
||||
def test_purchase_not_creating_useless_product_vendor(self):
|
||||
""" This test ensures that the product vendor is not created when the
|
||||
product is not set on the purchase order line.
|
||||
"""
|
||||
|
||||
#create a contact of type contact
|
||||
contact = self.env['res.partner'].create({
|
||||
'name': 'Contact',
|
||||
'type': 'contact',
|
||||
})
|
||||
|
||||
#create a contact of type Delivery Address lnked to the contact
|
||||
delivery_address = self.env['res.partner'].create({
|
||||
'name': 'Delivery Address',
|
||||
'type': 'delivery',
|
||||
'parent_id': contact.id,
|
||||
})
|
||||
|
||||
#create a product that use the delivery address as vendor
|
||||
product = self.env['product.product'].create({
|
||||
'name': 'Product A',
|
||||
'seller_ids': [(0, 0, {
|
||||
'partner_id': delivery_address.id,
|
||||
'min_qty': 1.0,
|
||||
'price': 1.0,
|
||||
})]
|
||||
})
|
||||
|
||||
#create a purchase order with the delivery address as partner
|
||||
po_form = Form(self.env['purchase.order'])
|
||||
po_form.partner_id = delivery_address
|
||||
with po_form.order_line.new() as po_line:
|
||||
po_line.product_id = product
|
||||
po_line.product_qty = 1.0
|
||||
po = po_form.save()
|
||||
po.button_confirm()
|
||||
|
||||
self.assertEqual(po.order_line.product_id.seller_ids.mapped('partner_id'), delivery_address)
|
||||
|
||||
Reference in New Issue
Block a user