Skip to content

Commit

Permalink
[FIX]account_payment_plaid: Error with sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed Jul 21, 2024
1 parent 5ac2894 commit e28bd5e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
35 changes: 33 additions & 2 deletions account_payment_plaid/models/plaid_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
import datetime

from odoo import _, models
from odoo.exceptions import ValidationError
Expand Down Expand Up @@ -33,6 +34,13 @@
from plaid.model.transfer_failure import TransferFailure
from plaid.model.transfer_network import TransferNetwork
from plaid.model.transfer_type import TransferType
from plaid.model.transfer_get_request import TransferGetRequest

from plaid.model.transfer_event_list_transfer_type import (
TransferEventListTransferType,
)
from plaid.model.transfer_event_type import TransferEventType

except (ImportError, IOError) as err:
_logger.debug(err)

Check warning on line 45 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L44-L45

Added lines #L44 - L45 were not covered by tests

Expand Down Expand Up @@ -130,14 +138,37 @@ def _transfer(
return response.to_dict()["transfer"]

def _sync_transfer_events(self, client):
request = TransferEventSyncRequest(after_id=4, count=25)
request = TransferEventSyncRequest(after_id=0, count=25)
events = []
try:
response = client.transfer_event_sync(request)
events.extend(response.to_dict()["transfer_events"])
except plaid.ApiException as e:
raise ValidationError(
_("Error syncing transfer events: %s") % e.body
) from e
return response.to_dict()["transfer_events"]

has_more = response.to_dict().get("has_more", False)
while has_more:
request = TransferEventSyncRequest(after_id=len(events), count=25)
try:
response = client.transfer_event_sync(request)
has_more = response.to_dict().get("has_more", False)
except plaid.ApiException as e:
raise ValidationError(

Check warning on line 158 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L153-L158

Added lines #L153 - L158 were not covered by tests
_("Error syncing transfer events: %s") % e.body
) from e
events.extend(response.to_dict()["transfer_events"])

Check warning on line 161 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L161

Added line #L161 was not covered by tests
return events

def _get_transfer(self, client, transfer_id):
request = TransferGetRequest(transfer_id=transfer_id)

Check warning on line 165 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L165

Added line #L165 was not covered by tests

try:
response = client.transfer_get(request)
except plaid.ApiException as e:
raise ValidationError(_("Error getting transfer: %s") % e.body) from e
return response.to_dict()

Check warning on line 171 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L167-L171

Added lines #L167 - L171 were not covered by tests

############################
# Sandbox Transfer Methods #
Expand Down
2 changes: 2 additions & 0 deletions account_payment_plaid/models/plaid_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PlaidTransfer(models.Model):
host = fields.Selection(related="company_id.plaid_host", string="Host")
ref = fields.Char(string="Reference")
account_move_id = fields.Many2one("account.move", string="Account Move")
html_body = fields.Html(string=_("HTML Body"))

def action_sandbox_simulation(self):
return {
Expand Down Expand Up @@ -71,6 +72,7 @@ def cron_sync_transfer_events(self):
transfer_ids = self.search(
[("name", "in", events), ("state", "!=", "settled")]
)

if transfer_ids:
transfer_ids.write({"state": event_type})
if event_type == "settled":
Expand Down
1 change: 0 additions & 1 deletion account_payment_plaid/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ResCompany(models.Model):
("sand", _("Sandbox")),
("prod", _("Production")),
],
default="sand",
)
plaid_access_token = fields.Char(string="Access Token")

Expand Down
4 changes: 0 additions & 4 deletions account_payment_plaid/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@ class ResConfigSettings(models.TransientModel):
readonly=False,
related="company_id.plaid_client_id",
string="Client ID",
config_parameter="plaid_connector.plaid_client_id",
)

plaid_secret = fields.Char(
string="Secret",
readonly=False,
related="company_id.plaid_secret",
config_parameter="plaid_connector.plaid_secret",
)
plaid_host = fields.Selection(
string="Host",
readonly=False,
default="sand",
related="company_id.plaid_host",
config_parameter="plaid_connector.plaid_host",
)

plaid_access_token = fields.Char(
Expand Down
7 changes: 6 additions & 1 deletion account_payment_plaid/views/plaid_transfer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<field name="create_date" readonly="1" />
</group>
</group>
<notebook>
<page name="html_body" string="Body">
<field name="html_body"/>
</page>
</notebook>
</sheet>
</form>
</field>
Expand All @@ -64,4 +69,4 @@
sequence="10"
/>
</data>
</odoo>
</odoo>

0 comments on commit e28bd5e

Please sign in to comment.