Navigation Menu

Skip to content

Commit

Permalink
[MIG] analytic_account: Migrated to 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luismontalba committed Jun 16, 2017
1 parent e25a3a3 commit c9d2b17
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 135 deletions.
43 changes: 32 additions & 11 deletions analytic_partner/README.rst
@@ -1,46 +1,67 @@
.. 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

==================================
Classify analytic items by partner
==================================

This module adds a partner on each analytic item for allowing to have another
dimension for analysing data.
This module adds a commercial partner on each analytic item for allowing to
have another dimension for data analysis.

It also handles the proper propagation of this field to the created analytic
entries when validating invoices.

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

You have to be granted as at least "Accountant" in your user profile and
You have to be granted as at least "Adviser" in your user profile and
have checked the "Analytic Accounting" access right.

Usage
=====

Go to Accounting > Analytic Journal Items, and there, you can set the partner
for the analytic items, and search or group by it.
#. Go to *Invoicing > Adviser > Analytic Entries*.
#. Set the *other partner* in the form view of an the analytic entry.
#. Go back to list view where you can search or group by this new field.

You can also go to a partner, and click on the smart-button "Cost/Revenue",
placed on the upper-right part, and you will navigate to the analytic items
associated to this partner.
You can also:

#. Go to the form view of one of the partners selected as "other partner".
#. Click on the smart-button *Cost/Revenue* placed on the upper-right part.
#. Navigate to the analytic items associated to this partner.

.. 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/8.0
:target: https://runbot.odoo-community.org/runbot/87/10.0

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

* This module hasn't been tested with *account_analytic_plans* module
installed, so maybe it's incompatible with it.
This module hasn't been tested with *account_analytic_distribution* module
installed, so maybe it's incompatible with it.

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
------------

* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Luis M. Ontalba <luis.martinez@tecnativa.com>

Maintainer
----------
Expand Down
14 changes: 7 additions & 7 deletions analytic_partner/__manifest__.py
Expand Up @@ -3,21 +3,21 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': 'Partner in analytics',
'version': '8.0.1.0.0',
'summary': 'Classify analytic entries by partner',
'name': 'Link analytic items and partner',
'summary': 'Search and group analytic entries by partner',
'version': '10.0.1.0.0',
'category': 'Analytic Accounting',
'author': 'Serv. Tecnol. Avanzados - Pedro M. Baeza, '
'website': 'https://www.tecnativa.com',
'author': 'Tecnativa, '
'Antiun Ingeniería S.L., '
'Odoo Community Association (OCA)',
'website': 'http://www.serviciosbaeza.com',
'license': 'AGPL-3',
'installable': True,
'depends': [
'analytic',
'account',
],
'data': [
'views/account_analytic_line_views.xml',
'views/res_partner_views.xml',
],
'installable': False,
}
1 change: 0 additions & 1 deletion analytic_partner/models/__init__.py
Expand Up @@ -2,5 +2,4 @@
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import account_analytic_line
from . import account_invoice
from . import account_move_line
5 changes: 1 addition & 4 deletions analytic_partner/models/account_analytic_line.py
@@ -1,15 +1,12 @@
# -*- coding: utf-8 -*-
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, fields
from odoo import fields, models


class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'

partner_id = fields.Many2one(
comodel_name='res.partner', string="Account Partner",
related="account_id.partner_id", readonly=True, store=True)
other_partner_id = fields.Many2one(
comodel_name='res.partner', string="Other Partner",
domain="['|', ('parent_id', '=', False), ('is_company', '=', True)]")
18 changes: 0 additions & 18 deletions analytic_partner/models/account_invoice.py

This file was deleted.

12 changes: 6 additions & 6 deletions analytic_partner/models/account_move_line.py
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, api
from odoo import api, models


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

@api.model
def _prepare_analytic_line(self, obj_line):
res = super(AccountMoveLine, self)._prepare_analytic_line(obj_line)
res['other_partner_id'] = (
obj_line.invoice.partner_id.commercial_partner_id.id)
@api.multi
def _prepare_analytic_line(self):
res = super(AccountMoveLine, self)._prepare_analytic_line()
res[0]['other_partner_id'] = \
self.invoice_id.partner_id.commercial_partner_id.id
return res
65 changes: 38 additions & 27 deletions analytic_partner/tests/test_analytic_partner.py
@@ -1,38 +1,49 @@
# -*- coding: utf-8 -*-
# (c) 2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import openerp.tests.common as common
from openerp import workflow
import odoo.tests.common as common


class TestAnalyticPartner(common.TransactionCase):
class TestAnalyticPartner(common.SavepointCase):

def setUp(self):
super(TestAnalyticPartner, self).setUp()
product = self.env.ref('product.product_product_5')
self.analytic_account = self.env['account.analytic.account'].create(
{'name': 'Test Analytic Account',
'state': 'draft',
'type': 'normal'}
)
self.invoice = self.env['account.invoice'].create(
{'journal_id': self.env.ref('account.sales_journal').id,
'partner_id': self.env.ref('base.res_partner_3').id,
'account_id': self.env.ref('account.a_recv').id,
'invoice_line': [
(0, 0, {'product_id': product.id,
'name': 'Test',
'account_analytic_id': self.analytic_account.id,
'quantity': 10.0,
})],
})
workflow.trg_validate(self.uid, 'account.invoice', self.invoice.id,
'invoice_open', self.cr)
@classmethod
def setUpClass(cls):
super(TestAnalyticPartner, cls).setUpClass()
cls.partner = cls.env['res.partner'].create({
'name': 'Test partner',
})
cls.account_type = cls.env['account.account.type'].create({
'name': 'Test account type',
'type': 'other',
})
cls.account = cls.env['account.account'].create({
'name': 'Test account',
'code': 'TEST',
'user_type_id': cls.account_type.id
})
cls.analytic_account = cls.env['account.analytic.account'].create({
'name': 'Test Analytic Account',
})
cls.invoice = cls.env['account.invoice'].create({
'partner_id': cls.partner.id,
'invoice_line_ids': [
(0, 0, {
'name': 'Test line',
'account_id': cls.account.id,
'account_analytic_id': cls.analytic_account.id,
'quantity': 10.0,
'price_unit': 50.0,
})
]
})

def test_partner_from_invoice(self):
analytic_lines = self.invoice.move_id.mapped('line_id.analytic_lines')
def test_flow(self):
self.invoice.action_invoice_open()
analytic_lines = self.invoice.move_id.mapped(
'line_ids.analytic_line_ids')
for analytic_line in analytic_lines:
self.assertEqual(
analytic_line.other_partner_id,
self.invoice.partner_id.commercial_partner_id,
'Invoice partner has not been propagated to the analytic line')
'''Invoice partner has not been propagated
to the analytic line''')
70 changes: 35 additions & 35 deletions analytic_partner/views/account_analytic_line_views.xml
@@ -1,42 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>

<record model="ir.ui.view" id="view_account_analytic_line_tree_partner">
<field name="name">Analytic entries tree (with partner)</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="account.view_account_analytic_line_tree" />
<field name="arch" type="xml">
<field name="journal_id" position="after">
<field name="partner_id"/>
<field name="other_partner_id"/>
</field>
<record model="ir.ui.view" id="view_account_analytic_line_tree">
<field name="name">Analytic entries tree (with partner)</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id"
ref="analytic.view_account_analytic_line_tree" />
<field name="arch" type="xml">
<field name="account_id" position="after">
<field name="partner_id"/>
<field name="other_partner_id"/>
</field>
</record>
</field>
</record>

<record model="ir.ui.view" id="view_account_analytic_line_form_partner">
<field name="name">Analytic entries form (with partner)</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="account.view_account_analytic_line_form" />
<field name="arch" type="xml">
<field name="ref" position="after">
<field name="partner_id"/>
<field name="other_partner_id"/>
</field>
<record model="ir.ui.view" id="view_account_analytic_line_form">
<field name="name">Analytic entries form (with partner)</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id"
ref="analytic.view_account_analytic_line_form" />
<field name="arch" type="xml">
<field name="account_id" position="after">
<field name="other_partner_id"/>
</field>
</record>
</field>
</record>

<record model="ir.ui.view" id="view_account_analytic_line_filter_partner">
<field name="name">Analytic entries search (with partner)</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="account.view_account_analytic_line_filter" />
<field name="arch" type="xml">
<filter name="group_journal" position="after">
<filter name="group_account_partner" string="Account Partner" context="{'group_by': 'partner_id'}"/>
<filter name="group_partner" string="Other Partner" context="{'group_by': 'other_partner_id'}"/>
</filter>
</field>
</record>
<record model="ir.ui.view" id="view_account_analytic_line_filter">
<field name="name">Analytic entries search (with partner)</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id"
ref="analytic.view_account_analytic_line_filter" />
<field name="arch" type="xml">
<filter name="group_date" position="after">
<filter name="group_other_partner" string="Other Partner"
context="{'group_by': 'other_partner_id'}"/>
</filter>
</field>
</record>

</data>
</openerp>
</odoo>
51 changes: 25 additions & 26 deletions analytic_partner/views/res_partner_views.xml
@@ -1,30 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>

<record model="ir.actions.act_window" id="act_analytic_cost_revenue">
<field name="context">{'search_default_group_date': 1, 'search_default_group_journal': 1, 'default_other_partner_id': active_id}</field>
<field name="domain">[('other_partner_id', 'child_of', active_id)]</field>
<field name="name">Costs &amp; Revenues</field>
<field name="res_model">account.analytic.line</field>
<field name="src_model">res.partner</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
</record>
<record model="ir.actions.act_window" id="act_analytic_cost_revenue">

<record id="view_partner_form_analytic" model="ir.ui.view">
<field name="name">res.partner.form.analytic</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr='//div[@name="buttons"]' position='inside'>
<button class="oe_inline oe_stat_button"
type="action"
name="%(act_analytic_cost_revenue)d"
icon="fa-usd" string="Cost/Revenue" widget="statinfo"/>
</xpath>
</field>
</record>
<field name="context">{'search_default_group_date': 1}</field>
<field name="domain">[('other_partner_id', 'child_of', active_id)]</field>
<field name="name">Costs &amp; Revenues</field>
<field name="res_model">account.analytic.line</field>
<field name="src_model">res.partner</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
</record>

</data>
</openerp>
<record id="view_partner_form_analytic" model="ir.ui.view">
<field name="name">res.partner.form.analytic</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr='//div[@name="button_box"]' position='inside'>
<button class="oe_inline oe_stat_button"
type="action"
name="%(act_analytic_cost_revenue)d"
icon="fa-usd" string="Cost/Revenue" widget="statinfo"/>
</xpath>
</field>
</record>

</odoo>

0 comments on commit c9d2b17

Please sign in to comment.