Skip to content

Commit

Permalink
ADD acc_facto_receiv_bal_eurofactor module
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Aug 13, 2024
1 parent 5468db1 commit cfe705e
Show file tree
Hide file tree
Showing 17 changed files with 1,087 additions and 0 deletions.
92 changes: 92 additions & 0 deletions account_factoring_receivable_balance_eurofactor/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
=================================================================
Account Factoring Receivable Balance Eurofactor - Crédit Agricole
=================================================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8566a7da7ce6ce8a102e907ef1dd9860f09a4887fe7e7c6d1b85db6a41bf6d0b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-Akretion%2Fhttps://github.com/akretion/odoo--factoring/tree/16.0-lightgray.png?logo=github
:target: https://github.com/Akretion/https://github.com/akretion/odoo-factoring/tree/16.0/tree/16.0/account_factoring_receivable_balance_eurofactor
:alt: Akretion/https://github.com/akretion/odoo-factoring/tree/16.0

|badge1| |badge2| |badge3|

Gestion de balance avec Eurofactor : Crédit Agricole et LCL

**Table of contents**

.. contents::
:local:

Configuration
=============

- use a company with l10n_fr
- alternatively you may create a new one with

Here you can create a new company with EUROFACTOR settings for default currency


.. code-block:: python
env["res.company"]._create_french_company(company_name="my new company")
Here you may create settings for a new installed currency

.. code-block:: python
env.browse(mycompany_id)._configure_eurof_factoring()
- now you can go to journals and filter them with `Factor type`.

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

Bugs are tracked on `GitHub Issues <https://github.com/Akretion/https://github.com/akretion/odoo-factoring/tree/16.0/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/Akretion/https://github.com/akretion/odoo-factoring/tree/16.0/issues/new?body=module:%20account_factoring_receivable_balance_eurofactor%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
~~~~~~~

* Akretion

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

* Akretion:
- David BEAL

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

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

Current maintainer:

|maintainer-bealdav|

This module is part of the `Akretion/https://github.com/akretion/odoo-factoring/tree/16.0 <https://github.com/Akretion/https://github.com/akretion/odoo-factoring/tree/16.0/tree/16.0/account_factoring_receivable_balance_eurofactor>`_ project on GitHub.

You are welcome to contribute.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions account_factoring_receivable_balance_eurofactor/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# © 2024 David BEAL @ Akretion

{
"name": "Account Factoring Receivable Balance Eurofactor - Crédit Agricole",
"version": "16.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"website": "https://github.com/akretion/odoo-factoring",
"author": "Akretion",
"maintainers": [
"bealdav",
],
"depends": [
"account_factoring_receivable_balance",
"account_factoring_receivable_balance",
"l10n_fr",
"partner_identification",
],
"data": [
"views/partner.xml",
"data/data.xml",
],
}
9 changes: 9 additions & 0 deletions account_factoring_receivable_balance_eurofactor/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="eurofactor_id_category" model="res.partner.id_category">
<field name="name">Eurofactor</field>
<field name="code">EF</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import partner
from . import account_journal
from . import subrogation_receipt
from . import company
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# © 2024 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccountJournal(models.Model):
_inherit = "account.journal"

factor_type = fields.Selection(
selection_add=[("eurof", "Eurofactor")],
ondelete={"eurof": "set null"},
)
factor_code2 = fields.Char(
help="Numéro attribué par notre système à l’enregistrement de votre contrat",
)
164 changes: 164 additions & 0 deletions account_factoring_receivable_balance_eurofactor/models/company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# © 2022 David BEAL @ Akretion
# © 2022 Alexis DE LATTRE @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

"""
Pour ce factor un seul journal de facto de type OD est nécessaire
pour l'envoi des credits : facture et avoir
"""

import logging

from odoo import _, fields, models
from odoo.exceptions import RedirectWarning, UserError
from odoo.tests import Form

logger = logging.getLogger(__name__)


FACTO_TYPE = "eurof"


class ResCompany(models.Model):
_inherit = "res.company"

def _prepare_data_for_factor(self, move_type="out_invoice"):
self.ensure_one()
move_form = Form(
self.env["account.move"]
.with_company(self.env.company)
.with_context(
default_move_type=move_type,
account_predictive_bills_disable_prediction=True,
)
)
move_form.invoice_date = fields.Date.from_string("2025-10-03")
move_form.date = move_form.invoice_date
move_form.partner_id = self.env.ref("base.res_partner_2")

def ui_populate_data_for_factor(self):
raise UserError(_("Not yet implemented"))
# self._prepare_data_for_factor()

def ui_configure_eurof_factoring_balance(self):
self.ensure_one()
self._configure_eurof_factoring()
eurof_journals = self.env["account.journal"].search(
[("factor_type", "=", FACTO_TYPE), ("company_id", "=", self.id)]
)
action_id = self.env.ref("account.action_account_journal_form").id
active_ids = ",".join([str(x) for x in eurof_journals.ids])

return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": "Configuration réussie",
"type": "success", # warning/success
"message": "Consulter les journaux et comptes configurés",
"links": [
{
"label": "Voir les journaux",
"url": f"#action={action_id}&model=account.journal"
f"&active_ids={active_ids}",
}
],
"sticky": True, # True/False will display for few seconds if false
"next": action_id,
},
}

def _configure_eurof_factoring(self):
"""Mainly copied from l10n_fr_account_vat_return
The code is created here and not in the test,
because it can be very useful for demos too
This method can be called to configure actual company or a new one
"""
self = self.sudo()
self.ensure_one()
currency = self.env.ref(
f"base.{self.currency_id.name.upper()}", raise_if_not_found=False
)
if not currency:
# pylint: disable=C8107
raise UserError(f"La devise '{currency.name}' est inconnue")
if self.env["account.journal"].search(
[
("factor_type", "=", FACTO_TYPE),
("company_id", "=", self.id),
("currency_id", "=", currency.id),
]
):
# pylint: disable=C8107
raise UserError(
f"Un journal Eurofactor avec la devise '{currency.name}'"
" existe déjà. Configuration annulée"
)
fr_chart_template = self.env.ref("l10n_fr.l10n_fr_pcg_chart_template")
company = self
if self.chart_template_id != fr_chart_template:
action = self.env.ref("account.action_account_config").read()[0]
action["name"] = f"Configure accounting chart in '{self.name}' company"
raise RedirectWarning(
_(
"The accounting chart installed in this company "
"is not the french one. Install it first"
),
action,
_("Go to accounting chart configuration"),
{"active_ids": [self.env.company.id]},
)
if self.env["account.journal"].search(
[
("factor_type", "=", FACTO_TYPE),
("currency_id", "=", currency.id),
("company_id", "=", company.id),
]
):
raise UserError(
_(
f"Eurofactor Journal with currency '{currency.name}' already exist."
" Configuration aborted"
)
)
vals = {"reconcile": False, "tax_ids": False, "company_id": company.id}
acc = {}
suffix = self._get_factor_shortname()
for acco in (
["4115", "Factoring Receivable", "income"],
["4671", "Factoring Current", "income"],
["4672", "Factoring Holdback", "income"],
["4673", "Factoring Recharging", "income"],
):
code = f"{acco[0]}{suffix}"
values = {"code": code, "name": acco[1], "account_type": acco[2]}
values.update(vals)
acc[code] = self.env["account.account"].create(values)
expense_acc = self.env["account.account"].search(
[("code", "=", "622500"), ("company_id", "=", company.id)]
)
self.env["account.journal"].create(
{
"name": f"Eurofactor Cr.Ag. {currency.symbol}",
"type": "general",
"factor_type": FACTO_TYPE,
"code": FACTO_TYPE.upper(),
"factor_code": "12345",
"factor_code2": "12345",
"company_id": company.id,
"factoring_receivable_account_id": acc[f"4115{suffix}"].id,
"factoring_current_account_id": acc[f"4671{suffix}"].id,
"factoring_holdback_account_id": acc[f"4672{suffix}"].id,
"factoring_pending_recharging_account_id": acc[f"4673{suffix}"].id,
"factoring_expense_account_id": expense_acc.id,
}
)
return company

def _get_factor_shortname(self):
"""Allow to customze account name
CA : Crédit agricole
can be LCL for Le Crédit Lyonnais
"""
return "CA"
50 changes: 50 additions & 0 deletions account_factoring_receivable_balance_eurofactor/models/partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# © 2024 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import exceptions, fields, models

MODULE = __name__[12 : __name__.index(".", 13)]


class ResPartner(models.Model):
_inherit = "res.partner"

factor_bank_id = fields.Many2one(
comodel_name="res.partner.bank", groups="account.group_account_manager"
)

def _get_partner_eurof_mapping(self):
rec_categ = self.env.ref(f"{MODULE}.eurofactor_id_category")
categ = self.env["res.partner.id_category"].search(
[("code", "=", rec_categ.code)]
)
return {
x.partner_id: x.name
for x in self.env["res.partner.id_number"].search(
[("category_id", "=", categ.id)]
)
}

def _check_eurof_data(self):
"Check data completude"

def printit(records):
return "\n\n" + "\n".join(records.mapped("display_name")) + "\n\n"

bank_missings = self.filtered(lambda s: not s.factor_bank_id)
identif_missings = self.env["res.partner"].browse(
[x.id for x in self if x not in self._get_partner_eurof_mapping()]
)
if bank_missings or identif_missings:
message = ""
if bank_missings:
message = (
f"Les clients {printit(bank_missings)}"
"n'ont pas de compte bancaire d'identifiant d'affacturage."
)
if identif_missings:
message += (
f"<br>Les clients {printit(identif_missings)}"
"n'ont pas d'identifiant d'affacturage."
)
raise exceptions.ValidationError(message)
Loading

0 comments on commit cfe705e

Please sign in to comment.