@@ -172,7 +172,7 @@ def test_07_alternative_purchases_wizards(self):
172
172
# first flow: check that creating an alt PO correctly auto-links both POs to each other
173
173
action = orig_po .action_create_alternative ()
174
174
alt_po_wiz = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
175
- alt_po_wiz .partner_id = self .res_partner_1
175
+ alt_po_wiz .partner_ids = self .res_partner_1
176
176
alt_po_wiz .copy_products = True
177
177
alt_po_wiz = alt_po_wiz .save ()
178
178
alt_po_wiz .action_create_alternative ()
@@ -203,7 +203,7 @@ def test_07_alternative_purchases_wizards(self):
203
203
# second flow: create extra alt PO, check that all 3 POs are correctly auto-linked
204
204
action = orig_po .action_create_alternative ()
205
205
alt_po_wiz = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
206
- alt_po_wiz .partner_id = self .res_partner_1
206
+ alt_po_wiz .partner_ids = self .res_partner_1
207
207
alt_po_wiz .copy_products = True
208
208
alt_po_wiz = alt_po_wiz .save ()
209
209
alt_po_wiz .action_create_alternative ()
@@ -276,7 +276,7 @@ def test_09_alternative_po_line_price_unit(self):
276
276
# Creates an alternative PO.
277
277
action = po_1 .action_create_alternative ()
278
278
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
279
- alt_po_wizard_form .partner_id = self .res_partner_1
279
+ alt_po_wizard_form .partner_ids = self .res_partner_1
280
280
alt_po_wizard_form .copy_products = True
281
281
alt_po_wizard = alt_po_wizard_form .save ()
282
282
alt_po_wizard .action_create_alternative ()
@@ -310,7 +310,7 @@ def test_10_alternative_po_line_price_unit_different_uom(self):
310
310
# Creates an alternative PO.
311
311
action = po_1 .action_create_alternative ()
312
312
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
313
- alt_po_wizard_form .partner_id = self .res_partner_1
313
+ alt_po_wizard_form .partner_ids = self .res_partner_1
314
314
alt_po_wizard_form .copy_products = True
315
315
alt_po_wizard = alt_po_wizard_form .save ()
316
316
alt_po_wizard .action_create_alternative ()
@@ -345,7 +345,7 @@ def test_11_alternative_po_from_po_with_requisition_id(self):
345
345
# Creates an alternative PO.
346
346
action = po_1 .action_create_alternative ()
347
347
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
348
- alt_po_wizard_form .partner_id = self .res_partner_1
348
+ alt_po_wizard_form .partner_ids = self .res_partner_1
349
349
alt_po_wizard_form .copy_products = True
350
350
alt_po_wizard = alt_po_wizard_form .save ()
351
351
alt_po_wizard .action_create_alternative ()
@@ -403,7 +403,7 @@ def test_12_alternative_po_line_different_currency(self):
403
403
# Creates an alternative PO
404
404
action = po_orig .action_create_alternative ()
405
405
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
406
- alt_po_wizard_form .partner_id = vendor_usd
406
+ alt_po_wizard_form .partner_ids = vendor_usd
407
407
alt_po_wizard_form .copy_products = True
408
408
alt_po_wizard = alt_po_wizard_form .save ()
409
409
alt_po_wizard .action_create_alternative ()
@@ -461,7 +461,7 @@ def test_alternative_po_with_multiple_price_list(self):
461
461
# Creates an alternative PO
462
462
action = po_orig .action_create_alternative ()
463
463
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
464
- alt_po_wizard_form .partner_id = vendor_b
464
+ alt_po_wizard_form .partner_ids = vendor_b
465
465
alt_po_wizard_form .copy_products = True
466
466
alt_po_wizard = alt_po_wizard_form .save ()
467
467
alt_po_wizard .action_create_alternative ()
@@ -544,7 +544,7 @@ def test_alternative_purchase_orders_with_vendor_specific_details(self):
544
544
# 1. Create an alternative PO with Supplier B (should use 'Custom Name B')
545
545
action = po_orig .action_create_alternative ()
546
546
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
547
- alt_po_wizard_form .partner_id = vendor_b
547
+ alt_po_wizard_form .partner_ids = vendor_b
548
548
alt_po_wizard_form .copy_products = True
549
549
alt_po_wizard = alt_po_wizard_form .save ()
550
550
alt_po_wizard .action_create_alternative ()
@@ -554,7 +554,7 @@ def test_alternative_purchase_orders_with_vendor_specific_details(self):
554
554
# 2. Create an alternative PO with Supplier C (should use '[Code C] Product')
555
555
action = po_orig .action_create_alternative ()
556
556
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
557
- alt_po_wizard_form .partner_id = vendor_c
557
+ alt_po_wizard_form .partner_ids = vendor_c
558
558
alt_po_wizard_form .copy_products = True
559
559
alt_po_wizard = alt_po_wizard_form .save ()
560
560
alt_po_wizard .action_create_alternative ()
@@ -573,7 +573,7 @@ def test_alternative_purchase_orders_with_vendor_specific_details(self):
573
573
# 3. Create an alternative PO with Supplier C (should NOT copy description, uses default product name)
574
574
action = po_single_qty .action_create_alternative ()
575
575
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
576
- alt_po_wizard_form .partner_id = vendor_c
576
+ alt_po_wizard_form .partner_ids = vendor_c
577
577
alt_po_wizard_form .copy_products = True
578
578
alt_po_wizard = alt_po_wizard_form .save ()
579
579
alt_po_wizard .action_create_alternative ()
@@ -583,7 +583,7 @@ def test_alternative_purchase_orders_with_vendor_specific_details(self):
583
583
# 4. Create an alternative PO with Supplier D (should copy description from Supplier A as no custom product_code/name exists)
584
584
action = po_single_qty .action_create_alternative ()
585
585
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
586
- alt_po_wizard_form .partner_id = vendor_d
586
+ alt_po_wizard_form .partner_ids = vendor_d
587
587
alt_po_wizard_form .copy_products = True
588
588
alt_po_wizard = alt_po_wizard_form .save ()
589
589
alt_po_wizard .action_create_alternative ()
@@ -672,7 +672,7 @@ def test_taxes_for_alternative_po(self):
672
672
# Creates an alternative PO
673
673
action = orig_po .action_create_alternative ()
674
674
alt_po_wizard_form = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
675
- alt_po_wizard_form .partner_id = vendor
675
+ alt_po_wizard_form .partner_ids = vendor
676
676
alt_po_wizard_form .copy_products = True
677
677
alt_po_wizard = alt_po_wizard_form .save ()
678
678
alt_po_id = alt_po_wizard .action_create_alternative ()['res_id' ]
@@ -694,7 +694,7 @@ def test_alternative_purchase_order_merge(self):
694
694
695
695
action = po_1 .action_create_alternative ()
696
696
alt_po_wiz = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
697
- alt_po_wiz .partner_id = res_partner_2
697
+ alt_po_wiz .partner_ids = res_partner_2
698
698
alt_po_wiz .copy_products = True
699
699
alt_po_wiz = alt_po_wiz .save ()
700
700
alt_po_wiz .action_create_alternative ()
@@ -708,11 +708,74 @@ def test_alternative_purchase_order_merge(self):
708
708
709
709
action = po_2 .action_create_alternative ()
710
710
alt_po_wiz = Form (self .env ['purchase.requisition.create.alternative' ].with_context (** action ['context' ]))
711
- alt_po_wiz .partner_id = res_partner_2
711
+ alt_po_wiz .partner_ids = res_partner_2
712
712
alt_po_wiz .copy_products = True
713
713
alt_po_wiz = alt_po_wiz .save ()
714
714
alt_po_wiz .action_create_alternative ()
715
715
po_orders = self .env ['purchase.order' ].search ([('partner_id' , '=' , res_partner_2 .id )])
716
716
merger_alternative_orders = po_orders [0 ] | po_orders [1 ]
717
717
merger_alternative_orders .action_merge ()
718
718
self .assertEqual (len (po_orders [0 ].alternative_po_ids ), 4 )
719
+
720
+ def test_create_alternatives_for_multiple_vendors (self ):
721
+ """
722
+ Ensure that adding multiple vendors in the Alternatives wizard
723
+ creates a separate alternative purchase order for each vendor.
724
+ """
725
+ res_partner_2 = self .env ['res.partner' ].create ({'name' : 'Vendor 2' })
726
+ res_partner_3 = self .env ['res.partner' ].create ({'name' : 'Vendor 3' })
727
+ res_partner_4 = self .env ['res.partner' ].create ({'name' : 'Vendor 4' })
728
+ # Create original purchase order (PO) with a vendor.
729
+ orig_po = self .env ['purchase.order' ].create ({
730
+ 'partner_id' : self .res_partner_1 .id ,
731
+ })
732
+
733
+ po_form = Form (orig_po )
734
+ with po_form .order_line .new () as line :
735
+ line .product_id = self .product_09
736
+ line .product_qty = 5.0
737
+ po_form .save ()
738
+
739
+ # Create alternatives PO's and check that all PO's (including the original) are auto-linked to each other.
740
+ alt_po_wiz = Form .from_action (self .env , orig_po .action_create_alternative ())
741
+ alt_po_wiz .partner_ids = res_partner_2 | res_partner_3 | res_partner_4
742
+ alt_po_wiz = alt_po_wiz .save ()
743
+ alt_po_wiz .action_create_alternative ()
744
+ self .assertEqual (len (orig_po .alternative_po_ids ), 4 , "There should be exactly 4 linked PO's: 1 original + 3 alternatives (one for each selected vendor.)" )
745
+
746
+ def test_alternative_purchase_vendor_currency (self ):
747
+ """
748
+ Ensure that the currency on the alternative RFQ is correctly set
749
+ based on the selected vendor purchase currency when creating
750
+ an alternative RFQ from an existing purchase order.
751
+ """
752
+ currency_eur = self .env .ref ("base.EUR" )
753
+ currency_usd = self .env .ref ("base.USD" )
754
+
755
+ self .res_partner_1 .write ({'property_purchase_currency_id' : currency_usd .id })
756
+ res_partner_2 = self .env ['res.partner' ].create ({'name' : 'Vendor 2' , 'property_purchase_currency_id' : currency_eur .id })
757
+
758
+ orig_po = self .env ['purchase.order' ].create ({
759
+ 'partner_id' : self .res_partner_1 .id ,
760
+ })
761
+ po_form = Form (orig_po )
762
+ with po_form .order_line .new () as line :
763
+ line .product_id = self .product_09
764
+ line .product_qty = 1.0
765
+ po_form .save ()
766
+
767
+ # Check that the currency is correctly set based on the selected vendor.
768
+ self .assertEqual (orig_po .currency_id , self .res_partner_1 .property_purchase_currency_id ,
769
+ "The original PO currency should match with the vendor purchase currency (USD)."
770
+ )
771
+
772
+ alt_po_wiz = Form .from_action (self .env , orig_po .action_create_alternative ())
773
+ alt_po_wiz .partner_ids = res_partner_2
774
+ alt_po_wizard = alt_po_wiz .save ()
775
+ alt_po_wizard .action_create_alternative ()
776
+ alt_po = orig_po .alternative_po_ids .filtered (lambda po : po .partner_id == res_partner_2 )
777
+
778
+ # Check that the currency is correctly set on the alternative PO based on the selected vendor.
779
+ self .assertEqual (alt_po .currency_id , res_partner_2 .property_purchase_currency_id ,
780
+ "The alternative PO currency should match with vendor 2 purchase currency (EUR)."
781
+ )
0 commit comments