Skip to content

Commit

Permalink
[ADD] stock_account_operating_unit: Added module.
Browse files Browse the repository at this point in the history
  • Loading branch information
mibab.heli authored and atularvind committed Mar 12, 2024
1 parent c412f0a commit b977e2a
Show file tree
Hide file tree
Showing 16 changed files with 1,141 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_account_operating_unit/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
89 changes: 89 additions & 0 deletions stock_account_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
=======================================
Stock account moves with Operating Unit
=======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a38124f922bb2a69950258c32437d7b20e455604c772399f78e83bc2fc461d61
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/16.0/stock_account_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-stock_account_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

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.

**Table of contents**

.. contents::
:local:

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

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20stock_account_operating_unit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Eficent Business and IT Consulting Services S.L.
* Serpent Consulting Services Pvt. Ltd.

Contributors
~~~~~~~~~~~~

* Eficent Business and IT Consulting Services S.L. <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>
* Jarsa Sistemas <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/16.0/stock_account_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_account_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import model
19 changes: 19 additions & 0 deletions stock_account_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2019 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": "16.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,
}
38 changes: 38 additions & 0 deletions stock_account_operating_unit/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_account_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2022-03-14 11:17+0000\n"
"Last-Translator: Javier Colmenero <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: stock_account_operating_unit
#: code:addons/stock_account_operating_unit/model/stock_move.py:0
#, python-format
msgid "%s - OU Move"
msgstr "%s - movimiento unidad operacional"

#. module: stock_account_operating_unit
#: model:ir.model,name:stock_account_operating_unit.model_stock_move
msgid "Stock Move"
msgstr "Movimiento de stock"

#. module: stock_account_operating_unit
#: code:addons/stock_account_operating_unit/model/stock_move.py:0
#, python-format
msgid ""
"You cannot create stock moves involving separate source and destination "
"accounts related to different operating units."
msgstr ""
"No puedes crear movimientos de stock, involucrando distintos orígines y "
"destinos asociados a unidades operacionales diferentes."
2 changes: 2 additions & 0 deletions stock_account_operating_unit/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import stock_move
165 changes: 165 additions & 0 deletions stock_account_operating_unit/model/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, exceptions, models


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

def _generate_valuation_lines_data(
self,
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
svl_id,
description,
):
if not svl_id:
if (
self.operating_unit_id
and self.operating_unit_dest_id
and self.operating_unit_id != self.operating_unit_dest_id
and credit_account_id != debit_account_id
):
raise exceptions.UserError(
_(
"You cannot create stock moves involving separate source"
" and destination accounts related to different "
"operating units."
)
)

if not self.operating_unit_dest_id and not self.operating_unit_id:
ou_id = (
self.picking_id.picking_type_id.warehouse_id.operating_unit_id.id
)
else:
ou_id = False
# This method returns a dictionary to provide
# an easy extension hook to modify the valuation
# lines (see purchase for an example)
self.ensure_one()

line_vals = {
"name": description,
"product_id": self.product_id.id,
"quantity": qty,
"product_uom_id": self.product_id.uom_id.id,
"ref": description,
"partner_id": partner_id,
}

rslt = {
"credit_line_vals": {
**line_vals,
"balance": -credit_value,
"account_id": credit_account_id,
"operating_unit_id": ou_id
or self.operating_unit_id.id
or self.operating_unit_dest_id.id,
},
"debit_line_vals": {
**line_vals,
"balance": debit_value,
"account_id": debit_account_id,
"operating_unit_id": ou_id
or self.operating_unit_dest_id.id
or self.operating_unit_id.id,
},
}

if credit_value != debit_value:
# for supplier returns of product in average costing method, in anglo saxon mode
diff_amount = debit_value - credit_value
price_diff_account = self.env.context.get("price_diff_account")
if not price_diff_account:
raise exceptions.UserError(
_(
"Configuration error. Please configure the price "
"difference account on the product or its category "
"to process this operation."
)
)

rslt["price_diff_line_vals"] = {
"name": self.name,
"product_id": self.product_id.id,
"quantity": qty,
"product_uom_id": self.product_id.uom_id.id,
"balance": -diff_amount,
"ref": description,
"partner_id": partner_id,
"account_id": price_diff_account.id,
"operating_unit_id": ou_id
or self.operating_unit_id.id
or self.operating_unit_dest_id.id,
}
return rslt
return super(StockMove, self)._generate_valuation_lines_data(
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
svl_id,
description,
)

def _action_done(self, cancel_backorder=False):
"""
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(StockMove, self)._action_done(cancel_backorder)
for move in self:

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
and move.location_id.company_id == move.location_dest_id.company_id
and move.operating_unit_id != move.operating_unit_dest_id
):
(
journal_id,
acc_src,
acc_dest,
acc_valuation,
) = move._get_accounting_data_for_valuation()

move_lines = move._prepare_account_move_line(
move.product_qty,
move.product_id.standard_price,
acc_valuation,
acc_valuation,
False,
_("%s - OU Move") % move.product_id.display_name,
)
am = (
self.env["account.move"]
.with_context(
force_company=move.location_id.company_id.id,
company_id=move.company_id.id,
)
.create(
{
"journal_id": journal_id,
"line_ids": move_lines,
"company_id": move.company_id.id,
"ref": move.picking_id and move.picking_id.name,
"stock_move_id": move.id,
}
)
)
am._post()
return res
11 changes: 11 additions & 0 deletions stock_account_operating_unit/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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.
3 changes: 3 additions & 0 deletions stock_account_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Eficent Business and IT Consulting Services S.L. <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>
* Jarsa Sistemas <[email protected]>
4 changes: 4 additions & 0 deletions stock_account_operating_unit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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.
3 changes: 3 additions & 0 deletions stock_account_operating_unit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b977e2a

Please sign in to comment.