@@ -13,6 +13,9 @@ class TestShoppingfeedIntegration(AccountTestInvoicingCommon):
1313 def setUpClass (cls ):
1414 super ().setUpClass ()
1515 cls .bank_journal = cls .company_data ["default_journal_bank" ]
16+ cls .market_account = cls .company_data ["default_account_receivable" ].copy (
17+ {"name" : "SF Market Clearing" }
18+ )
1619 cls .inbound_payment_method_line = cls .env ["account.payment.method.line" ].create (
1720 {
1821 "name" : "SF Inbound Payment Method" ,
@@ -21,6 +24,21 @@ def setUpClass(cls):
2124 ].id ,
2225 "payment_type" : "inbound" ,
2326 "journal_id" : cls .bank_journal .id ,
27+ "payment_account_id" : cls .market_account .id ,
28+ }
29+ )
30+ cls .outbound_manual_method = cls .env ["account.payment.method" ].search (
31+ [("code" , "=" , "manual" ), ("payment_type" , "=" , "outbound" )], limit = 1
32+ )
33+ cls .outbound_payment_method_line = cls .env [
34+ "account.payment.method.line"
35+ ].create (
36+ {
37+ "name" : "SF Outbound Payment Method" ,
38+ "payment_method_id" : cls .outbound_manual_method .id ,
39+ "payment_type" : "outbound" ,
40+ "journal_id" : cls .bank_journal .id ,
41+ "payment_account_id" : cls .market_account .id ,
2442 }
2543 )
2644 cls .sf_store = cls .env ["shoppingfeed.store" ].create (
@@ -52,6 +70,26 @@ def _sf_order_line(cls, product=None):
5270 }
5371 )
5472
73+ def _sf_refund (self , sale_order , product = None ):
74+ product = product or self .product_a
75+ return self .env ["account.move" ].create (
76+ {
77+ "move_type" : "out_refund" ,
78+ "partner_id" : sale_order .partner_id .id ,
79+ "invoice_origin" : sale_order .name ,
80+ "invoice_line_ids" : [
81+ Command .create (
82+ {
83+ "product_id" : product .id ,
84+ "quantity" : 1.0 ,
85+ "price_unit" : product .list_price ,
86+ "sale_line_ids" : [Command .set (sale_order .order_line .ids )],
87+ }
88+ )
89+ ],
90+ }
91+ )
92+
5593 def test_partner_gets_payment_method_on_create (self ):
5694 """New partner created during SF import receives
5795 property_inbound_payment_method_line_id from the channel."""
@@ -158,6 +196,38 @@ def test_invoice_not_auto_paid_when_disabled(self):
158196 self .assertNotEqual (invoice .payment_state , "paid" )
159197 self .sf_channel .auto_pay = True
160198
199+ def test_refund_auto_paid_on_channel_account (self ):
200+ self .partner_a .property_inbound_payment_method_line_id = (
201+ self .inbound_payment_method_line
202+ )
203+ sale_order = self .env ["sale.order" ].create (
204+ {
205+ "partner_id" : self .partner_a .id ,
206+ "shoppingfeed_order_ref" : "SF-TEST-REFUND-001" ,
207+ "shoppingfeed_store_id" : self .sf_store .id ,
208+ "shoppingfeed_channel_id" : self .sf_channel .id ,
209+ "order_line" : [self ._sf_order_line ()],
210+ }
211+ )
212+ sale_order .action_confirm ()
213+ self .sf_channel .auto_pay = False
214+ unpaid = self ._sf_refund (sale_order )
215+ unpaid .action_post ()
216+ self .assertNotEqual (unpaid .payment_state , "paid" )
217+ self .sf_channel .auto_pay = True
218+ refund = self ._sf_refund (sale_order )
219+ refund .action_post ()
220+ self .assertEqual (refund .payment_state , "paid" )
221+ payment = refund .reconciled_payment_ids
222+ self .assertEqual (len (payment ), 1 )
223+ self .assertEqual (payment .payment_type , "outbound" )
224+ self .assertEqual (
225+ payment .payment_method_line_id , self .outbound_payment_method_line
226+ )
227+ self .assertEqual (
228+ payment .payment_method_line_id .payment_account_id , self .market_account
229+ )
230+
161231 def test_product_reference_cleaning (self ):
162232 """_shoppingfeed_clean_product_reference strips 2-char country suffixes only."""
163233 so = self .env ["sale.order" ]
0 commit comments