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

[9.0][ADD] account_analytic_no_lines #69

Merged
merged 4 commits into from
Oct 11, 2016
Merged
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
60 changes: 60 additions & 0 deletions account_analytic_no_lines/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=========================
Account Analytic No Lines
=========================

This module hides analytics lines from accounting menus and disable their generation from an invoice or a move line.

In many situations (i.e. when there are no analytic distribution, and when people don't consider timesheets as analytic entries),
the generation of analytic entries for each account move is redundant, creates overhead and poses a risk of desynchronization between analytic data and GL entries.
In such situations users are happy to do their analytics reporting on account move lines and don't need analytic entries.
This module disables the generation of analytic entries and related menus.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/87/9.0

.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example

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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account_analytic/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.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

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

* Thomas Binsfeld <[email protected]>

Maintainer
----------

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
1 change: 1 addition & 0 deletions account_analytic_no_lines/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions account_analytic_no_lines/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Account Analytic No Lines',
'summary': """
This module hides analytics lines from accounting menus and disable
their generation from an invoice or a move line.""",
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
'website': 'www.acsone.eu',
'depends': [
'account',
'analytic',
],
'data': [
'views/account_analytic_account.xml',
'data/data_account_analytic_group.xml',
'views/account_analytic.xml',
],
}
11 changes: 11 additions & 0 deletions account_analytic_no_lines/data/data_account_analytic_group.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Acsone SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="hide_analytic_entries" model="res.groups">
<field name="name">Hide Analytic Entries</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions account_analytic_no_lines/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_invoice
from . import account_move_line
17 changes: 17 additions & 0 deletions account_analytic_no_lines/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import api, models


class AccountInvoice(models.Model):

_inherit = 'account.invoice'

@api.multi
def finalize_invoice_move_lines(self, move_lines):
move_lines = super(AccountInvoice, self)\
.finalize_invoice_move_lines(move_lines)
move_lines[0][2].pop('analytic_line_ids')
return move_lines
14 changes: 14 additions & 0 deletions account_analytic_no_lines/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import api, models


class AccountMoveLine(models.Model):

_inherit = 'account.move.line'

@api.multi
def create_analytic_lines(self):
pass
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions account_analytic_no_lines/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_analytic_no_lines
115 changes: 115 additions & 0 deletions account_analytic_no_lines/tests/test_account_analytic_no_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests.common import SavepointCase


class TestAccountAnalyticNoLines(SavepointCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why SavepointCase instead of TransactionCase?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With SavepointCase, the setup is done once for all test cases and each test case is done in a transaction. I found it interesting here.


@classmethod
def setUpClass(cls):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self instead of cls as normal Python convention.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According PEP8, cls must be the first argument of a class method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@ThomasBinsfeld ThomasBinsfeld Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza In this case the overridden method is the classmethod setUpClass not the instance method setUp

https://github.com/odoo/odoo/blob/06754b3237a44d8ba2a18bf407a3e65447ca390c/openerp/tests/common.py#L181

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why are you using that one which is not the regular way? Please use standard methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. My confusion comes from using SavepointCase instead of TransactionCase. We can continue then with this (although in this case there's no performance improvement).
Sorry for the noise.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No stress 😏 Thank you to you for your investment in the reviewing process of so much PR!!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza @lmignon Actually, there are two tests, that's why I choosed to use SavepointCase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Another reason more! Forget my transient mental lapsus

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza Thanks for the review

super(TestAccountAnalyticNoLines, cls).setUpClass()

# ENVIRONMENTS

cls.account_account = cls.env['account.account']
cls.account_analytic_line = cls.env['account.analytic.line']
cls.account_journal = cls.env['account.journal']
cls.account_move_line = cls.env['account.move.line']
cls.account_invoice = cls.env['account.invoice']
cls.account_invoice_line = cls.env['account.invoice.line']

# INSTANCES

# Instance: user
cls.user = cls.env.ref('base.res_partner_2')

# Instance: accounts
cls.account_440000 = cls.account_account.create({
'name': 'Entreprises liées',
'code': '440000_demo',
'user_type_id':
cls.env.ref('account.data_account_type_payable').id,
'reconcile': True})
cls.account_550001 = cls.account_account.create({
'name': 'Banque',
'code': '550001_demo',
'user_type_id':
cls.env.ref('account.data_account_type_liquidity').id,
'reconcile': False})
cls.account_600000 = cls.account_account.create({
'name': 'Achats de matières premières',
'code': '600000_demo',
'user_type_id':
cls.env.ref('account.data_account_type_expenses').id,
'reconcile': False})

# Journal
cls.journal = cls.account_journal.create({
'name': 'Bank Journal Test',
'type': 'bank',
'code': 'BKTEST',
'default_debit_account_id': cls.account_550001.id,
'default_credit_account_id': cls.account_550001.id})

# Invoice lines
cls.invoice_line_1 = cls.account_invoice_line.create({
'name': 'Test invoice line 1',
'price_unit': 50,
'quantity': 2,
'account_id': cls.account_600000.id})
cls.invoice_line_2 = cls.account_invoice_line.create({
'name': 'Test invoice line 2',
'price_unit': 25,
'quantity': 2,
'account_id': cls.account_600000.id})
cls.invoice_line_3 = cls.account_invoice_line.create({
'name': 'Test invoice line 3',
'price_unit': 100,
'quantity': 1,
'account_id': cls.account_600000.id})

# Invoice
cls.invoice = cls.account_invoice.create({
'partner_id': cls.user.id,
'account_id': cls.account_440000.id,
'type': 'in_invoice',
'invoice_line_ids': [(6, 0, [cls.invoice_line_1.id,
cls.invoice_line_2.id,
cls.invoice_line_3.id])]})
cls.invoice.action_move_create()

def test_create_analytic_lines(self):
"""
Test the expected result when the method ´create_analytic_lines` is
called on an invoice.
The expected result is that no analytic line has been created
for this invoice.
"""
move_lines = self.account_move_line.search([
('invoice_id', '=', self.invoice.id)])
for line in move_lines:
line.create_analytic_lines()

analytic_lines =\
self.account_analytic_line.search([
('move_id', 'in', move_lines.ids)]).ids
self.assertFalse(analytic_lines)

def test_finalize_invoice_move_lines(self):
"""
Test the expected result when the method ´finalize_invoice_move_lines`
is called on an invoice.
The expected result is that no analytic line has been created
for this invoice.
"""
move_lines = self.account_move_line.search([('invoice_id',
'=',
self.invoice.id)])
self.invoice.action_move_create()
analytic_lines =\
self.account_analytic_line.search([('move_id',
'in',
move_lines.ids)]).ids
self.assertFalse(analytic_lines)
15 changes: 15 additions & 0 deletions account_analytic_no_lines/views/account_analytic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Acsone SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.menu" id="account.menu_action_analytic_lines_tree">
<field name="groups_id" eval="[(6,0,[ref('account_analytic_no_lines.hide_analytic_entries')])]"/>
</record>

<record model="ir.ui.menu" id="account.menu_action_analytic_account_tree2">
<field name="groups_id" eval="[(6,0,[ref('account_analytic_no_lines.hide_analytic_entries')])]"/>
</record>

</odoo>
35 changes: 35 additions & 0 deletions account_analytic_no_lines/views/account_analytic_account.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="account_analytic_account_form_view">
<field name="name">account.analytic.account.form (in account_analytic_no_lines)</field>
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']/button[@name=%(analytic.account_analytic_line_action)d]" position="attributes">
<attribute name="groups">account_analytic_no_lines.hide_analytic_entries</attribute>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="account_analytic_account_tree_view">
<field name="name">account.analytic.account.tree (in account_analytic_no_lines)</field>
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="analytic.view_account_analytic_account_list"/>
<field name="arch" type="xml">
<field name="debit" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="credit" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="balance" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions setup/account_analytic_no_lines/odoo_addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/account_analytic_no_lines/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)