Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.0 autogiro #62

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compassion_denmark_payment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
"version": "14.0.1.3.3",
"license": "AGPL-3",
"category": "Banking addons",
"depends": ["compassion_nordic_accounting"],
"depends": [
"compassion_nordic_accounting",
"account_payment_return_import" #OCA/account-payment
],
"data": [
"data/account_payment_method.xml",
"data/payment.return.reason.csv"
],
"installable": True,
}
4 changes: 4 additions & 0 deletions compassion_denmark_payment/data/payment.return.reason.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,code,name
automated_dk_payment_rejected,237,Beservice payment rejected
automated_dk_payment_cancelled,238,Beservice payment cancelled
automated_dk_payment_charged_back,239,Beservice payment charged back
1 change: 0 additions & 1 deletion compassion_denmark_payment/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@

from ..beservice import *
from . import account_payment_order
from . import account_statement_import
from . import account_statement_import_beservice_parser
3 changes: 1 addition & 2 deletions compassion_denmark_payment/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def generate_payment_file(self):
data_delivery.sections[0].add_payment(customer_number=f'{pymt_trx.partner_id.ref:15}',
mandate_number=pymt_trx.payment_line_ids[0].move_line_id.move_id.
line_ids.mapped('contract_id').group_id.ref,
reference=(pymt_trx.date.strftime("%b").capitalize()
+ ' ' + pymt_trx.payment_line_ids[0].payment_type.capitalize())[:20],
reference=f"{self.id}_{pymt_trx.id}_{pymt_trx.ref}_"[:30],
amount=pymt_trx.amount,
sign_code=beservice.SignCode.COLLECTION,
payment_date=pymt_trx.date,
Expand Down
32 changes: 0 additions & 32 deletions compassion_denmark_payment/models/account_statement_import.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
#
##############################################################################

import base64
import itertools
import logging
from datetime import datetime
from decimal import Decimal
from io import StringIO
from os import path
from .. import beservice
from pytz import timezone, utc

from odoo import _, api, models
from odoo import _, api, models, fields

_logger = logging.getLogger(__name__)

Expand All @@ -33,41 +28,31 @@ class AccountBankStatementImportPayPalParser(models.TransientModel):
_description = "Account Statement Import Betalingsservice Parser "

@api.model
def parse(self, data_file, filename):
journal = self.env["account.journal"].browse(self.env.context.get("journal_id"))
def parse(self, data_file):
file_data = beservice.parse(StringIO(data_file.decode("iso-8859-1")).read())
Journal = self.env["account.journal"]
journal = Journal.search([
("payment_mode_id.initiating_party_scheme", "=", file_data.data_supplier_number)
], limit=1) or Journal.browse(self.env.context.get("journal_id"))
currency_code = (journal.currency_id or journal.company_id.currency_id).name
account_number = journal.bank_account_id.acc_number

name = _("%s: %s") % (
journal.code,
path.basename(filename),
)
file_data = beservice.parse(StringIO(data_file.decode("iso-8859-1")).read())
name = journal.code + str(fields.Datetime.now())
lines = [a for a in self._calculate_lines(file_data.sections[0]) if
a.transaction_code == beservice.TransactionCode.AUTOMATED_PAYMENT_COMPLETED]
a.transaction_code != beservice.TransactionCode.AUTOMATED_PAYMENT_COMPLETED]
if not lines:
return currency_code, account_number, [{"name": name, "transactions": []}]
date = file_data.sections[0].section_date

transactions = list(
itertools.chain.from_iterable(
map(lambda line: self._convert_line_to_transactions(line), lines)
)
)

return (
currency_code,
account_number,
[
{
"name": name,
"date": date,
"balance_start": float(-file_data.sections[0].get_net_amount()),
"balance_end_real": float(0),
"transactions": transactions,
}
],
)
return {
"name": name,
"date": date,
"account_number": account_number,
"transactions": transactions,
}

@staticmethod
def _calculate_lines(data):
Expand All @@ -78,19 +63,16 @@ def _calculate_lines(data):

@api.model
def _convert_line_to_transactions(self, line: beservice.PaymentInformation):
transactions = []
details = line.reference
pay_ord_id, pay_trx_id, pay_trx_ref, empty = line.reference.split("_")
payment = self.env["account.payment"].browse(int(pay_trx_id))
gross_amount = line.amount
#
res = self.env['recurring.contract.group'].search([('ref', '=', line.mandate_number)])
bank_account = res.partner_id.bank_ids
transaction = {
return [{
"partner_id": res.partner_id.id,
"amount": str(gross_amount),
"date": line.info_date,
"ref": line.mandate_number,
"payment_ref": details,
}
transactions.append(transaction)

return transactions
"concept": line.mandate_number,
"reference": payment.move_id.name,
"reason_code": line.transaction_code.value,
"raw_import_data": line,
}]
3 changes: 2 additions & 1 deletion compassion_denmark_payment/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
#
##############################################################################

from . import load_mandate_wizard
from . import load_mandate_wizard
from . import payment_return_import
23 changes: 23 additions & 0 deletions compassion_denmark_payment/wizards/payment_return_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2016 Tecnativa - Pedro M. Baeza
# Copyright 2018 Tecnativa - Luis M. Ontalba
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
from odoo import _, api, models
_logger = logging.getLogger(__name__)


class PaymentReturnImport(models.TransientModel):
_inherit = "payment.return.import"

@api.model
def _parse_file(self, data_file):
try:
Parser = self.env["account.statement.import.beservice.parser"]
return Parser.with_context(journal_id=self.journal_id.id).parse(
data_file
)
except Exception:
_logger.warning(_("The file couldn't be parsed by danish beservice parser"), exc_info=True)
return super()._parse_file(data_file)
6 changes: 5 additions & 1 deletion compassion_sweden_payment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
"website": "http://www.compassion.ch",
"license": "AGPL-3",
"category": "Banking addons",
"depends": ["compassion_nordic_accounting"],
"depends": [
"compassion_nordic_accounting",
"account_payment_return_import" # OCA/account-payment
],
"data": [
"data/account_payment_method.xml",
"data/payment.return.reason.csv",
"data/statement_import_sheet_mapping.xml",
],
"installable": True,
Expand Down
4 changes: 4 additions & 0 deletions compassion_sweden_payment/data/payment.return.reason.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,code,name
automated_se_payment_insufficient_fund,1,Autogiro payment refused for insufficient fund
automated_se_payment_no_connection,2,Autogiro payment refused for no connection
automated_se_payment_renewed_funds,9,Autogiro payment refused for renewed funds
10 changes: 5 additions & 5 deletions compassion_sweden_payment/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def generate_payment_file(self):
payment_initiation = bggiro.PaymentInitiation(date_written=self.create_date,
bankgiro_number=self.company_partner_bank_id.acc_number,
customer_number=self.payment_mode_id.initiating_party_identifier)
for payment_line in self.payment_line_ids:
for payment in self.payment_ids:
payment_initiation.add_payment(
transaction_type=bggiro.TransactionType.INCOMING_PAYMENT,
payment_date=payment_line.date,
payment_date=payment.date,
period_code=bggiro.PeriodCode.ONCE,
number_recurring_payments=0,
payer_number=int(payment_line.move_line_id.move_id.line_ids.mapped('contract_id').group_id.ref),
amount=int(payment_line.amount_currency),
reference=payment_line.communication[:16])
payer_number=int(payment.move_id.line_ids.mapped('contract_id').group_id.ref),
amount=int(payment.amount),
reference=payment.id[:16])
return payment_initiation.to_ocr().encode('iso-8859-1'), "{}.txt".format(self.name)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from io import StringIO
from os import path

from odoo import _, api, models
from odoo import _, api, models, fields
from .. import bggiro

_logger = logging.getLogger(__name__)
Expand All @@ -28,44 +28,37 @@ class AccountBankStatementImportPayPalParser(models.TransientModel):
_description = "Account Statement Import Betalingsservice Parser "

@api.model
def parse(self, data_file, filename):
journal = self.env["account.journal"].browse(self.env.context.get("journal_id"))
def parse(self, data_file):
file_data = bggiro.parse(StringIO(data_file.decode("iso-8859-1")).read())
Journal = self.env["account.journal"]
journal = Journal.search([
("payment_mode_id.initiating_party_identifier", "=", file_data.customer_number)
], limit=1) or Journal.browse(self.env.context.get("journal_id"))
currency_code = (journal.currency_id or journal.company_id.currency_id).name
account_number = journal.bank_account_id.acc_number

name = _("%s: %s") % (
journal.code,
path.basename(filename),
)
file_data = bggiro.parse(StringIO(data_file.decode("iso-8859-1")).read())
lines = [p for p in file_data.payments if p.payment_status_code == bggiro.PaymentStatus.APPROVED]
name = journal.code + str(fields.Datetime.now())
lines = [p for p in file_data.payments if p.payment_status_code != bggiro.PaymentStatus.APPROVED]
if not lines:
return currency_code, account_number, [{"name": name, "transactions": []}]
date = file_data.date_written
transactions = list(map(lambda line: self._convert_line_to_transactions(line), lines))
return (
currency_code,
account_number,
[
{
"name": name,
"date": date,
"balance_start": float(-file_data.get_total_amount_incoming()),
"balance_end_real": float(0),
"transactions": transactions,
}
],
)
return {
"name": name,
"date": date,
"account_number": account_number,
"transactions": transactions,
}

@api.model
def _convert_line_to_transactions(self, line: bggiro.Payment):
pay_opt = self.env['recurring.contract.group'].search([('ref', '=', line.payer_number)], limit=1)
payment = self.env["account.payment"].search([("ref", "=", line.reference)], limit=1)
return {
"partner_id": pay_opt.partner_id.id,
"amount": str(line.amount),
"date": line.payment_date,
# str(line.payer_bankgiro_number) We do not implement the account_number see cp-264 comment
"account_number": False,
"ref": line.payer_number,
"payment_ref": line.reference or ""
"concept": line.reference,
"reference": payment.move_id.name,
"reason_code": line.payment_status_code.value,
"raw_import_data": line
}
2 changes: 1 addition & 1 deletion compassion_sweden_payment/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
#
##############################################################################
from . import generate_tax_wizard
from . import account_statement_import
from . import payment_return_import
30 changes: 0 additions & 30 deletions compassion_sweden_payment/wizards/account_statement_import.py

This file was deleted.

21 changes: 21 additions & 0 deletions compassion_sweden_payment/wizards/payment_return_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Compassion CH Simon Gonzalez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
from odoo import _, api, models
_logger = logging.getLogger(__name__)


class PaymentReturnImport(models.TransientModel):
_inherit = "payment.return.import"

@api.model
def _parse_file(self, data_file):
try:
Parser = self.env["account.statement.import.bggiro.parser"]
return Parser.with_context(journal_id=self.journal_id.id).parse(
data_file
)
except Exception:
_logger.warning(_("The file couldn't be parsed by Swedish bggiro parser"), exc_info=True)
return super()._parse_file(data_file)