Skip to content

Commit

Permalink
[MIG] analytic_partner_hr_timesheet_invoice: Migration to 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luismontalba committed Jun 27, 2017
1 parent 827b3f5 commit c32b357
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 169 deletions.
54 changes: 23 additions & 31 deletions analytic_partner_hr_timesheet_invoice/README.rst
Expand Up @@ -14,68 +14,60 @@ Installation
============

This module is auto-installed by Odoo when *analytic_partner* and
*hr_timesheet_invoice* are installed.

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

You have to set the "Analytic Accounting" permission at user or db level for
seeing the analytic lines.
*analytic_partner_hr_timesheet* are installed.

Usage
=====

Go to Accounting > Journal entries > Analytic Journal Items, and selecting some
of the lines, click on *More > Create Invoice*. Created invoice(s) will be
split by the other partner field (if any), or the analytic account partner.
Go to *Sales > Invoicing > Sales to invoice* and select some of the lines,
click on *Action > Invoice Order*.
Created invoice(s) will be split by the other partner field (if any), or the
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 fully overwrites invoicing technical method
(*invoice_cost_create*), so it's incompatible with other modules that also
change something in the same method. If some hooks are provided on Odoo,
this module can be changed for respecting inheritance chain.

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
`here <https://github.com/OCA/account-analytic/issues/new?body=module:%20analytic_partner_hr_timesheet_invoice%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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 smash it by providing detailed and welcomed feedback.

Credits
=======

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

* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Rafael Blasco <rafabn@antiun.com>

Icon
----
Images
------

* Thanks to https://openclipart.org/detail/201137/primary%20template%20invoice
* Thanks to https://openclipart.org/detail/15193/Arrow%20set%20%28Comic%29
* Original Odoo icons
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

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

* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Luis M. Ontalba <luis.martinez@tecnativa.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
: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 http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.
2 changes: 1 addition & 1 deletion analytic_partner_hr_timesheet_invoice/__init__.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
17 changes: 9 additions & 8 deletions analytic_partner_hr_timesheet_invoice/__manifest__.py
@@ -1,23 +1,24 @@
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# Copyright 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# Copyright 2017 Tecnativa, S.L. - Luis M. Ontalba
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': 'Invoice to the partner in analytic lines',
'version': '8.0.1.0.0',
'name': 'Invoice to the other partner',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'summary': 'Invoice analytic lines for the specific partner in them',
'summary': 'Invoice analytic lines for the other partner',
'category': 'Human Resources',
'author': 'Antiun Ingeniería S.L., '
'Serv. Tecnol. Avanzados - Pedro M. Baeza, '
'author': 'Antiun Ingeniería, '
'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'http://www.antiun.com',
'depends': [
'analytic_partner_hr_timesheet',
'analytic_partner',
'hr_timesheet_invoice',
],
'data': [
],
'installable': False,
'installable': True,
"auto_install": True,
}
4 changes: 2 additions & 2 deletions analytic_partner_hr_timesheet_invoice/models/__init__.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import account_analytic_line

from . import sale_order_line

This file was deleted.

45 changes: 45 additions & 0 deletions analytic_partner_hr_timesheet_invoice/models/sale_order_line.py
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa, S.L. - Pedro M. Baeza, Luis M. Ontalba
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

@api.multi
def _compute_analytic(self, domain=None):
"""Split by partner of the lines to filter only affected analytic
lines.
"""
for partner in self.mapped('order_partner_id'):
so_lines = self.filtered(lambda x: x.order_partner_id == partner)
if not domain:
# To filter on analyic lines linked to an expense
expense_type_id = self.env.ref(
'account.data_account_type_expenses',
raise_if_not_found=False)
expense_type_id = expense_type_id and expense_type_id.id
domain = [
('so_line', 'in', self.ids),
'|',
('amount', '<', 0),
'&',
('amount', '=', 0),
'|',
('move_id', '=', False),
('move_id.account_id.user_type_id', '=', expense_type_id)
]
partner_domain = list(domain) # make a copy of the domain
partner_domain += [
'|',
('other_partner_id', '=', partner.id),
('other_partner_id', '=', False),
'|',
('partner_id', '=', partner.id),
('partner_id', '=', False),
]
super(SaleOrderLine, so_lines)._compute_analytic(
domain=partner_domain,
)
2 changes: 1 addition & 1 deletion analytic_partner_hr_timesheet_invoice/tests/__init__.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import test_analytic_partner_hr_timesheet_invoice
@@ -1,57 +1,76 @@
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# Copyright 2017 Tecnativa, S.L. - Luis M. Ontalba
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import openerp.tests.common as common
from openerp import fields

import odoo.tests.common as common
from odoo import fields
from datetime import timedelta, datetime

class TestAnalyticPartnerHrTimesheetInvoice(common.TransactionCase):

def setUp(self):
super(TestAnalyticPartnerHrTimesheetInvoice, self).setUp()
self.partner = self.env.ref('base.res_partner_1')
self.other_partner = self.env.ref('base.res_partner_3')
self.analytic_account = self.env['account.analytic.account'].create(
{'name': 'Test Analytic Account',
'state': 'draft',
'partner_id': self.partner.id,
'pricelist_id': self.env.ref('product.list0').id,
'to_invoice': self.env.ref(
'hr_timesheet_invoice.timesheet_invoice_factor1').id,
'type': 'normal'}
)
self.analytic_line_model = self.env['account.analytic.line']
self.analytic_line_1 = self.analytic_line_model.create(
{'name': 'Test for other partner',
'account_id': self.analytic_account.id,
'unit_amount': 1.0,
'amount': 100.0,
'date': fields.Date.today(),
'general_account_id': self.env.ref('account.a_recv').id,
'journal_id': self.env.ref('account.analytic_journal_sale').id,
'to_invoice': self.analytic_account.to_invoice.id,
'other_partner_id': self.other_partner.id})
self.analytic_line_2 = self.analytic_line_model.create(
{'name': 'Test for account partner',
'account_id': self.analytic_account.id,
'unit_amount': 1.0,
'amount': 200.0,
'date': fields.Date.today(),
'general_account_id': self.env.ref('account.a_recv').id,
'journal_id': self.env.ref('account.analytic_journal_sale').id,
'to_invoice': self.analytic_account.to_invoice.id})
class TestAnalyticPartnerHrTimesheetInvoice(common.SavepointCase):

def test_invoices_split_by_partner(self):
lines = self.analytic_line_1 + self.analytic_line_2
invoices = lines.invoice_cost_create()
self.assertEqual(len(invoices), 2, "Invoices has not been split")
@classmethod
def setUpClass(cls):
super(TestAnalyticPartnerHrTimesheetInvoice, cls).setUpClass()
cls.order_partner = cls.env['res.partner'].create({
'name': 'Test Order Partner',
})
cls.category = cls.env['product.category'].create({
'name': 'Test Product Category',
})
cls.product = cls.env['product.product'].create({
'name': 'Test Product',
'sale_ok': True,
'type': 'service',
'categ_id': cls.category.id,
'invoice_policy': 'order',
'track_service': 'task',
})
cls.sale_order_vals = [
(0, 0, {
'product_id': cls.product.id,
'name': 'Test Sale order Line',
'product_uom_qty': 100.0,
'price_unit': 50.00,
})
]
cls.sale_order = cls.env['sale.order'].create({
'name': 'Test Sale Order',
'partner_id': cls.order_partner.id,
'order_line': cls.sale_order_vals,
})
cls.sale_order.action_confirm()
cls.task = cls.env['project.task'].search(
[('sale_line_id.id', '=', cls.sale_order.order_line[0].id)])
cls.date_time = fields.Datetime.to_string(
datetime.now() - timedelta(hours=1))
cls.user = cls.env.user
cls.analytic_account = cls.env['account.analytic.account'].create({
'name': 'Test Analytic Account',
})
cls.analytic_line_1 = cls.env['account.analytic.line'].create({
'date': cls.date_time,
'user_id': cls.env.user.id,
'name': 'Test Analytic line 1',
'account_id': cls.analytic_account.id,
'task_id': cls.task.id,
'unit_amount': 10.0,
})
cls.analytic_line_2 = cls.env['account.analytic.line'].create({
'date': cls.date_time,
'user_id': cls.env.user.id,
'name': 'Test Analytic line 2',
'account_id': cls.analytic_account.id,
'task_id': cls.task.id,
'unit_amount': 10.0,
})

def test_partner_invoice_1(self):
invoice_id = self.analytic_line_1.invoice_cost_create()[0]
def test_global(self):
self.analytic_line_1.other_partner_id = self.order_partner.id
self.analytic_line_1.partner_id = False
self.analytic_line_2.other_partner_id = False
self.analytic_line_1.partner_id = self.order_partner.id
invoice_id = self.sale_order.action_invoice_create()
invoice = self.env['account.invoice'].browse(invoice_id)
self.assertEqual(invoice.partner_id, self.other_partner)

def test_partner_invoice_2(self):
invoice_id = self.analytic_line_2.invoice_cost_create()[0]
invoice = self.env['account.invoice'].browse(invoice_id)
self.assertEqual(invoice.partner_id, self.partner)
self.assertEqual(invoice.partner_id, self.order_partner)
self.assertEqual(invoice.amount_untaxed, 5000)

0 comments on commit c32b357

Please sign in to comment.