Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] stock_account_operating_unit: Migration to 17.0 #725

Open
wants to merge 20 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions stock_account_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
=======================================
Stock account moves with Operating Unit
=======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4c1b8e31f015492e7d5387ff3f79eeb230a94add7a9e551203bc5cac586b2dfd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/17.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-17-0/operating-unit-17-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=17.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:%2017.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]>
- Daniel Herreros <[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/17.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": "17.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."
33 changes: 33 additions & 0 deletions stock_account_operating_unit/i18n/stock_account_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_account_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

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

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

#. 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 ""
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
126 changes: 126 additions & 0 deletions stock_account_operating_unit/model/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# © 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,
):
res = super()._generate_valuation_lines_data(
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
svl_id,
description,
)
if res:
debit_line_vals = res.get("debit_line_vals")
credit_line_vals = res.get("credit_line_vals")
price_diff_line_vals = res.get("price_diff_line_vals", {})

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(

Check warning on line 43 in stock_account_operating_unit/model/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_account_operating_unit/model/stock_move.py#L43

Added line #L43 was not covered by tests
_(
"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 = (

Check warning on line 52 in stock_account_operating_unit/model/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_account_operating_unit/model/stock_move.py#L52

Added line #L52 was not covered by tests
self.picking_id.picking_type_id.warehouse_id.operating_unit_id.id
)
else:
ou_id = False

debit_line_vals["operating_unit_id"] = (
ou_id or self.operating_unit_dest_id.id or self.operating_unit_id.id
)
credit_line_vals["operating_unit_id"] = (
ou_id or self.operating_unit_id.id or self.operating_unit_dest_id.id
)
rslt = {
"credit_line_vals": credit_line_vals,
"debit_line_vals": debit_line_vals,
}
if price_diff_line_vals:
price_diff_line_vals["operating_unit_id"] = (

Check warning on line 69 in stock_account_operating_unit/model/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_account_operating_unit/model/stock_move.py#L69

Added line #L69 was not covered by tests
ou_id or self.operating_unit_id.id or self.operating_unit_dest_id.id
)
rslt["price_diff_line_vals"] = price_diff_line_vals

Check warning on line 72 in stock_account_operating_unit/model/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_account_operating_unit/model/stock_move.py#L72

Added line #L72 was not covered by tests
return rslt
return res

Check warning on line 74 in stock_account_operating_unit/model/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_account_operating_unit/model/stock_move.py#L74

Added line #L74 was not covered by tests

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()._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(
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,
}
)
.with_company(move.location_id.company_id.id)
)
am.action_post()
return res
3 changes: 3 additions & 0 deletions stock_account_operating_unit/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
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.
5 changes: 5 additions & 0 deletions stock_account_operating_unit/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Eficent Business and IT Consulting Services S.L.
\<<[email protected]>\>
- Serpent Consulting Services Pvt. Ltd. \<<[email protected]>\>
- Jarsa Sistemas \<<[email protected]>\>
- Daniel Herreros \<<[email protected]>\>
4 changes: 4 additions & 0 deletions stock_account_operating_unit/readme/DESCRIPTION.md
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.md
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
Loading