Skip to content

Commit

Permalink
Merge PR #149 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by aheficent
  • Loading branch information
OCA-git-bot committed Oct 1, 2019
2 parents 20861d3 + a22a37a commit d8d9d5a
Show file tree
Hide file tree
Showing 31 changed files with 1,887 additions and 0 deletions.
141 changes: 141 additions & 0 deletions account_operating_unit/README.rst
@@ -0,0 +1,141 @@
===============================
Accounting with Operating Units
===============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/12.0/account_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-12-0/operating-unit-12-0-account_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/213/12.0
:alt: Try me on Runbot

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

This module allows a company to manage the accounting based on Operating
Units (OU's).

* The financial reports (Trial Balance, P&L, Balance Sheet), allow to report
the balances of one or more OU's.
* If a company wishes to report Balance Sheet and P&L accounts based on
OU's, they should indicate at company level that the OU's are
self-balanced, and the corresponding Inter-Operating Unit clearing account.
The Chart of Accounts will always be balanced, for each Operating Unit.
* A company considering Operating Unit as applicable to report only profits
and losses will not need to set the OU's as self-balanced.
* The self-balancing of Operating Unit is ensured at the time of posting a
journal entry. In case that the journal involves posting of items in
separate Operating Units, new journal items will be created, using the
Inter-Operating Unit clearing account, to ensure that each OU is going to
be self-balanced for that journal entry.
* Adds the Operating Unit to the invoice. A user can choose what OU to
create the invoice for.
* Adds the Operating Unit to payments and payment methods. The operating
unit of a payment will be that of the payment method chosen.
* Implements security rules at OU level to invoices, payments and journal
items.

**Table of contents**

.. contents::
:local:

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

If your company is required to generate a balanced balance sheet by
Operating Unit you can specify at company level that Operating Units should
be self-balanced, and then indicate a self-balancing clearing account.

#. Create an account "Inter-OU Clearing". It is a balance sheet account.
#. Go to *Settings / Companies / Configuration* and Set the "Operating Units
are self-balanced" checkbox. Then set the "Inter-OU Clearing" account in "Inter-Operating Unit
clearing account" field.
#. Go to *Accounting / Configuration / Accounting / Journals* and define, for
each Payment Method, the Operating Unit that will be used in payments.

Usage
=====

* Add the Operating Unit to invoices.
* Report invoices by Operating Unit in *Accounting / Reporting*
*Business Intelligence / Invoices*
* Add the Default Operating Unit to account move. Then all move lines will
by default adopt this Operating Unit.
* Add Operating Units to the move lines. If they differ across lines of the same move, and the OU's are
self-balanced, then additional move lines will be created so as to make
the move self-balanced from OU perspective.
* In the menu *Accounting / Reporting / PDF Reports*, you can indicate the
Operating Units to report on, for the *Trial Balance*, *Balance Sheet*,
*Profit and Loss*, and *Financial Reports*.

Known issues / Roadmap
======================

* The *General Ledger*, *Aged Partner Balance* reports do not support the
filter by Operating Unit. Basically due to lack of proper hooks in the
standard methods used by these reports, to introduce the ability to filter
by Operating Unit.
* Trial Balance, P&L and Balance Sheet were removed from Odoo Community. Once
OCA Financial Reports are migrated to 12 we can add the Operating Unit to
those reports.

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

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

* Eficent
* Serpent Consulting Services Pvt. Ltd.
* WilldooIT Pty Ltd

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

* Eficent Business and IT Consulting Services S.L. <contact@eficent.com>
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Aarón Henríquez <ahenriquez@eficent.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
* WilldooIT Pty Ltd <info@willdooit.com>
* Michael Villamar <michael.villamar@willdooit.com>

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.

This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/12.0/account_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions account_operating_unit/__init__.py
@@ -0,0 +1,4 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import models
from . import report
26 changes: 26 additions & 0 deletions account_operating_unit/__manifest__.py
@@ -0,0 +1,26 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": 'Accounting with Operating Units',
"summary": "Introduces Operating Unit (OU) in invoices and "
"Accounting Entries with clearing account",
"version": "12.0.1.0.0",
"author": "Eficent, "
"Serpent Consulting Services Pvt. Ltd.,"
"WilldooIT Pty Ltd,"
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Accounting & Finance",
"depends": ['account', 'operating_unit', 'analytic_operating_unit'],
"license": "LGPL-3",
"data": [
"security/account_security.xml",
"views/account_move_view.xml",
"views/account_journal_view.xml",
"views/company_view.xml",
"views/invoice_view.xml",
"views/account_payment_view.xml",
"views/account_invoice_report_view.xml",
],
}
7 changes: 7 additions & 0 deletions account_operating_unit/models/__init__.py
@@ -0,0 +1,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import res_company
from . import account_journal
from . import account_move
from . import account_invoice
from . import account_payment
89 changes: 89 additions & 0 deletions account_operating_unit/models/account_invoice.py
@@ -0,0 +1,89 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.translate import _


class AccountInvoice(models.Model):
_inherit = "account.invoice"

operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit',
default=lambda self:
self.env['res.users'].
operating_unit_default_get(self._uid),
domain="[('user_ids', '=', uid)]",
readonly=True,
states={'draft': [('readonly',
False)]})

@api.onchange('operating_unit_id')
def _onchange_operating_unit(self):
if self.operating_unit_id and (
not self.journal_id or
self.journal_id.operating_unit_id != self.operating_unit_id):
journal = self.env['account.journal'].search(
[('type', '=', self.journal_id.type)])
jf = journal.filtered(
lambda aj: aj.operating_unit_id == self.operating_unit_id)
if not jf:
self.journal_id = journal[0]
else:
self.journal_id = jf[0]

@api.onchange('journal_id')
def _onchange_journal(self):
if self.journal_id and self.journal_id.operating_unit_id and \
self.journal_id.operating_unit_id != self.operating_unit_id:
ou = self.env['operating.unit'].search(
[('id', '=', self.journal_id.operating_unit_id.id)], limit=1
)
self.operating_unit_id = ou

@api.multi
def finalize_invoice_move_lines(self, move_lines):
move_lines = super(AccountInvoice,
self).finalize_invoice_move_lines(move_lines)
new_move_lines = []
for line_tuple in move_lines:
if self.operating_unit_id:
line_tuple[2]['operating_unit_id'] = \
self.operating_unit_id.id
new_move_lines.append(line_tuple)
return new_move_lines

@api.multi
@api.constrains('operating_unit_id', 'company_id')
def _check_company_operating_unit(self):
for pr in self:
if (
pr.company_id and
pr.operating_unit_id and
pr.company_id != pr.operating_unit_id.company_id
):
raise ValidationError(_('The Company in the Invoice and in '
'Operating Unit must be the same.'))
return True

@api.multi
@api.constrains('operating_unit_id', 'journal_id')
def _check_journal_operating_unit(self):
for ai in self:
if (
ai.journal_id.operating_unit_id and
ai.operating_unit_id and
ai.operating_unit_id != ai.journal_id.operating_unit_id
):
raise ValidationError(_('The OU in the Invoice and in '
'Journal must be the same.'))
return True


class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'

operating_unit_id = fields.Many2one('operating.unit',
related='invoice_id.operating_unit_id',
string='Operating Unit', store=True)
29 changes: 29 additions & 0 deletions account_operating_unit/models/account_journal.py
@@ -0,0 +1,29 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models, _
from odoo.exceptions import UserError


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

operating_unit_id = fields.Many2one(comodel_name='operating.unit',
string='Operating Unit',
domain="[('user_ids', '=', uid)]",
help="Operating Unit that will be "
"used in payments, when this "
"journal is used.")

@api.multi
@api.constrains('type')
def _check_ou(self):
for journal in self:
if journal.type in ('bank', 'cash') \
and journal.company_id.ou_is_self_balanced \
and not journal.operating_unit_id:
raise UserError(_('Configuration error. If defined as '
'self-balanced at company level, the '
'operating unit is mandatory in bank '
'journal.'))

0 comments on commit d8d9d5a

Please sign in to comment.