Browse Source

[MIG]account_bank_statement_import_paypal: Migration to 11.0

pull/207/head
cubells 6 years ago
committed by Victor Martin
parent
commit
b21ff6c30c
  1. 88
      account_bank_statement_import_paypal/README.rst
  2. 2
      account_bank_statement_import_paypal/__init__.py
  3. 13
      account_bank_statement_import_paypal/__manifest__.py
  4. 2
      account_bank_statement_import_paypal/models/__init__.py
  5. 40
      account_bank_statement_import_paypal/models/account_bank_statement_import_paypal.py
  6. 12
      account_bank_statement_import_paypal/readme/CONFIGURE.rst
  7. 5
      account_bank_statement_import_paypal/readme/CONTRIBUTORS.rst
  8. 1
      account_bank_statement_import_paypal/readme/DESCRIPTION.rst
  9. 8
      account_bank_statement_import_paypal/readme/USAGE.rst

88
account_bank_statement_import_paypal/README.rst

@ -1,49 +1,105 @@
=============================
Import Paypal Bank Statements Import Paypal Bank Statements
============================= =============================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/OCA/bank-statement-import/tree/11.0/account_bank_statement_import_paypal
:alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-11-0/bank-statement-import-11-0-account_bank_statement_import_paypal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/174/11.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module allows you to import the Paypal CSV files in Odoo as bank statements. This module allows you to import the Paypal CSV files in Odoo as bank statements.
**Table of contents**
.. contents::
:local:
Configuration Configuration
============= =============
In the menu Accounting > Configuration > Accounts > Setup your Bank Accounts, make sure that you have your Paypal bank account with the following parameters:
In the menu Accounting > Configuration > Accounting > Bank Accounts,
make sure that you have your Paypal bank account with the following parameters:
* Bank Account Type: Normal Bank Account * Bank Account Type: Normal Bank Account
* Account Number: the email address associated with your Paypal account * Account Number: the email address associated with your Paypal account
* Account Journal: the journal associated to your Paypal account * Account Journal: the journal associated to your Paypal account
============
TIPS
----
For now only French and English report are supported.
For adding new support you just need to add your header in
model/account_bank_statement_import_paypal.py in the variables HEADERS.
Please help us and do a PR for adding new header ! Thanks
Usage
=====
To use this module, you need to:
Go to Paypal and download your Bank Statement
#. Go to Paypal and download your Bank Statement
.. image:: account_bank_statement_import_paypal/static/description/paypal_backoffice.png .. image:: account_bank_statement_import_paypal/static/description/paypal_backoffice.png
:alt: . :alt: .
.. image:: static/description/paypal_backoffice.png .. image:: static/description/paypal_backoffice.png
:alt: . :alt: .
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_bank_statement_import_paypal%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits Credits
======= =======
Authors
-------
* Akretion
Contributors Contributors
------------
~~~~~~~~~~~~
* Alexis de Lattre <alexis.delattre@akretion.com> * Alexis de Lattre <alexis.delattre@akretion.com>
* Sebastien BEAU <sebastien.beau@akretion.com> * Sebastien BEAU <sebastien.beau@akretion.com>
* Tecnativa (https://www.tecnativa.com)
TIPS
--------
For now only French and English report are supported
For adding new support you just need to add your header in model/account_bank_statement_import_paypal.py in the variables HEADERS.
Please help us and do a PR for adding new header ! Thanks
* Vicent Cubells <vicent.cubells@tecnativa.com>
Maintainer
----------
Maintainers
~~~~~~~~~~~
.. image:: http://odoo-community.org/logo.png
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association :alt: Odoo Community Association
:target: http://odoo-community.org
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
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.
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/11.0/account_bank_statement_import_paypal>`_ project on GitHub.
To contribute to this module, please visit http://odoo-community.org.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

2
account_bank_statement_import_paypal/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import models from . import models

13
account_bank_statement_import_paypal/__manifest__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2017 Akretion (http://www.akretion.com). # Copyright 2014-2017 Akretion (http://www.akretion.com).
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Sébastien BEAU <sebastien.beau@akretion.com> # @author Sébastien BEAU <sebastien.beau@akretion.com>
@ -6,24 +5,14 @@
{ {
"name": "Import Paypal Bank Statements", "name": "Import Paypal Bank Statements",
'summary': 'Import Paypal CSV files as Bank Statements in Odoo', 'summary': 'Import Paypal CSV files as Bank Statements in Odoo',
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"category": "Accounting", "category": "Accounting",
"website": "https://github.com/OCA/bank-statement-import", "website": "https://github.com/OCA/bank-statement-import",
"author": " Akretion, Odoo Community Association (OCA)", "author": " Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"application": False, "application": False,
"installable": True, "installable": True,
"external_dependencies": {
'python': ['unicodecsv'],
"bin": [],
},
"depends": [ "depends": [
"account_bank_statement_import", "account_bank_statement_import",
], ],
"data": [
],
"demo": [
],
"qweb": [
]
} }

2
account_bank_statement_import_paypal/models/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import account_bank_statement_import_paypal from . import account_bank_statement_import_paypal

40
account_bank_statement_import_paypal/models/account_bank_statement_import_paypal.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2017 Akretion (http://www.akretion.com). # Copyright 2014-2017 Akretion (http://www.akretion.com).
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Sébastien BEAU <sebastien.beau@akretion.com> # @author Sébastien BEAU <sebastien.beau@akretion.com>
@ -6,14 +5,14 @@
import logging import logging
from datetime import datetime from datetime import datetime
from openerp import models, fields, api, _
from openerp.exceptions import UserError
from odoo import _, api, fields, models
from odoo.exceptions import UserError
import re import re
from cStringIO import StringIO
from io import StringIO
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
import unicodecsv
import csv
except (ImportError, IOError) as err: except (ImportError, IOError) as err:
_logger.debug(err) _logger.debug(err)
@ -31,7 +30,7 @@ HEADERS = [
'"Date","Time","Time Zone","Description","Currency","Gross ","Fee ","Net",' '"Date","Time","Time Zone","Description","Currency","Gross ","Fee ","Net",'
'"Balance","Transaction ID","From Email Address","Name","Bank Name",' '"Balance","Transaction ID","From Email Address","Name","Bank Name",'
'"Bank Account","Shipping and Handling Amount","Sales Tax","Invoice ID",' '"Bank Account","Shipping and Handling Amount","Sales Tax","Invoice ID",'
'"Reference Txn ID"'
'"Reference Txn ID"',
] ]
@ -40,16 +39,22 @@ class AccountBankStatementImport(models.TransientModel):
@api.model @api.model
def _get_paypal_encoding(self): def _get_paypal_encoding(self):
return 'utf-8'
return 'utf-8-sig'
@api.model
def _get_paypal_str_data(self, data_file):
if not isinstance(data_file, str):
data_file = data_file.decode(self._get_paypal_encoding())
return data_file.strip()
@api.model @api.model
def _get_paypal_date_format(self): def _get_paypal_date_format(self):
'''This method is designed to be inherited'''
""" This method is designed to be inherited """
return '%d/%m/%Y' return '%d/%m/%Y'
@api.model @api.model
def _paypal_convert_amount(self, amount_str): def _paypal_convert_amount(self, amount_str):
'''This method is designed to be inherited'''
""" This method is designed to be inherited """
valstr = re.sub(r'[^\d,.-]', '', amount_str) valstr = re.sub(r'[^\d,.-]', '', amount_str)
valstrdot = valstr.replace('.', '') valstrdot = valstr.replace('.', '')
valstrdot = valstrdot.replace(',', '.') valstrdot = valstrdot.replace(',', '.')
@ -57,6 +62,7 @@ class AccountBankStatementImport(models.TransientModel):
@api.model @api.model
def _check_paypal(self, data_file): def _check_paypal(self, data_file):
data_file = self._get_paypal_str_data(data_file)
for header in HEADERS: for header in HEADERS:
if data_file.strip().startswith(header): if data_file.strip().startswith(header):
return True return True
@ -75,7 +81,7 @@ class AccountBankStatementImport(models.TransientModel):
'transaction_id': line[9], 'transaction_id': line[9],
'email': line[10], 'email': line[10],
'partner_name': line[11], 'partner_name': line[11],
# This two field are usefull for bank transfert
# This two field are useful for bank transfer
'bank_name': line[12], 'bank_name': line[12],
'bank_account': line[13], 'bank_account': line[13],
'invoice_number': line[16], 'invoice_number': line[16],
@ -86,7 +92,7 @@ class AccountBankStatementImport(models.TransientModel):
_logger.debug('Trying to convert %s to float' % rline[field]) _logger.debug('Trying to convert %s to float' % rline[field])
try: try:
rline[field] = self._paypal_convert_amount(rline[field]) rline[field] = self._paypal_convert_amount(rline[field])
except:
except Exception:
raise UserError( raise UserError(
_("Value '%s' for the field '%s' on line %d, " _("Value '%s' for the field '%s' on line %d, "
"cannot be converted to float") "cannot be converted to float")
@ -94,12 +100,12 @@ class AccountBankStatementImport(models.TransientModel):
return rline return rline
def _parse_paypal_file(self, data_file): def _parse_paypal_file(self, data_file):
f = StringIO()
f.write(data_file)
data_file = self._get_paypal_str_data(data_file)
f = StringIO(data_file)
f.seek(0) f.seek(0)
raw_lines = [] raw_lines = []
reader = unicodecsv.reader(f, encoding=self._get_paypal_encoding())
reader.next() # Drop header
reader = csv.reader(f)
next(reader) # Drop header
for idx, line in enumerate(reader): for idx, line in enumerate(reader):
_logger.debug("Line %d: %s" % (idx, line)) _logger.debug("Line %d: %s" % (idx, line))
raw_lines.append(self._convert_paypal_line_to_dict(idx, line)) raw_lines.append(self._convert_paypal_line_to_dict(idx, line))
@ -188,7 +194,7 @@ class AccountBankStatementImport(models.TransientModel):
@api.model @api.model
def _parse_file(self, data_file): def _parse_file(self, data_file):
""" Import a file in Paypal CSV format"""
""" Import a file in Paypal CSV format """
paypal = self._check_paypal(data_file) paypal = self._check_paypal(data_file)
if not paypal: if not paypal:
return super(AccountBankStatementImport, self)._parse_file( return super(AccountBankStatementImport, self)._parse_file(
@ -265,7 +271,7 @@ class AccountBankStatementImport(models.TransientModel):
@api.model @api.model
def _complete_statement(self, stmts_vals, journal_id, account_number): def _complete_statement(self, stmts_vals, journal_id, account_number):
'''Match the partner from paypal information'''
""" Match the partner from paypal information """
stmts_vals = super(AccountBankStatementImport, self).\ stmts_vals = super(AccountBankStatementImport, self).\
_complete_statement(stmts_vals, journal_id, account_number) _complete_statement(stmts_vals, journal_id, account_number)
for line in stmts_vals['transactions']: for line in stmts_vals['transactions']:

12
account_bank_statement_import_paypal/readme/CONFIGURE.rst

@ -0,0 +1,12 @@
In the menu Accounting > Configuration > Accounting > Bank Accounts,
make sure that you have your Paypal bank account with the following parameters:
* Bank Account Type: Normal Bank Account
* Account Number: the email address associated with your Paypal account
* Account Journal: the journal associated to your Paypal account
TIPS
----
For now only French and English report are supported.
For adding new support you just need to add your header in
model/account_bank_statement_import_paypal.py in the variables HEADERS.
Please help us and do a PR for adding new header ! Thanks

5
account_bank_statement_import_paypal/readme/CONTRIBUTORS.rst

@ -0,0 +1,5 @@
* Alexis de Lattre <alexis.delattre@akretion.com>
* Sebastien BEAU <sebastien.beau@akretion.com>
* Tecnativa (https://www.tecnativa.com)
* Vicent Cubells <vicent.cubells@tecnativa.com>

1
account_bank_statement_import_paypal/readme/DESCRIPTION.rst

@ -0,0 +1 @@
This module allows you to import the Paypal CSV files in Odoo as bank statements.

8
account_bank_statement_import_paypal/readme/USAGE.rst

@ -0,0 +1,8 @@
To use this module, you need to:
#. Go to Paypal and download your Bank Statement
.. image:: account_bank_statement_import_paypal/static/description/paypal_backoffice.png
:alt: .
.. image:: static/description/paypal_backoffice.png
:alt: .
Loading…
Cancel
Save