Skip to content

Commit

Permalink
Merge 290e3f7 into 90641e1
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Jul 25, 2017
2 parents 90641e1 + 290e3f7 commit f846415
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 0 deletions.
79 changes: 79 additions & 0 deletions stock_account_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
:alt: License: LGPL-3

=======================================
Stock account moves with Operating Unit
=======================================

This module introduces the following features:

- Creates account move lines when stock moves are posted between internal
locations within the same company, but different OU’s.


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

If your company is required to generate a balanced balance sheet by
operating unit you can specify at company level that operating units should
be self-balanced, and then indicate a self-balancing clearing account.

#. Create an account for "Inter-OU Clearing" of type Regular.
#. Go to *Settings / Companies / Configuration* and:

* Set the "Operating Units are self-balanced" checkbox.

* Set the "Inter-OU Clearing" account in "Inter-operating unit clearing
account" field.

#. Assign Operating Unit in Accounts.


Usage
=====

Create stock moves between internal locations within the same company, but
different OU’s. The journal entries are created and they are self-balanced
within the OU when the journal entries are posted

.. 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/10.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: http://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.
6 changes: 6 additions & 0 deletions stock_account_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import model
24 changes: 24 additions & 0 deletions stock_account_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Stock account moves with Operating Unit",
"summary": "Create journal entries in moves between internal locations "
"with different operating units.",
"version": "10.0.1.0.0",
"category": "Generic Modules/Sales & Purchases",
"author": "Eficent Business and IT Consulting Services S.L., "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/operating-unit",
"depends": [
'stock_operating_unit',
'account_operating_unit',
"stock_account"
],
"installable": True,
}
7 changes: 7 additions & 0 deletions stock_account_operating_unit/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import stock_move
from . import stock_quant
38 changes: 38 additions & 0 deletions stock_account_operating_unit/model/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp import _, api, exceptions, models


class StockMove(models.Model):
_inherit = "stock.move"

@api.model
def _prepare_account_move_line(self, qty, cost, credit_account_id,
debit_account_id):
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id)

debit_line_vals = res[0][2]
credit_line_vals = res[1][2]

if (
self.operating_unit_id and self.operating_unit_dest_id and
self.operating_unit_id != self.operating_unit_dest_id and
debit_line_vals['account_id'] != credit_line_vals['account_id']
):
raise exceptions.UserError(
_('You cannot create stock moves involving separate source '
'and destination accounts related to different operating '
'units.')
)

debit_line_vals['operating_unit_id'] = (
self.operating_unit_dest_id.id or self.operating_unit_id.id
)
credit_line_vals['operating_unit_id'] = (
self.operating_unit_id.id or self.operating_unit_dest_id.id
)
return [(0, 0, debit_line_vals), (0, 0, credit_line_vals)]
54 changes: 54 additions & 0 deletions stock_account_operating_unit/model/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp import api, models


class StockQuant(models.Model):
_inherit = 'stock.quant'

@api.multi
def _account_entry_move(self, move):
"""
Generate accounting moves if the product being moved is subject
to real_time valuation tracking,
and the source or destination location are
a transit location or is outside of the company or the source or
destination locations belong to different operating units.
"""
res = super(StockQuant, self)._account_entry_move(move)
if move.product_id.valuation == 'real_time':
# Inter-operating unit moves do not accept to
# from/to non-internal location
if (
move.location_id.company_id ==
move.location_dest_id.company_id and
move.operating_unit_id != move.operating_unit_dest_id
):
src_company_ctx = dict(
force_company=move.location_id.company_id.id
)
company_ctx = dict(company_id=move.company_id.id)
self = self.with_context(src_company_ctx)
(journal_id, acc_src, acc_dest, acc_valuation) = \
move._get_accounting_data_for_valuation()
quant_cost_qty = {}
for quant in self:
if quant_cost_qty.get(quant.cost):
quant_cost_qty[quant.cost] += quant.qty
else:
quant_cost_qty[quant.cost] = quant.qty
move_obj = self.env['account.move']
for cost, qty in quant_cost_qty.items():
move_lines = move._prepare_account_move_line(qty, cost,
acc_valuation,
acc_valuation)
move_obj.with_context(company_ctx).create({
'journal_id': journal_id,
'line_ids': move_lines,
'company_id': move.company_id.id,
'ref': move.picking_id and move.picking_id.name,
})
return res
6 changes: 6 additions & 0 deletions stock_account_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L. -
# Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_stock_account_operating_unit

0 comments on commit f846415

Please sign in to comment.