forked from OCA/operating-unit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] move classes to their canonical files
- Loading branch information
Showing
4 changed files
with
58 additions
and
51 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 |
---|---|---|
@@ -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 |
File renamed without changes.
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
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,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." | ||
) | ||
) |