-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] : Added stock_account OU module
[ADD] : Added Test Cases. [IMP] : Improved code for test cases [IMP] Migrated Valuation method of quants. [IMP] Migrated Valuation method _account_entry_move of quants. [UPT] migrate code and minor fixes [FIX] account move lines were not being correctly linked to the account move
- Loading branch information
1 parent
64d97d2
commit d67bfeb
Showing
7 changed files
with
544 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
.. 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/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: 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. |
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,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 |
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,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": "9.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": "http://www.eficent.com", | ||
"depends": [ | ||
'stock_operating_unit', | ||
'account_operating_unit', | ||
"stock_account" | ||
], | ||
"installable": 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 |
---|---|---|
@@ -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 stock |
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,100 @@ | ||
# -*- 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 StockQuant(models.Model): | ||
_inherit = 'stock.quant' | ||
|
||
@api.model | ||
def _prepare_account_move_line(self, move, qty, cost, credit_account_id, | ||
debit_account_id): | ||
res = super(StockQuant, self)._prepare_account_move_line( | ||
move, qty, cost, credit_account_id, debit_account_id | ||
) | ||
|
||
debit_line_vals = res[0][2] | ||
credit_line_vals = res[1][2] | ||
|
||
if ( | ||
move.operating_unit_id and move.operating_unit_dest_id and | ||
move.operating_unit_id != move.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'] = ( | ||
move.operating_unit_dest_id.id or move.operating_unit_id.id | ||
) | ||
credit_line_vals['operating_unit_id'] = ( | ||
move.operating_unit_id.id or move.operating_unit_dest_id.id | ||
) | ||
return [(0, 0, debit_line_vals), (0, 0, credit_line_vals)] | ||
|
||
@api.model | ||
def _account_entry_move(self, quants, move): | ||
""" | ||
Generate an 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(quants, 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 | ||
): | ||
err = False | ||
if (move.location_id.usage != 'internal' and | ||
move.location_dest_id.usage == 'internal'): | ||
err = True | ||
if (move.location_id.usage == 'internal' and | ||
move.location_dest_id.usage != 'internal'): | ||
err = True | ||
if (move.location_id.usage != 'internal' and | ||
move.location_dest_id.usage != 'internal'): | ||
err = True | ||
if err: | ||
raise exceptions.UserError( | ||
_('Transfers between locations of different operating ' | ||
'unit locations is only allowed when both source ' | ||
'and destination locations are internal.') | ||
) | ||
src_company_ctx = dict( | ||
force_company=move.location_id.company_id.id | ||
) | ||
company_ctx = dict(company_id=move.company_id.id) | ||
self_c = self.with_context(src_company_ctx) | ||
data = self_c._get_accounting_data_for_valuation(move) | ||
(journal_id, acc_src, acc_dest, acc_valuation) = data | ||
quant_cost_qty = {} | ||
for quant in quants: | ||
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 = self._prepare_account_move_line(move, 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 |
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,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 |
Oops, something went wrong.