Skip to content

Commit

Permalink
[FIX] move classes to their canonical files
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Jul 18, 2024
1 parent 1e2ee21 commit c4c4c8e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
3 changes: 2 additions & 1 deletion account_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 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_bank_statement_line
from . import account_journal
from . import account_move
from . import account_move_line
from . import account_partial_reconcile
from . import account_payment
50 changes: 0 additions & 50 deletions account_operating_unit/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,6 @@
from odoo.exceptions import UserError


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("move_id", False):
move = self.env["account.move"].browse(vals["move_id"])
if move.operating_unit_id:
vals["operating_unit_id"] = move.operating_unit_id.id
return super().create(vals_list)

@api.constrains("operating_unit_id", "company_id")
def _check_company_operating_unit(self):
for rec in self:
if (
rec.company_id
and rec.operating_unit_id
and rec.company_id != rec.operating_unit_id.company_id
):
raise UserError(
_(
"Configuration error. The Company in the"
" Move Line and in the Operating Unit must "
"be the same."
)
)

@api.constrains("operating_unit_id", "move_id")
def _check_move_operating_unit(self):
for rec in self:
if (
rec.move_id
and rec.move_id.operating_unit_id
and rec.operating_unit_id
and rec.move_id.operating_unit_id != rec.operating_unit_id
):
raise UserError(
_(
"Configuration error. The Operating Unit in"
" the Move Line and in the Move must be the"
" same."
)
)


class AccountMove(models.Model):
_inherit = "account.move"

Expand Down
56 changes: 56 additions & 0 deletions account_operating_unit/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# © 2019 ForgeFlow S.L.
# © 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.exceptions import UserError


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("move_id", False):
move = self.env["account.move"].browse(vals["move_id"])
if move.operating_unit_id:
vals["operating_unit_id"] = move.operating_unit_id.id
return super().create(vals_list)

@api.constrains("operating_unit_id", "company_id")
def _check_company_operating_unit(self):
for rec in self:
if (
rec.company_id
and rec.operating_unit_id
and rec.company_id != rec.operating_unit_id.company_id
):
raise UserError(
_(
"Configuration error. The Company in the"
" Move Line and in the Operating Unit must "
"be the same."
)
)

@api.constrains("operating_unit_id", "move_id")
def _check_move_operating_unit(self):
for rec in self:
if (
rec.move_id
and rec.move_id.operating_unit_id
and rec.operating_unit_id
and rec.move_id.operating_unit_id != rec.operating_unit_id
):
raise UserError(
_(
"Configuration error. The Operating Unit in"
" the Move Line and in the Move must be the"
" same."
)
)

0 comments on commit c4c4c8e

Please sign in to comment.