Skip to content

Commit 01cefd0

Browse files
author
Kevin Baptiste
committed
[IMP] pos_adyen: adapt to Odoo Payments changes
- Dropped adyen.payout model - Show pos.payment on adyen.transaction TaskID: 2129218 Closes odoo#68952 Related: odoo/upgrade#2501 Signed-off-by: Kevin Baptiste <kba@odoo.com>
1 parent 208a82f commit 01cefd0

File tree

9 files changed

+63
-22
lines changed

9 files changed

+63
-22
lines changed

addons/pos_adyen/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'data': [
1111
'security/ir.model.access.csv',
1212
'views/adyen_account_views.xml',
13+
'views/adyen_transaction_views.xml',
1314
'views/pos_config_views.xml',
1415
'views/pos_payment_method_views.xml',
1516
'views/res_config_settings_views.xml',

addons/pos_adyen/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33

44
from . import adyen_account
5+
from . import adyen_transaction
56
from . import pos_config
67
from . import pos_payment_method
78
from . import res_config_settings

addons/pos_adyen/models/adyen_account.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
3+
4+
from odoo import fields, models
5+
6+
7+
class AdyenTransaction(models.Model):
8+
_inherit = 'adyen.transaction'
9+
10+
pos_payment_id = fields.Many2one('pos.payment', string='POS Order')
11+
pos_order_id = fields.Many2one(related='pos_payment_id.pos_order_id')
12+
13+
def _post_transaction_sync(self):
14+
to_match = self.filtered(lambda t: not t.pos_payment_id)
15+
pos_payment_ids = self.env['pos.payment'].search([('transaction_id', 'in', to_match.mapped('reference'))])
16+
17+
for tx in to_match:
18+
tx.pos_payment_id = pos_payment_ids.filtered(lambda t: t.transaction_id == tx.reference)

addons/pos_adyen/models/pos_payment_method.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def _get_payment_terminal_selection(self):
2626

2727
# Odoo Payments by Adyen
2828
adyen_account_id = fields.Many2one('adyen.account', related='company_id.adyen_account_id')
29-
adyen_payout_id = fields.Many2one('adyen.payout', string='Adyen Payout', domain="[('adyen_account_id', '=', adyen_account_id)]")
3029
adyen_terminal_id = fields.Many2one('adyen.terminal', string='Adyen Terminal', domain="[('adyen_account_id', '=', adyen_account_id)]")
3130

3231
adyen_latest_response = fields.Char(help='Technical field used to buffer the latest asynchronous notification from Adyen.', copy=False, groups='base.group_erp_manager')
@@ -138,7 +137,7 @@ def _proxy_adyen_request_odoo_proxy(self, data, operation):
138137
company_sudo = self.env.company.sudo()
139138
return company_sudo.adyen_account_id._adyen_rpc('v1/%s' % operation, {
140139
'request_data': data,
141-
'account_code': self.sudo().adyen_payout_id.code,
140+
'account_code': self.sudo().adyen_account_id.account_code,
142141
'notification_url': company_sudo.get_base_url(),
143142
})
144143
except Forbidden:
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
22
access_adyen_store_group_erp_manager,adyen.store,model_adyen_store,base.group_erp_manager,1,0,1,1
3-
access_adyen_payout_group_pos_manager,adyen.payout,adyen_platforms.model_adyen_payout,point_of_sale.group_pos_manager,1,0,0,0
43
access_adyen_terminal_group_pos_manager,adyen.terminal,model_adyen_terminal,point_of_sale.group_pos_manager,1,0,0,0

addons/pos_adyen/views/adyen_account_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
</field>
2222
</record>
2323

24-
2524
<record id="adyen_store_view_form" model="ir.ui.view">
2625
<field name="name">adyen.store.view.form</field>
2726
<field name="model">adyen.store</field>
2827
<field name="arch" type="xml">
2928
<form string="Adyen Store">
3029
<sheet>
3130
<group>
31+
<field name="store_reference" invisible="1" />
3232
<field name="store_uuid" attrs="{'invisible': [('id', '=', False)]}"/>
3333
<field name="name" attrs="{'readonly': [('id', '!=', False)]}"/>
3434
<field name="phone_number" attrs="{'readonly': [('id', '!=', False)]}"/>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<record id="adyen_transaction_view_form" model="ir.ui.view">
4+
<field name="model">adyen.transaction</field>
5+
<field name="inherit_id" ref="adyen_platforms.adyen_transaction_view_form"/>
6+
<field name="arch" type="xml">
7+
<xpath expr="//field[@name='description']" position="after">
8+
<field name="pos_order_id" attrs="{'invisible': [('pos_order_id', '=', False)]}" />
9+
</xpath>
10+
</field>
11+
</record>
12+
13+
<record id="adyen_transaction_view_list" model="ir.ui.view">
14+
<field name="model">adyen.transaction</field>
15+
<field name="inherit_id" ref="adyen_platforms.adyen_transaction_view_list"/>
16+
<field name="arch" type="xml">
17+
<xpath expr="//field[@name='description']" position="after">
18+
<field name="pos_order_id" optional="show" />
19+
</xpath>
20+
</field>
21+
</record>
22+
</odoo>

addons/pos_adyen/views/pos_payment_method_views.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<!-- Odoo Payments by Adyen -->
1515
<field name="adyen_account_id" invisible="1"/>
1616
<field name="adyen_terminal_id" attrs="{'invisible': [('use_payment_terminal', '!=', 'odoo_adyen')], 'required': [('use_payment_terminal', '=', 'odoo_adyen')]}"/>
17-
<field name="adyen_payout_id" attrs="{'invisible': [('use_payment_terminal', '!=', 'odoo_adyen')], 'required': [('use_payment_terminal', '=', 'odoo_adyen')]}" options="{'no_create': True}"/>
1817
</xpath>
1918
</field>
2019
</record>

0 commit comments

Comments
 (0)