Skip to content

Commit

Permalink
[ADD] test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
serpentcs-dev1 committed Jun 15, 2017
1 parent d1f2fc6 commit fdf0ea1
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion account_invoice_merge_operating_unit/README.rst
Expand Up @@ -6,7 +6,7 @@
Account Invoice Merge Operating Units
=====================================

This module adds operating unit to the new invoice if the merging invoices are belonging to the same Operating Unit.
This module adds Operating Unit to the new invoice ensuring that the invoices that are merged belongs to the same Operating Unit.


Usage
Expand Down
6 changes: 6 additions & 0 deletions account_invoice_merge_operating_unit/tests/__init__.py
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import test_account_invoice_merge_operating_unit
@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from openerp.tests import common
from openerp.exceptions import UserError


class TestInvoiceMergeOperatingUnit(common.TransactionCase):

def setUp(self):
super(TestInvoiceMergeOperatingUnit, self).setUp()
self.res_users_model = self.env['res.users']
self.invoice_model = self.env['account.invoice']

# company
self.company = self.env.ref('base.main_company')
self.grp_acc_manager = self.env.ref('account.group_account_manager')
# Main Operating Unit
self.ou1 = self.env.ref('operating_unit.main_operating_unit')
# B2B Operating Unit
self.b2b = self.env.ref('operating_unit.b2b_operating_unit')
# B2C Operating Unit
self.b2c = self.env.ref('operating_unit.b2c_operating_unit')
# Partner
self.partner1 = self.env.ref('base.res_partner_1')
# Products
self.product1 = self.env.ref('product.product_product_7')

# Create user1
self.user_id =\
self.res_users_model.with_context({'no_reset_password': True}).\
create({
'name': 'Test Account User',
'login': 'user_1',
'password': 'demo',
'email': 'example@yourcompany.com',
'company_id': self.company.id,
'company_ids': [(4, self.company.id)],
'operating_unit_ids': [(4, self.b2b.id), (4, self.b2c.id)],
'groups_id': [(6, 0, [self.grp_acc_manager.id])]
})

def _prepare_invoice(self, operating_unit_id, qty):
line_products = [(self.product1, qty)]
# Prepare invoice lines
lines = []
acc_type = self.env.ref('account.data_account_type_revenue')
for product, qty in line_products:
line_values = {
'name': product.name,
'product_id': product.id,
'quantity': qty,
'price_unit': 50,
'account_id': self.env['account.account'].search(
[('user_type_id', '=', acc_type.id)], limit=1).id
}
lines.append((0, 0, line_values))
inv_vals = {
'partner_id': self.partner1.id,
'account_id': self.partner1.property_account_receivable_id.id,
'operating_unit_id': operating_unit_id,
'name': "Test Supplier Invoice",
'reference_type': "none",
'type': 'out_invoice',
'invoice_line_ids': lines,
}
return inv_vals

def test_invoice_merge_with_opearting_unit(self):
"""Create the invoice and assert the value of
Operating Unit in the new Invoice.
"""
# Create invoice
self.invoice =\
self.invoice_model.sudo(self.user_id.id).create(
self._prepare_invoice(self.b2b.id, 10))

# Create second invoice with different quantity
self.invoice2 =\
self.invoice_model.sudo(self.user_id.id).create(
self._prepare_invoice(self.b2b.id, 20))

wiz_invoice_merge = self.env['invoice.merge'].\
with_context({'active_ids': [self.invoice.id, self.invoice2.id],
'active_model': 'account.invoice'})

action = wiz_invoice_merge.create({'keep_references': True}).\
merge_invoices()

invoices = self.env['account.invoice'].browse(action['domain'][0][2])
self.assertEqual(invoices[1].operating_unit_id,
invoices[2].operating_unit_id,
'Invoice should have Operating Unit')

def test_invoice_dirty_check_on_opearting_unit(self):
"""Creates the invoice and asserts that Operating Unit
of the invoice getting merged are same otherwise
raise an exception.
"""
# Create invoice
self.invoice =\
self.invoice_model.sudo(self.user_id.id).create(
self._prepare_invoice(self.b2b.id, 10))
# Create second invoice with different quantity
self.invoice2 =\
self.invoice_model.sudo(self.user_id.id).create(
self._prepare_invoice(self.b2c.id, 20))

# dirty check to assert similar Operating Unit in invoices

wiz_invoice_merge = self.env['invoice.merge'].\
with_context({'active_ids': [self.invoice.id,
self.invoice2.id],
'active_model': 'account.invoice'})

with self.assertRaises(UserError):

wiz_invoice_merge.create({'keep_references': True})._dirty_check()

0 comments on commit fdf0ea1

Please sign in to comment.