Skip to content

Commit

Permalink
Merge PR #3233 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rvalyi
  • Loading branch information
OCA-git-bot committed Jul 29, 2024
2 parents a8998ba + 5d98b82 commit 05ab4dd
Show file tree
Hide file tree
Showing 78 changed files with 10,208 additions and 0 deletions.
114 changes: 114 additions & 0 deletions l10n_br_cnab_structure/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
==============
CNAB Structure
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:96ca0f1eb804341d0e36d4d79df0162d6a5e3be4ee9f214c6e217d9a00027048
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fl10n--brazil-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-brazil/tree/16.0/l10n_br_cnab_structure
:alt: OCA/l10n-brazil
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-brazil-16-0/l10n-brazil-16-0-l10n_br_cnab_structure
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-brazil&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds functionality for implementing brazilian banking automation by CNAB file exchange.

**Table of contents**

.. contents::
:local:

Usage
=====

Configuration and usability:
https://youtu.be/ljommELunlA

Changelog
=========

14.0.0.0.1 (2022)
~~~~~~~~~~~~~~~~~

Module creation.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-brazil/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-brazil/issues/new?body=module:%20l10n_br_cnab_structure%0Aversion:%2016.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
=======

Authors
~~~~~~~

* Engenere
* Escodoo

Contributors
~~~~~~~~~~~~

* `Engenere <https://engenere.one>`_:

* Antônio S. Pereira Neto <[email protected]>
* Felipe Motter Pereira <[email protected]>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Escodoo - https://www.escodoo.com.br

* Engenere - https://engenere.one/

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-antoniospneto| image:: https://github.com/antoniospneto.png?size=40px
:target: https://github.com/antoniospneto
:alt: antoniospneto
.. |maintainer-felipemotter| image:: https://github.com/felipemotter.png?size=40px
:target: https://github.com/felipemotter
:alt: felipemotter

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-antoniospneto| |maintainer-felipemotter|

This module is part of the `OCA/l10n-brazil <https://github.com/OCA/l10n-brazil/tree/16.0/l10n_br_cnab_structure>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions l10n_br_cnab_structure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .hooks import post_init_hook

from . import cnab
from . import models
from . import wizard
39 changes: 39 additions & 0 deletions l10n_br_cnab_structure/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Engenere
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# pylint: disable=pointless-statement
{
"name": "CNAB Structure",
"summary": """
This module allows defining the structure for generating the CNAB file.
Used to exchange information with Brazilian banks.""",
"version": "16.0.1.0.0",
"author": "Engenere, Escodoo, Odoo Community Association (OCA)",
"maintainers": ["antoniospneto", "felipemotter"],
"website": "https://github.com/OCA/l10n-brazil",
"license": "AGPL-3",
"depends": [
"l10n_br_account_payment_order",
"l10n_br_coa_generic",
],
"data": [
"wizard/field_select_wizard.xml",
"wizard/cnab_preview_wizard.xml",
"wizard/cnab_import_wizard.xml",
"views/cnab_structure.xml",
"views/cnab_batch.xml",
"views/cnab_line.xml",
"views/cnab_line_field.xml",
"views/account_payment_mode.xml",
"views/l10n_br_cnab_return_log_view.xml",
"views/l10n_br_cnab_return_event_view.xml",
"views/cnab_line_field_group.xml",
"views/cnab_line_field_group_condition.xml",
"views/journal_view.xml",
"security/cnab_security.xml",
"security/ir.model.access.csv",
"views/cnab_menu.xml",
],
"demo": [],
"post_init_hook": "post_init_hook",
"external_dependencies": {"python": ["pyyaml", "unidecode"]},
}
1 change: 1 addition & 0 deletions l10n_br_cnab_structure/cnab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .cnab import Cnab, CnabBatch, CnabDetailRecord, CnabLine, RecordType
151 changes: 151 additions & 0 deletions l10n_br_cnab_structure/cnab/cnab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Copyright (C) 2022-Today - Engenere (<https://engenere.one>).
# @author Antônio S. Pereira Neto <[email protected]>
# @author Felipe Motter Pereira <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from enum import Enum
from typing import List


class RecordType(Enum):
HEADER = 0
HEADER_BATCH = 1
DETAIL_RECORD = 3
TRAILER_BATCH = 5
TRAILER = 9


class CnabField:
__slots__ = ["position", "value", "name"]

def __init__(self, position: int, value: str, name: str = "") -> None:
self.position = position
self.value = value
self.name = name


class CnabLine:
type: RecordType
fields: List[CnabField]

def __init__(self, record_type) -> None:
self.type = record_type
self.fields = []

def get_field_by_name(self, name: str) -> CnabField:
field = next((obj for obj in self.fields if obj.name == name), None)
return field

def add_field(self, name: str, value: str, pos: int) -> None:
self.fields.append(CnabField(position=pos, value=value, name=name))

def sorted_values(self):
# sort the fields according to position
sorted_fields = sorted(self.fields, key=lambda f: f.position)
# return dict without position value:
fields_values_dict = {}
for field in sorted_fields:
fields_values_dict[field.name] = field.value
return fields_values_dict

def output(self) -> str:
return "".join(self.sorted_values().values())

def asdict(self):
return {"type": self.type.name, "fields": self.sorted_values()}


class CnabDetailRecord:
segments: List[CnabLine]

def __init__(self, name: str) -> None:
self.name = name
self.segments = []

def lines(self) -> List[CnabLine]:
lines = []
for segment in self.segments:
lines.append(segment)
return lines

def len_records(self) -> int:
return len(self.segments)

def asdict(self):
return {"name": self.name, "segments": [s.asdict() for s in self.segments]}


class CnabBatch:
header: CnabLine
detail_records: List[CnabDetailRecord]
trailer: CnabLine

def __init__(self) -> None:
self.detail_records = []

def detail_lines(self) -> List[CnabLine]:
lines = []
for detail in self.detail_records:
lines.extend(detail.lines())
return lines

def lines(self) -> List[CnabLine]:
lines = []
lines.append(self.header)
lines.extend(self.detail_lines())
lines.append(self.trailer)
return lines

def len_records(self) -> int:
count_records = 0
for detail in self.detail_records:
count_records += detail.len_records()
return count_records + 2

def asdict(self):
return {
"header": self.header.asdict(),
"detail_records": [d.asdict() for d in self.detail_records],
"trailer": self.trailer.asdict(),
}


class Cnab:
header: CnabLine
batches: List[CnabBatch]
trailer: CnabLine

def __init__(self) -> None:
self.header = CnabLine(RecordType.HEADER)
self.batches = []
self.trailer = CnabLine(RecordType.TRAILER)

def lines(self) -> List[CnabLine]:
lines = []
lines.append(self.header)
for batch in self.batches:
lines.extend(batch.lines())
lines.append(self.trailer)
return lines

def len_batches(self) -> int:
return len(self.batches)

def len_records(self) -> int:
count_records = 0
for batch in self.batches:
count_records += batch.len_records()
return count_records + 2

def output(self) -> str:
output = ""
for line in self.lines():
output += line.output() + "\r\n"
return output

def asdict(self):
return {
"header": self.header.asdict(),
"batches": [b.asdict() for b in self.batches],
"trailer": self.trailer.asdict(),
}
5 changes: 5 additions & 0 deletions l10n_br_cnab_structure/data/cnab.line.field.group.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"id","name","cnab_line_id/id"
"l10n_br_cnab_structure.cnab_line_field_group_1","Conta Corrente - Mesmo Banco","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a"
"l10n_br_cnab_structure.cnab_line_field_group_2","Conta Corrente - Outros Bancos","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a"
"l10n_br_cnab_structure.cnab_line_field_group_3","Conta Pagamento - Outros Bancos","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a"
"l10n_br_cnab_structure.cnab_line_field_group_4","Conta Corrente - Chave PIX","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"id","cnab_group_id/id","field_id/id","operator","json_value"
"l10n_br_cnab_structure.cnab_line_group_field_condition_1","l10n_br_cnab_structure.cnab_line_field_group_1","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a_21_23","in","[""341"",""409""]"
"l10n_br_cnab_structure.cnab_line_group_field_condition_6","l10n_br_cnab_structure.cnab_line_field_group_1","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a_113_114","not in","[""04""]"
"l10n_br_cnab_structure.cnab_line_group_field_condition_2","l10n_br_cnab_structure.cnab_line_field_group_2","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a_21_23","not in","[""341"", ""409""]"
"l10n_br_cnab_structure.cnab_line_group_field_condition_5","l10n_br_cnab_structure.cnab_line_field_group_2","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a_113_114","not in","[""04""]"
"l10n_br_cnab_structure.cnab_line_group_field_condition_3","l10n_br_cnab_structure.cnab_line_field_group_3","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a_113_114","in","[""PG""]"
"l10n_br_cnab_structure.cnab_line_group_field_condition_4","l10n_br_cnab_structure.cnab_line_field_group_4","l10n_br_cnab_structure.cnab_itau_240_pagamentos_segmento_a_113_114","in","[""04""]"
Loading

0 comments on commit 05ab4dd

Please sign in to comment.