[IMP] pos_adyen: adapt to Odoo Payments changes
- Dropped adyen.payout model - Show pos.payment on adyen.transaction TaskID: 2129218 Closes odoo/odoo#68952 Related: odoo/upgrade#2501 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/adyen_account_views.xml',
|
||||
'views/adyen_transaction_views.xml',
|
||||
'views/pos_config_views.xml',
|
||||
'views/pos_payment_method_views.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import adyen_account
|
||||
from . import adyen_transaction
|
||||
from . import pos_config
|
||||
from . import pos_payment_method
|
||||
from . import res_config_settings
|
||||
|
||||
@@ -46,13 +46,12 @@ class AdyenStore(models.Model):
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
adyen_store_id = super(AdyenStore, self).create(values)
|
||||
response = adyen_store_id.adyen_account_id._adyen_rpc('v1/create_store', adyen_store_id._format_data())
|
||||
adyen_account_id = self.env['adyen.account'].browse(values.get('adyen_account_id'))
|
||||
response = adyen_account_id._adyen_rpc('v1/create_store', self._format_data(values))
|
||||
stores = response['accountHolderDetails']['storeDetails']
|
||||
created_store = next(store for store in stores if store['storeReference'] == adyen_store_id.store_reference)
|
||||
adyen_store_id.with_context(update_from_adyen=True).sudo().write({
|
||||
'store_uuid': created_store['store'],
|
||||
})
|
||||
created_store = next(store for store in stores if store['storeReference'] == values.get('store_reference'))
|
||||
values['store_uuid'] = created_store['store']
|
||||
adyen_store_id = super(AdyenStore, self).create(values)
|
||||
return adyen_store_id
|
||||
|
||||
def unlink(self):
|
||||
@@ -63,23 +62,26 @@ class AdyenStore(models.Model):
|
||||
})
|
||||
return super(AdyenStore, self).unlink()
|
||||
|
||||
def _format_data(self):
|
||||
def _format_data(self, values):
|
||||
adyen_account_id = self.env['adyen.account'].browse(values.get('adyen_account_id')) if values.get('adyen_account_id') else self.adyen_account_id
|
||||
country_id = self.env['res.country'].browse(values.get('country_id')) if values.get('country_id') else self.country_id
|
||||
state_id = self.env['res.country.state'].browse(values.get('state_id')) if values.get('state_id') else self.state_id
|
||||
return {
|
||||
'accountHolderCode': self.adyen_account_id.account_holder_code,
|
||||
'accountHolderCode': adyen_account_id.account_holder_code,
|
||||
'accountHolderDetails': {
|
||||
'storeDetails': [{
|
||||
'storeReference': self.store_reference,
|
||||
'storeName': self.name,
|
||||
'storeReference': values.get('store_reference') or self.store_reference,
|
||||
'storeName': values.get('name') or self.name,
|
||||
'merchantCategoryCode': '7999',
|
||||
'address': {
|
||||
'city': self.city,
|
||||
'country': self.country_id.code,
|
||||
'houseNumberOrName': self.house_number_or_name,
|
||||
'postalCode': self.zip,
|
||||
'stateOrProvince': self.state_id.code or None,
|
||||
'street': self.street,
|
||||
'city': values.get('city') or self.city,
|
||||
'country': country_id.code,
|
||||
'houseNumberOrName': values.get('house_number_or_name') or self.house_number_or_name,
|
||||
'postalCode': values.get('zip') or self.zip,
|
||||
'stateOrProvince': state_id.code or None,
|
||||
'street': values.get('street') or self.street,
|
||||
},
|
||||
'fullPhoneNumber': self.phone_number,
|
||||
'fullPhoneNumber': values.get('phone_number') or self.phone_number,
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AdyenTransaction(models.Model):
|
||||
_inherit = 'adyen.transaction'
|
||||
|
||||
pos_payment_id = fields.Many2one('pos.payment', string='POS Order')
|
||||
pos_order_id = fields.Many2one(related='pos_payment_id.pos_order_id')
|
||||
|
||||
def _post_transaction_sync(self):
|
||||
to_match = self.filtered(lambda t: not t.pos_payment_id)
|
||||
pos_payment_ids = self.env['pos.payment'].search([('transaction_id', 'in', to_match.mapped('reference'))])
|
||||
|
||||
for tx in to_match:
|
||||
tx.pos_payment_id = pos_payment_ids.filtered(lambda t: t.transaction_id == tx.reference)
|
||||
@@ -26,7 +26,6 @@ class PosPaymentMethod(models.Model):
|
||||
|
||||
# Odoo Payments by Adyen
|
||||
adyen_account_id = fields.Many2one('adyen.account', related='company_id.adyen_account_id')
|
||||
adyen_payout_id = fields.Many2one('adyen.payout', string='Adyen Payout', domain="[('adyen_account_id', '=', adyen_account_id)]")
|
||||
adyen_terminal_id = fields.Many2one('adyen.terminal', string='Adyen Terminal', domain="[('adyen_account_id', '=', adyen_account_id)]")
|
||||
|
||||
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 @@ class PosPaymentMethod(models.Model):
|
||||
company_sudo = self.env.company.sudo()
|
||||
return company_sudo.adyen_account_id._adyen_rpc('v1/%s' % operation, {
|
||||
'request_data': data,
|
||||
'account_code': self.sudo().adyen_payout_id.code,
|
||||
'account_code': self.sudo().adyen_account_id.account_code,
|
||||
'notification_url': company_sudo.get_base_url(),
|
||||
})
|
||||
except Forbidden:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_adyen_store_group_erp_manager,adyen.store,model_adyen_store,base.group_erp_manager,1,0,1,1
|
||||
access_adyen_payout_group_pos_manager,adyen.payout,adyen_platforms.model_adyen_payout,point_of_sale.group_pos_manager,1,0,0,0
|
||||
access_adyen_terminal_group_pos_manager,adyen.terminal,model_adyen_terminal,point_of_sale.group_pos_manager,1,0,0,0
|
||||
|
||||
|
@@ -21,7 +21,6 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="adyen_store_view_form" model="ir.ui.view">
|
||||
<field name="name">adyen.store.view.form</field>
|
||||
<field name="model">adyen.store</field>
|
||||
@@ -29,6 +28,7 @@
|
||||
<form string="Adyen Store">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="store_reference" invisible="1" />
|
||||
<field name="store_uuid" attrs="{'invisible': [('id', '=', False)]}"/>
|
||||
<field name="name" attrs="{'readonly': [('id', '!=', False)]}"/>
|
||||
<field name="phone_number" attrs="{'readonly': [('id', '!=', False)]}"/>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="adyen_transaction_view_form" model="ir.ui.view">
|
||||
<field name="model">adyen.transaction</field>
|
||||
<field name="inherit_id" ref="adyen_platforms.adyen_transaction_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='description']" position="after">
|
||||
<field name="pos_order_id" attrs="{'invisible': [('pos_order_id', '=', False)]}" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="adyen_transaction_view_list" model="ir.ui.view">
|
||||
<field name="model">adyen.transaction</field>
|
||||
<field name="inherit_id" ref="adyen_platforms.adyen_transaction_view_list"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='description']" position="after">
|
||||
<field name="pos_order_id" optional="show" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -14,7 +14,6 @@
|
||||
<!-- Odoo Payments by Adyen -->
|
||||
<field name="adyen_account_id" invisible="1"/>
|
||||
<field name="adyen_terminal_id" attrs="{'invisible': [('use_payment_terminal', '!=', 'odoo_adyen')], 'required': [('use_payment_terminal', '=', 'odoo_adyen')]}"/>
|
||||
<field name="adyen_payout_id" attrs="{'invisible': [('use_payment_terminal', '!=', 'odoo_adyen')], 'required': [('use_payment_terminal', '=', 'odoo_adyen')]}" options="{'no_create': True}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user