diff --git a/account_statement_import_online/models/online_bank_statement_provider.py b/account_statement_import_online/models/online_bank_statement_provider.py index 37f6130460..18457a58d2 100644 --- a/account_statement_import_online/models/online_bank_statement_provider.py +++ b/account_statement_import_online/models/online_bank_statement_provider.py @@ -29,7 +29,6 @@ class OnlineBankStatementProvider(models.Model): journal_id = fields.Many2one( comodel_name="account.journal", required=True, - readonly=True, ondelete="cascade", domain=[("type", "=", "bank")], ) @@ -49,7 +48,6 @@ class OnlineBankStatementProvider(models.Model): service = fields.Selection( selection=lambda self: self._selection_service(), required=True, - readonly=True, ) interval_type = fields.Selection( selection=[ diff --git a/account_statement_import_online_ponto/__manifest__.py b/account_statement_import_online_ponto/__manifest__.py index ea938f9813..0e400569f9 100644 --- a/account_statement_import_online_ponto/__manifest__.py +++ b/account_statement_import_online_ponto/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Online Bank Statements: MyPonto.com", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Account", "website": "https://github.com/OCA/bank-statement-import", "author": "Florent de Labarre, Therp BV, Odoo Community Association (OCA)", diff --git a/account_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py b/account_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py index fe2472141f..8007c4b75b 100644 --- a/account_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py +++ b/account_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py @@ -23,7 +23,6 @@ class OnlineBankStatementProvider(models.Model): ("execution_date", "Execution Date"), ("value_date", "Value Date"), ], - string="Ponto Date Field", default="execution_date", help="Select the Ponto date field that will be used for " "the Odoo bank statement line date. If you change this parameter " @@ -50,6 +49,7 @@ def _pull(self, date_since, date_until): stop retrieving when either we get before date_since or there is no more data available. """ + # pylint: disable=missing-return ponto_providers = self.filtered(lambda provider: provider.service == "ponto") super(OnlineBankStatementProvider, self - ponto_providers)._pull( date_since, date_until @@ -63,10 +63,13 @@ def _ponto_pull(self, date_since, date_until): is_scheduled = self.env.context.get("scheduled") if is_scheduled: _logger.debug( - _("Ponto obtain statement data for journal %s from %s to %s"), - self.journal_id.name, - date_since, - date_until, + _( + "Ponto obtain statement data for journal {journal}" + " from {date_since} to {date_until}" + ), + journal=self.journal_id.name, + date_since=date_since, + date_until=date_until, ) else: _logger.debug( @@ -74,10 +77,13 @@ def _ponto_pull(self, date_since, date_until): self.journal_id.name, ) lines = self._ponto_retrieve_data(date_since, date_until) - # For scheduled runs, store latest identifier. - if is_scheduled and lines: - self.ponto_last_identifier = lines[0].get("id") - self._ponto_store_lines(lines) + if not lines: + _logger.info(_("No lines were retrieved from Ponto")) + else: + # For scheduled runs, store latest identifier. + if is_scheduled: + self.ponto_last_identifier = lines[0].get("id") + self._ponto_store_lines(lines) def _ponto_retrieve_data(self, date_since, date_until): """Fill buffer with data from Ponto. diff --git a/account_statement_import_online_ponto/models/ponto_interface.py b/account_statement_import_online_ponto/models/ponto_interface.py index f116d6aff1..28fb7890bb 100644 --- a/account_statement_import_online_ponto/models/ponto_interface.py +++ b/account_statement_import_online_ponto/models/ponto_interface.py @@ -28,14 +28,14 @@ def _login(self, username, password): url = PONTO_ENDPOINT + "/oauth2/token" if not (username and password): raise UserError(_("Please fill login and key.")) - login = "%s:%s" % (username, password) + login = ":".join([username, password]) login = base64.b64encode(login.encode("UTF-8")).decode("UTF-8") login_headers = { "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json", - "Authorization": "Basic %s" % login, + "Authorization": "Basic {login}".format(login=login), } - _logger.debug(_("POST request on %s"), url) + _logger.debug(_("POST request on {url}"), url=url) response = requests.post( url, params={"grant_type": "client_credentials"}, @@ -63,13 +63,15 @@ def _get_request_headers(self, access_data): access_data.update(updated_data) return { "Accept": "application/json", - "Authorization": "Bearer %s" % access_data["access_token"], + "Authorization": "Bearer {access_token}".format( + access_token=access_data["access_token"] + ), } def _set_access_account(self, access_data, account_number): """Set ponto account for bank account in access_data.""" url = PONTO_ENDPOINT + "/accounts" - _logger.debug(_("GET request on %s"), url) + _logger.debug(_("GET request on {}"), url) response = requests.get( url, params={"limit": 100}, @@ -86,8 +88,9 @@ def _set_access_account(self, access_data, account_number): return # If we get here, we did not find Ponto account for bank account. raise UserError( - _("Ponto : wrong configuration, account %s not found in %s") - % (account_number, data) + _( + "Ponto : wrong configuration, account {account} not found in {data}" + ).format(account=account_number, data=data) ) def _get_transactions(self, access_data, last_identifier): @@ -116,7 +119,7 @@ def _get_transactions_from_data(self, data): transactions = data.get("data", []) if not transactions: _logger.debug( - _("No transactions where found in data %s"), + _("No transactions where found in data {}"), data, ) else: @@ -130,7 +133,10 @@ def _get_request(self, access_data, url, params): """Interact with Ponto to get next page of data.""" headers = self._get_request_headers(access_data) _logger.debug( - _("GET request to %s with headers %s and params %s"), url, params, headers + _("GET request to {url} with headers {headers} and params {params}"), + url=url, + headers=headers, + params=params, ) response = requests.get( url, @@ -142,10 +148,17 @@ def _get_request(self, access_data, url, params): def _get_response_data(self, response): """Get response data for GET or POST request.""" - _logger.debug(_("HTTP answer code %s from Ponto"), response.status_code) + _logger.debug( + _("HTTP answer code {response_code} from Ponto"), + response_code=response.status_code, + ) if response.status_code not in (200, 201): raise UserError( - _("Server returned status code %s: %s") - % (response.status_code, response.text) + _( + "Server returned status code {response_code}: {response_text}" + ).format( + response_code=response.status_code, + response_text=response.text, + ) ) return json.loads(response.text) diff --git a/account_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py b/account_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py index 5fd8f7ca89..89c9298731 100644 --- a/account_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py +++ b/account_statement_import_online_ponto/tests/test_account_statement_import_online_ponto.py @@ -152,13 +152,18 @@ def setUp(self): "code": "BANK", "currency_id": self.currency_eur.id, "bank_statements_source": "online", - "online_bank_statement_provider": "ponto", "bank_account_id": self.bank_account.id, } ) - self.provider = self.journal.online_bank_statement_provider_id - # To get all the moves in a month at once - self.provider.statement_creation_mode = "monthly" + self.provider = self.OnlineBankStatementProvider.create( + { + "name": "Ponto Provider", + "service": "ponto", + "journal_id": self.journal.id, + # To get all the moves in a month at once + "statement_creation_mode": "monthly", + } + ) self.mock_login = lambda: mock.patch( _interface_class + "._login", diff --git a/setup/account_statement_import_online_ponto/odoo/addons/account_statement_import_online_ponto b/setup/account_statement_import_online_ponto/odoo/addons/account_statement_import_online_ponto new file mode 120000 index 0000000000..efde64a7f7 --- /dev/null +++ b/setup/account_statement_import_online_ponto/odoo/addons/account_statement_import_online_ponto @@ -0,0 +1 @@ +../../../../account_statement_import_online_ponto \ No newline at end of file diff --git a/setup/account_statement_import_online_ponto/setup.py b/setup/account_statement_import_online_ponto/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/account_statement_import_online_ponto/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)