Skip to content

Commit

Permalink
Merge fdf0ea1 into f6e6e10
Browse files Browse the repository at this point in the history
  • Loading branch information
serpentcs-dev1 committed Jun 15, 2017
2 parents f6e6e10 + fdf0ea1 commit 3fdec55
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 0 deletions.
54 changes: 54 additions & 0 deletions account_invoice_merge_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
:alt: License: LGPL-3

=====================================
Account Invoice Merge Operating Units
=====================================

This module adds Operating Unit to the new invoice ensuring that the invoices that are merged belongs to the same Operating Unit.


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/213/9.0

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

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

* Eficent Business and IT Consulting Services S.L. <contact@eficent.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>

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.
7 changes: 7 additions & 0 deletions account_invoice_merge_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- 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 models
from . import wizard
22 changes: 22 additions & 0 deletions account_invoice_merge_operating_unit/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- 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).

{
'name': "Account Invoice Merge Operating Unit",
'author': "Eficent Business and IT Consulting Services, S.L.,"
"Odoo Community Association (OCA)",
'website': "http://www.eficent.com",
'category': 'Finance',
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'account_invoice_merge',
'account_operating_unit',
],
'data': [
'wizard/invoice_merge_view.xml',
],
'auto_install': True,
}
6 changes: 6 additions & 0 deletions account_invoice_merge_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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 account_invoice
22 changes: 22 additions & 0 deletions account_invoice_merge_operating_unit/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- 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 import api, models


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

@api.model
def _get_invoice_key_cols(self):
res = super(AccountInvoice, self)._get_invoice_key_cols()
res.append('operating_unit_id')
return res

@api.model
def _get_first_invoice_fields(self, invoice):
res = super(AccountInvoice, self)._get_first_invoice_fields(invoice)
res.update({'operating_unit_id': invoice.operating_unit_id.id})
return res
6 changes: 6 additions & 0 deletions account_invoice_merge_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions account_invoice_merge_operating_unit/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -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 invoice_merge
24 changes: 24 additions & 0 deletions account_invoice_merge_operating_unit/wizard/invoice_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- 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 import api, models, _
from openerp.exceptions import Warning as UserError


class InvoiceMerge(models.TransientModel):
_inherit = "invoice.merge"

@api.model
def _dirty_check(self):
res = super(InvoiceMerge, self)._dirty_check()
if self.env.context.get('active_model', '') == 'account.invoice':
ids = self.env.context['active_ids']

invs = self.env['account.invoice'].browse(ids)
for d in invs:
if d['operating_unit_id'] != invs[0]['operating_unit_id']:
raise UserError(
_('Not all invoices are at the same Operating Unit!'))
return res
31 changes: 31 additions & 0 deletions account_invoice_merge_operating_unit/wizard/invoice_merge_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_invoice_merge_ou" model="ir.ui.view">
<field name="name">Merger Partner Invoice OU</field>
<field name="model">invoice.merge</field>
<field name="inherit_id" ref="account_invoice_merge.view_invoice_merge"/>
<field name="priority" eval="16"/>
<field name="arch" type="xml">
<xpath expr="//form/group/p[1]" position="replace">
<p>
Please note that:
<br/><br/>
Invoices will only be merged if:
<br/>
* Invoices are in draft
<br/>
* Invoices belong to the same partner
<br/>
* Invoices are have same company, operating unit, partner, address, currency, journal, salesman, account, type
<br/><br/>
Lines will only be merged if:
<br/>
* Invoice lines are exactly the same except for the product,quantity and unit
<br/>
</p>
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
account-invoicing
purchase-workflow

0 comments on commit 3fdec55

Please sign in to comment.