@@ -46,13 +46,12 @@ class AdyenStore(models.Model):
4646
4747 @api .model
4848 def create (self , values ):
49- adyen_store_id = super ( AdyenStore , self ). create (values )
50- response = adyen_store_id . adyen_account_id ._adyen_rpc ('v1/create_store' , adyen_store_id ._format_data ())
49+ adyen_account_id = self . env [ 'adyen.account' ]. browse (values . get ( 'adyen_account_id' ) )
50+ response = adyen_account_id ._adyen_rpc ('v1/create_store' , self ._format_data (values ))
5151 stores = response ['accountHolderDetails' ]['storeDetails' ]
52- created_store = next (store for store in stores if store ['storeReference' ] == adyen_store_id .store_reference )
53- adyen_store_id .with_context (update_from_adyen = True ).sudo ().write ({
54- 'store_uuid' : created_store ['store' ],
55- })
52+ created_store = next (store for store in stores if store ['storeReference' ] == values .get ('store_reference' ))
53+ values ['store_uuid' ] = created_store ['store' ]
54+ adyen_store_id = super (AdyenStore , self ).create (values )
5655 return adyen_store_id
5756
5857 def unlink (self ):
@@ -63,23 +62,26 @@ def unlink(self):
6362 })
6463 return super (AdyenStore , self ).unlink ()
6564
66- def _format_data (self ):
65+ def _format_data (self , values ):
66+ adyen_account_id = self .env ['adyen.account' ].browse (values .get ('adyen_account_id' )) if values .get ('adyen_account_id' ) else self .adyen_account_id
67+ country_id = self .env ['res.country' ].browse (values .get ('country_id' )) if values .get ('country_id' ) else self .country_id
68+ state_id = self .env ['res.country.state' ].browse (values .get ('state_id' )) if values .get ('state_id' ) else self .state_id
6769 return {
68- 'accountHolderCode' : self . adyen_account_id .account_holder_code ,
70+ 'accountHolderCode' : adyen_account_id .account_holder_code ,
6971 'accountHolderDetails' : {
7072 'storeDetails' : [{
71- 'storeReference' : self .store_reference ,
72- 'storeName' : self .name ,
73+ 'storeReference' : values . get ( 'store_reference' ) or self .store_reference ,
74+ 'storeName' : values . get ( 'name' ) or self .name ,
7375 'merchantCategoryCode' : '7999' ,
7476 'address' : {
75- 'city' : self .city ,
76- 'country' : self . country_id .code ,
77- 'houseNumberOrName' : self .house_number_or_name ,
78- 'postalCode' : self .zip ,
79- 'stateOrProvince' : self . state_id .code or None ,
80- 'street' : self .street ,
77+ 'city' : values . get ( 'city' ) or self .city ,
78+ 'country' : country_id .code ,
79+ 'houseNumberOrName' : values . get ( 'house_number_or_name' ) or self .house_number_or_name ,
80+ 'postalCode' : values . get ( 'zip' ) or self .zip ,
81+ 'stateOrProvince' : state_id .code or None ,
82+ 'street' : values . get ( 'street' ) or self .street ,
8183 },
82- 'fullPhoneNumber' : self .phone_number ,
84+ 'fullPhoneNumber' : values . get ( 'phone_number' ) or self .phone_number ,
8385 }],
8486 }
8587 }
0 commit comments