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 4ce5483
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
30 changes: 28 additions & 2 deletions account_payment_plaid/models/plaid_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
from plaid.model.transfer_create_request import TransferCreateRequest
from plaid.model.transfer_event_sync_request import TransferEventSyncRequest
from plaid.model.transfer_failure import TransferFailure
from plaid.model.transfer_get_request import TransferGetRequest
from plaid.model.transfer_network import TransferNetwork
from plaid.model.transfer_type import TransferType


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

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

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L39-L40

Added lines #L39 - L40 were not covered by tests

Expand Down Expand Up @@ -130,14 +133,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 153 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L148-L153

Added lines #L148 - L153 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 156 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L156

Added line #L156 was not covered by tests
return events

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

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

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L160

Added line #L160 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 166 in account_payment_plaid/models/plaid_interface.py

View check run for this annotation

Codecov / codecov/patch

account_payment_plaid/models/plaid_interface.py#L162-L166

Added lines #L162 - L166 were not covered by tests

############################
# Sandbox Transfer Methods #
Expand Down
1 change: 1 addition & 0 deletions account_payment_plaid/models/plaid_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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
11 changes: 7 additions & 4 deletions account_payment_plaid/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -440,7 +441,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down

0 comments on commit 4ce5483

Please sign in to comment.