Skip to content

Commit

Permalink
[MIG] account_operating_unit: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alan196 authored and hbrunn committed Mar 14, 2024
1 parent b7839c1 commit 87fec2a
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 67 deletions.
10 changes: 5 additions & 5 deletions account_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Accounting with Operating Units
: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/14.0/account_operating_unit
:target: https://github.com/OCA/operating-unit/tree/15.0/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-14-0/operating-unit-14-0-account_operating_unit
:target: https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-account_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/213/14.0
:target: https://runbot.odoo-community.org/runbot/213/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -99,7 +99,7 @@ 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 <https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2015.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.

Expand Down Expand Up @@ -138,6 +138,6 @@ 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/14.0/account_operating_unit>`_ project on GitHub.
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/15.0/account_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Accounting with Operating Units",
"summary": "Introduces Operating Unit (OU) in invoices and "
"Accounting Entries with clearing account",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"author": "ForgeFlow, "
"Serpent Consulting Services Pvt. Ltd.,"
"WilldooIT Pty Ltd,"
Expand Down
1 change: 1 addition & 0 deletions account_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import res_company
from . import account_bank_statement
from . import account_journal
from . import account_move
from . import account_payment
20 changes: 20 additions & 0 deletions account_operating_unit/models/account_bank_statement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022 Jarsa
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, models


class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"

@api.model
def _prepare_liquidity_move_line_vals(self):
res = super()._prepare_liquidity_move_line_vals()
res["operating_unit_id"] = self.statement_id.journal_id.operating_unit_id.id
return res

@api.model
def _prepare_counterpart_move_line_vals(self, counterpart_vals, move_line=None):
res = super()._prepare_counterpart_move_line_vals(counterpart_vals, move_line)
res["operating_unit_id"] = self.statement_id.journal_id.operating_unit_id.id
return res
23 changes: 4 additions & 19 deletions account_operating_unit/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _prepare_inter_ou_balancing_move_line(self, move, ou_id, ou_balances):
)

res = {
"name": "OU-Balancing",
"name": _("OU-Balancing"),
"move_id": move.id,
"journal_id": move.journal_id.id,
"date": move.date,
Expand Down Expand Up @@ -220,24 +220,9 @@ def _check_journal_operating_unit(self):
and move.operating_unit_id
and move.operating_unit_id != move.journal_id.operating_unit_id
):
# Change journal_id if create move from other model. e.g., sale.order
if (
move._context.get("active_model")
and move._context.get("active_model") != "account.move"
):
move._onchange_operating_unit()
if (
move.journal_id.operating_unit_id
and move.operating_unit_id
and move.operating_unit_id != move.journal_id.operating_unit_id
):
raise UserError(
_("The OU in the Move and in Journal must be the same.")
)
else:
raise UserError(
_("The OU in the Move and in Journal must be the same.")
)
raise UserError(
_("The OU in the Move and in Journal must be the same.")
)
return True

@api.constrains("operating_unit_id", "company_id")
Expand Down
22 changes: 10 additions & 12 deletions account_operating_unit/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models
from odoo import fields, models


class AccountPayment(models.Model):
_inherit = "account.payment"

@api.depends("journal_id")
def _compute_operating_unit_id(self):
for payment in self:
if payment.journal_id:
payment.operating_unit_id = payment.journal_id.operating_unit_id

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
domain="[('user_ids', '=', uid)]",
Expand All @@ -22,14 +16,18 @@ def _compute_operating_unit_id(self):
)

def _prepare_move_line_default_vals(self, write_off_line_vals=None):
res = super()._prepare_move_line_default_vals(write_off_line_vals)
for line in res:
lines = super()._prepare_move_line_default_vals(write_off_line_vals)
for line in lines:
line["operating_unit_id"] = self.operating_unit_id.id
invoices = self.env["account.move"].browse(self._context.get("active_ids"))
if not self._context.get("active_model"):
return lines
invoices = self.env[self._context.get("active_model")].browse(
self._context.get("active_ids")
)
invoices_ou = invoices.operating_unit_id
if invoices and len(invoices_ou) == 1 and invoices_ou != self.operating_unit_id:
destination_account_id = self.destination_account_id.id
for line in res:
for line in lines:
if line["account_id"] == destination_account_id:
line["operating_unit_id"] = invoices_ou.id
return res
return lines
8 changes: 4 additions & 4 deletions account_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Accounting with Operating Units</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Accounting with Operating Units</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/operating-unit/tree/14.0/account_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/operating-unit-14-0/operating-unit-14-0-account_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/213/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/account_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-account_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/213/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows a company to manage the accounting based on Operating
Units (OU’s).</p>
<ul class="simple">
Expand Down Expand Up @@ -453,7 +453,7 @@ <h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -486,7 +486,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/14.0/account_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/account_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
11 changes: 4 additions & 7 deletions account_operating_unit/tests/test_account_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def setUp(self):
)

# Create user1
self.user_id = self.res_users_model.with_context(
{"no_reset_password": True}
).create(
self.user_id = self.res_users_model.with_context(no_reset_password=True).create(
{
"name": "Test Account User",
"login": "user_1",
Expand Down Expand Up @@ -91,7 +89,7 @@ def setUp(self):

# Create user2
self.user2_id = self.res_users_model.with_context(
{"no_reset_password": True}
no_reset_password=True
).create(
{
"name": "Test Account User",
Expand Down Expand Up @@ -121,20 +119,19 @@ def setUp(self):
self.cash_journal_ou1 = self.journal_model.create(
{
"name": "Cash Journal 1 - Test",
"code": "test_cash_1",
"code": "cash1",
"type": "cash",
"company_id": self.company.id,
"default_account_id": self.cash1_account_id.id,
"operating_unit_id": self.ou1.id,
}
)

# Create a cash account 2
user_type = self.env.ref("account.data_account_type_liquidity")
self.cash2_account_id = self.account_model.create(
{
"name": "Cash 2 - Test",
"code": "test_cash_2",
"code": "cash2",
"user_type_id": user_type.id,
"company_id": self.company.id,
}
Expand Down
28 changes: 9 additions & 19 deletions account_operating_unit/tests/test_payment_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def test_payment_from_invoice(self):

# Pay the invoice using a cash journal associated to the main company
ctx = {"active_model": "account.move", "active_ids": [self.invoice.id]}
register_payments = self.register_payments_model.with_context(ctx).create(
register_payments = self.register_payments_model.with_context(**ctx).create(
{
"payment_date": time.strftime("%Y") + "-07-15",
"journal_id": self.cash_journal_ou1.id,
"payment_method_id": self.payment_method_manual_in.id,
"payment_method_line_id": self.payment_method_manual_in.id,
}
)

Expand Down Expand Up @@ -53,11 +53,11 @@ def test_payment_from_two_invoices(self):

# Pay the invoices using a cash journal associated to the main company
ctx = {"active_model": "account.move", "active_ids": invoices.ids}
register_payments = self.register_payments_model.with_context(ctx).create(
register_payments = self.register_payments_model.with_context(**ctx).create(
{
"payment_date": time.strftime("%Y") + "-07-15",
"journal_id": self.cash_journal_ou1.id,
"payment_method_id": self.payment_method_manual_in.id,
"payment_method_line_id": self.payment_method_manual_in.id,
}
)

Expand All @@ -73,30 +73,20 @@ def test_payment_from_two_invoices(self):

def test_payment_transfer(self):
"""Create a transfer payment with journals in different OU"""

payments = self.payment_model.create(
payment = self.payment_model.create(
{
"payment_type": "outbound",
"amount": 115000,
"date": time.strftime("%Y") + "-07-15",
"journal_id": self.cash_journal_ou1.id,
"destination_journal_id": self.cash2_journal_b2b.id,
"destination_account_id": self.company.transfer_account_id.id,
"payment_method_id": self.payment_method_manual_in.id,
"is_internal_transfer": True,
}
)
payments |= self.payment_model.create(
{
"payment_type": "inbound",
"amount": 115000,
"date": time.strftime("%Y") + "-07-15",
"journal_id": self.cash2_journal_b2b.id,
"destination_account_id": self.company.transfer_account_id.id,
"payment_method_id": self.payment_method_manual_in.id,
"payment_method_line_id": self.payment_method_manual_in.id,
"is_internal_transfer": True,
}
)
payments.action_post()
payment.action_post()
payments = payment + payment.paired_internal_transfer_payment_id
self.assertEqual(len(payments.move_id.mapped("line_ids.operating_unit_id")), 2)
# Validate that every move has their correct OU
for move in payments.move_id:
Expand Down

0 comments on commit 87fec2a

Please sign in to comment.