Skip to content

Commit

Permalink
Run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed May 23, 2024
1 parent 7cd31cd commit 5a08fe9
Show file tree
Hide file tree
Showing 13 changed files with 630 additions and 123 deletions.
37 changes: 15 additions & 22 deletions account_offbalance_sponsorship/README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
==================================
Off balance sponsorship accounting
==================================
==============================
account_offbalance_sponsorship
==============================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand All @@ -17,18 +17,17 @@ Off balance sponsorship accounting
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-CompassionCH%2Ftest--repo-lightgray.png?logo=github
:target: https://github.com/CompassionCH/test-repo/tree/14.0/account_statement_completion
:target: https://github.com/CompassionCH/test-repo/tree/14.0/account_offbalance_sponsorship
:alt: CompassionCH/test-repo

|badge1| |badge2| |badge3|

This module adds a way to implement off-balance sponsorship accounting.
Sponsorship generate invoices to enable off balance accounting (which can be required in certain legislation)
we cannot rely on the odoo off-balance account feature (it does not allow a reconcilable account)
2 accounts are defined in the sponsorship config: Account asset and an reconcilable account.
This enable to have the full set of accounts from invoice generation to payment, all off the main chart of account.

The income to be reported in the accounting is to be done in batch, once payments are in.
It's not possible to use the stock off-balance feature because it's not
possible to have a reconciliable off-balance account. So we use the 9xxx
account and a configuration to define: - receivable (off-balance): A -
asset (off-balance): B this function adds in the payment move if there
is an off-balance (A) receivable account: - the off-balance asset (B) -
add the outstanding account again.

**Table of contents**

Expand All @@ -41,7 +40,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/CompassionCH/test-repo/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/CompassionCH/test-repo/issues/new?body=module:%20account_statement_completion%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/CompassionCH/test-repo/issues/new?body=module:%20account_offbalance_sponsorship%0Aversion:%2014.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.

Expand All @@ -51,18 +50,12 @@ Credits
Authors
-------

* Compassion CH

Contributors
------------

- Steve Ferry <[email protected]>
- Emanuel Cino <[email protected]>
- Quentin Gigon <[email protected]>
* Compassion Switzerland
* David Wulliamoz

Maintainers
-----------

This module is part of the `CompassionCH/test-repo <https://github.com/CompassionCH/test-repo/tree/14.0/account_statement_completion>`_ project on GitHub.
This module is part of the `CompassionCH/test-repo <https://github.com/CompassionCH/test-repo/tree/14.0/account_offbalance_sponsorship>`_ project on GitHub.

You are welcome to contribute.
2 changes: 0 additions & 2 deletions account_offbalance_sponsorship/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import models
48 changes: 14 additions & 34 deletions account_offbalance_sponsorship/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,24 @@
##############################################################################

{
'name': "account_offbalance_sponsorship",

'summary': """
"name": "account_offbalance_sponsorship",
"summary": """
Off-Balance accounting for sponsorships.
""",

'description': """
It's not possible to use the stock off-balance feature because
it's not possible to have a reconciliable off-balance account. So we use the 9xxx account and a configuration to
define:
- receivable (off-balance): A
- asset (off-balance): B
this function adds in the payment move if there is an off-balance (A) receivable account:
- the off-balance asset (B)
- add the outstanding account again. """,

'author': "Compassion CH",
'website': "http://www.compassion.ch",

# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'sponsorship and donation',
'version': '0.1',

"author": "Compassion Switzerland, David Wulliamoz",
"website": "https://github.com/CompassionCH/test-repo",
"category": "sponsorship and donation",
"license": "AGPL-3",
"version": "14.0.1.0.0",
# any module necessary for this one to work correctly
'depends': ['base',
'sponsorship_compassion',
#'account_reconcile_compassion',
],

"depends": [
"base",
"sponsorship_compassion",
#'account_reconcile_compassion',
],
# always loaded
'data': [
"data": [
# 'security/ir.model.access.csv',
'views/res_config_view.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
"views/res_config_view.xml",
],
}
2 changes: 0 additions & 2 deletions account_offbalance_sponsorship/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-

from . import account_move
from . import res_config
191 changes: 145 additions & 46 deletions account_offbalance_sponsorship/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-today Compassion CH (http://www.compassion.ch)
Expand All @@ -9,99 +8,199 @@
#
##############################################################################

from odoo import _, models
from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

def js_remove_outstanding_partial(self, partial_id):
''' Called by the 'payment' widget to remove a reconciled entry to the present invoice.
"""Called by the 'payment' widget to remove a reconciled entry to the present
invoice.
:param partial_id: The id of an existing partial reconciled with the current invoice.
'''
:param partial_id: The id of an existing partial reconciled with the current
invoice.
"""
mv = self.env["account.partial.reconcile"].browse(partial_id)
account_offbalance_receivable, account_offbalance_asset = self.line_ids.get_account_offbalance(mv.company_id)
(
account_offbalance_receivable,
account_offbalance_asset,
) = self.line_ids.get_account_offbalance(mv.company_id)
pmt_move = mv.credit_move_id.move_id
rem_lines = self.env["account.move.line"].search([
("account_id", "=", account_offbalance_asset), ("move_id", "=", pmt_move.id),
("debit", "=", mv.amount)])
rem_lines = self.env["account.move.line"].search(
[
("account_id", "=", account_offbalance_asset),
("move_id", "=", pmt_move.id),
("debit", "=", mv.amount),
]
)
if rem_lines.statement_line_id:
rem_lines.statement_line_id.with_delay().button_undo_reconciliation()
res = super().js_remove_outstanding_partial(partial_id)
return res


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def get_account_offbalance(self,company):
def get_account_offbalance(self, company):
param_obj = self.env["res.config.settings"].with_company(company)
return (param_obj.get_param("account_offbalance_receivable"),param_obj.get_param("account_offbalance_asset"))
return (
param_obj.get_param("account_offbalance_receivable"),
param_obj.get_param("account_offbalance_asset"),
)

def reconcile(self):
res = super().reconcile()
account_offbalance_receivable,account_offbalance_asset = self.get_account_offbalance(self[0].move_id.company_id)
(
account_offbalance_receivable,
account_offbalance_asset,
) = self.get_account_offbalance(self[0].move_id.company_id)
if self[0].account_id.id == account_offbalance_receivable:
if "partials" in res.keys():
for part in res["partials"]:
self.add_off_balance_lines(part,account_offbalance_receivable,account_offbalance_asset,self[0].move_id.company_id)
self.add_off_balance_lines(
part,
account_offbalance_receivable,
account_offbalance_asset,
self[0].move_id.company_id,
)
return res

def add_off_balance_lines(self,mv,account_offbalance_receivable,account_offbalance_asset,company):
def add_off_balance_lines(
self, mv, account_offbalance_receivable, account_offbalance_asset, company
):
rec_invoice_line_ids = mv.debit_move_id.move_id.line_ids.filtered(
lambda l: l.account_id.code.startswith('93'))
counterpart_credit_amount = sum(inv_line.credit for inv_line in rec_invoice_line_ids)
lambda mvl: mvl.account_id.code.startswith("93")
)
counterpart_credit_amount = sum(
inv_line.credit for inv_line in rec_invoice_line_ids
)
# Only allocate as income what has been "closed"
pmt_move = mv.credit_move_id.move_id
pmt_move_receivable_amount = sum(l.credit - l.debit for l in pmt_move.line_ids.filtered(lambda a: a.account_id.id == account_offbalance_receivable))
closed_amount = mv.amount if mv.amount<pmt_move_receivable_amount else pmt_move_receivable_amount
add_lines = self.env["account.move.line"].with_context(check_move_validity=False).create(
{"account_id": account_offbalance_asset, "move_id": pmt_move.id, "debit": closed_amount,"credit": 0})
pmt_move_receivable_amount = sum(
mvl.credit - mvl.debit
for mvl in pmt_move.line_ids.filtered(
lambda a: a.account_id.id == account_offbalance_receivable
)
)
closed_amount = (
mv.amount
if mv.amount < pmt_move_receivable_amount
else pmt_move_receivable_amount
)
add_lines = (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"account_id": account_offbalance_asset,
"move_id": pmt_move.id,
"debit": closed_amount,
"credit": 0,
}
)
)
total_amount_lines = 0
for inv_line in rec_invoice_line_ids:
inc_acc = self.env['account.account'].search(
[('code', '=', inv_line.account_id.code[1:]), ('company_id', '=', company.id)])
amount_line = round(closed_amount / counterpart_credit_amount * inv_line.credit, 2)
if abs(closed_amount - total_amount_lines - amount_line) <= .1:
#to avoid rounding issues
inc_acc = self.env["account.account"].search(
[
("code", "=", inv_line.account_id.code[1:]),
("company_id", "=", company.id),
]
)
amount_line = round(
closed_amount / counterpart_credit_amount * inv_line.credit, 2
)
if abs(closed_amount - total_amount_lines - amount_line) <= 0.1:
# to avoid rounding issues
amount_line = closed_amount - total_amount_lines
else:
total_amount_lines += amount_line
add_lines += self.env["account.move.line"].with_context(check_move_validity=False).create(
{"account_id": inc_acc.id, "move_id": pmt_move.id, "debit": 0,"product_id": inv_line.product_id.id,
"partner_id": inv_line.partner_id.id, "credit": amount_line})
add_lines += (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"account_id": inc_acc.id,
"move_id": pmt_move.id,
"debit": 0,
"product_id": inv_line.product_id.id,
"partner_id": inv_line.partner_id.id,
"credit": amount_line,
}
)
)
pmt_move.line_ids += add_lines

def remove_move_reconcile(self):
""" Undo a reconciliation """
"""Undo a reconciliation"""
if self.move_id:
part = self.matched_debit_ids + self.matched_credit_ids
account_offbalance_receivable, account_offbalance_asset = self.get_account_offbalance(
self[0].move_id.company_id)
if part and (part[0].debit_move_id.account_id.id == account_offbalance_receivable):
(
account_offbalance_receivable,
account_offbalance_asset,
) = self.get_account_offbalance(self[0].move_id.company_id)
if part and (
part[0].debit_move_id.account_id.id == account_offbalance_receivable
):
for mv in part:
rec_invoice_line_ids = mv.debit_move_id.move_id.line_ids.filtered(
lambda l: l.account_id.code.startswith('93'))
counterpart_credit_amount = sum(inv_line.credit for inv_line in rec_invoice_line_ids)
lambda mvl: mvl.account_id.code.startswith("93")
)
counterpart_credit_amount = sum(
inv_line.credit for inv_line in rec_invoice_line_ids
)
closed_amount = mv.amount
pmt_move = mv.credit_move_id.move_id
rem_lines = self.env["account.move.line"].search([
("account_id","=", account_offbalance_asset),("move_id","=", pmt_move.id), ("debit","=",closed_amount)])
rem_lines = self.env["account.move.line"].search(
[
("account_id", "=", account_offbalance_asset),
("move_id", "=", pmt_move.id),
("debit", "=", closed_amount),
]
)
if self.filtered(lambda s: s.statement_line_id is not False):
rem_lines.statement_line_id.with_delay().button_undo_reconciliation()
(
rem_lines.statement_line_id.with_delay().button_undo_reconciliation()
)
else:
total_amount_lines = 0
for inv_line in rec_invoice_line_ids:
inc_acc = self.env['account.account'].search(
[('code', '=', inv_line.account_id.code[1:]), ('company_id', '=', self.company_id.id)])
amount_line = round(closed_amount / counterpart_credit_amount * inv_line.credit, 2)
if abs(counterpart_credit_amount - total_amount_lines - amount_line) < 0.1:
#to avoid rounding issues
inc_acc = self.env["account.account"].search(
[
("code", "=", inv_line.account_id.code[1:]),
("company_id", "=", self.company_id.id),
]
)
amount_line = round(
closed_amount
/ counterpart_credit_amount
* inv_line.credit,
2,
)
if (
abs(
counterpart_credit_amount
- total_amount_lines
- amount_line
)
< 0.1
):
# to avoid rounding issues
amount_line = closed_amount - total_amount_lines
else:
total_amount_lines += amount_line
rem_lines += self.env["account.move.line"].search([
("account_id","=",inc_acc.id),("move_id","=",pmt_move.id),("product_id","=", inv_line.product_id.id)
,("partner_id","=", inv_line.partner_id.id),("credit","=", amount_line)])
pmt_move.write({'state': 'draft', 'is_move_sent': False})
rem_lines += self.env["account.move.line"].search(
[
("account_id", "=", inc_acc.id),
("move_id", "=", pmt_move.id),
("product_id", "=", inv_line.product_id.id),
("partner_id", "=", inv_line.partner_id.id),
("credit", "=", amount_line),
]
)
pmt_move.write({"state": "draft", "is_move_sent": False})
pmt_move.line_ids -= rem_lines
pmt_move.action_post()
super().remove_move_reconcile()
Loading

0 comments on commit 5a08fe9

Please sign in to comment.