Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] analytic_partner_hr_timesheet_invoice: Migration to 10.0
- Loading branch information
1 parent
827b3f5
commit c32b357
Showing
8 changed files
with
149 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
77 changes: 0 additions & 77 deletions
77
analytic_partner_hr_timesheet_invoice/models/account_analytic_line.py
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
analytic_partner_hr_timesheet_invoice/models/sale_order_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
117 changes: 68 additions & 49 deletions
117
analytic_partner_hr_timesheet_invoice/tests/test_analytic_partner_hr_timesheet_invoice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |