[MIG]account_statement_import_paypal: Migration to 15.0

This commit is contained in:
manu
2023-01-16 18:53:49 +01:00
parent e16e9a5bd2
commit 6304b0a2b1
6 changed files with 25 additions and 42 deletions

View File

@@ -7,7 +7,7 @@
{ {
"name": "PayPal CSV Format Bank Statements Import", "name": "PayPal CSV Format Bank Statements Import",
"summary": "Import PayPal CSV files as Bank Statements in Odoo", "summary": "Import PayPal CSV files as Bank Statements in Odoo",
"version": "14.0.1.0.0", "version": "15.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, CorporateHub, Odoo Community Association (OCA)", "author": "Akretion, CorporateHub, Odoo Community Association (OCA)",

View File

@@ -23,6 +23,9 @@ class AccountStatementImport(models.TransientModel):
self.ensure_one() self.ensure_one()
try: try:
Parser = self.env["account.statement.import.paypal.parser"] Parser = self.env["account.statement.import.paypal.parser"]
logging.warning(
Parser.parse(self.paypal_mapping_id, data_file, self.statement_filename)
)
return Parser.parse( return Parser.parse(
self.paypal_mapping_id, data_file, self.statement_filename self.paypal_mapping_id, data_file, self.statement_filename
) )

View File

@@ -26,11 +26,9 @@ class AccountBankStatementImportPayPalMapping(models.Model):
required=True, required=True,
) )
date_format = fields.Char( date_format = fields.Char(
string="Date Format",
required=True, required=True,
) )
time_format = fields.Char( time_format = fields.Char(
string="Time Format",
required=True, required=True,
) )
date_column = fields.Char( date_column = fields.Char(

View File

@@ -38,10 +38,10 @@ class AccountBankStatementImportPayPalParser(models.TransientModel):
currency_code = (journal.currency_id or journal.company_id.currency_id).name currency_code = (journal.currency_id or journal.company_id.currency_id).name
account_number = journal.bank_account_id.acc_number account_number = journal.bank_account_id.acc_number
name = _("%s: %s") % ( name = _("%(code)s: %(path)s") % {
journal.code, "code": journal.code,
path.basename(filename), "path": path.basename(filename),
) }
lines = self._parse_lines(mapping, data_file, currency_code) lines = self._parse_lines(mapping, data_file, currency_code)
if not lines: if not lines:
return currency_code, account_number, [{"name": name, "transactions": []}] return currency_code, account_number, [{"name": name, "transactions": []}]

View File

@@ -7,3 +7,4 @@
* Carlos Roca * Carlos Roca
* Alexey Pelykh <alexey.pelykh@corphub.eu> (`CorporateHub <https://corporatehub.eu/>`__) * Alexey Pelykh <alexey.pelykh@corphub.eu> (`CorporateHub <https://corporatehub.eu/>`__)
* Manuel Regidor <manuel.regidor@sygel.es>

View File

@@ -36,6 +36,7 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
self.AccountStatementImportPayPalMappingWizard = self.env[ self.AccountStatementImportPayPalMappingWizard = self.env[
"account.statement.import.paypal.mapping.wizard" "account.statement.import.paypal.mapping.wizard"
] ]
self.env.ref("base.EUR").write({"active": True})
def _data_file(self, filename): def _data_file(self, filename):
with open(path.join(path.dirname(__file__), filename)) as file: with open(path.join(path.dirname(__file__), filename)) as file:
@@ -50,9 +51,7 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
"currency_id": self.currency_usd.id, "currency_id": self.currency_usd.id,
} }
) )
wizard = self.AccountStatementImport.with_context( wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
{"journal_id": journal.id}
).create(
{ {
"statement_filename": "fixtures/statement_en.csv", "statement_filename": "fixtures/statement_en.csv",
"statement_file": self._data_file("fixtures/statement_en.csv"), "statement_file": self._data_file("fixtures/statement_en.csv"),
@@ -60,10 +59,8 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
} }
) )
wizard.with_context( wizard.with_context(
{ journal_id=journal.id,
"journal_id": journal.id, account_statement_import_paypal_test=True,
"account_statement_import_paypal_test": True,
}
).import_file_button() ).import_file_button()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 1) self.assertEqual(len(statement), 1)
@@ -78,9 +75,7 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
"currency_id": self.currency_eur.id, "currency_id": self.currency_eur.id,
} }
) )
wizard = self.AccountStatementImport.with_context( wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
{"journal_id": journal.id}
).create(
{ {
"statement_filename": "fixtures/statement_en.csv", "statement_filename": "fixtures/statement_en.csv",
"statement_file": self._data_file("fixtures/statement_en.csv"), "statement_file": self._data_file("fixtures/statement_en.csv"),
@@ -88,10 +83,8 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
} }
) )
wizard.with_context( wizard.with_context(
{ journal_id=journal.id,
"journal_id": journal.id, account_statement_import_paypal_test=True,
"account_statement_import_paypal_test": True,
}
).import_file_button() ).import_file_button()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 1) self.assertEqual(len(statement), 1)
@@ -106,9 +99,7 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
"currency_id": self.currency_eur.id, "currency_id": self.currency_eur.id,
} }
) )
wizard = self.AccountStatementImport.with_context( wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
{"journal_id": journal.id}
).create(
{ {
"statement_filename": "fixtures/statement_es.csv", "statement_filename": "fixtures/statement_es.csv",
"statement_file": self._data_file("fixtures/statement_es.csv"), "statement_file": self._data_file("fixtures/statement_es.csv"),
@@ -116,10 +107,8 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
} }
) )
wizard.with_context( wizard.with_context(
{ journal_id=journal.id,
"journal_id": journal.id, account_statement_import_paypal_test=True,
"account_statement_import_paypal_test": True,
}
).import_file_button() ).import_file_button()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 1) self.assertEqual(len(statement), 1)
@@ -134,9 +123,7 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
"currency_id": self.currency_usd.id, "currency_id": self.currency_usd.id,
} }
) )
wizard = self.AccountStatementImport.with_context( wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
{"journal_id": journal.id}
).create(
{ {
"statement_filename": "fixtures/activity_en.csv", "statement_filename": "fixtures/activity_en.csv",
"statement_file": self._data_file("fixtures/activity_en.csv"), "statement_file": self._data_file("fixtures/activity_en.csv"),
@@ -144,10 +131,8 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
} }
) )
wizard.with_context( wizard.with_context(
{ journal_id=journal.id,
"journal_id": journal.id, account_statement_import_paypal_test=True,
"account_statement_import_paypal_test": True,
}
).import_file_button() ).import_file_button()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 1) self.assertEqual(len(statement), 1)
@@ -162,9 +147,7 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
"currency_id": self.currency_usd.id, "currency_id": self.currency_usd.id,
} }
) )
wizard = self.AccountStatementImport.with_context( wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
{"journal_id": journal.id}
).create(
{ {
"statement_filename": "fixtures/empty_activity.csv", "statement_filename": "fixtures/empty_activity.csv",
"statement_file": self._data_file("fixtures/empty_activity.csv"), "statement_file": self._data_file("fixtures/empty_activity.csv"),
@@ -173,10 +156,8 @@ class TestAccountBankStatementImportPayPal(common.TransactionCase):
) )
with self.assertRaises(UserError): with self.assertRaises(UserError):
wizard.with_context( wizard.with_context(
{ journal_id=journal.id,
"journal_id": journal.id, account_statement_import_paypal_test=True,
"account_statement_import_paypal_test": True,
}
).import_file_button() ).import_file_button()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 0) self.assertEqual(len(statement), 0)