-
-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] account_receipt_journal: Exclusive Receipt Journals
- Loading branch information
Showing
7 changed files
with
128 additions
and
34 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
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,6 +1,46 @@ | ||
from odoo import fields, models | ||
from odoo import _, api, exceptions, fields, models | ||
|
||
|
||
class Journal(models.Model): | ||
class AccountJournal(models.Model): | ||
_inherit = "account.journal" | ||
receipts = fields.Boolean() | ||
|
||
receipts = fields.Boolean( | ||
string="Exclusive to Receipts", | ||
help="If checked, this journal will be used by default for receipts " | ||
"and only can be used for receipts.", | ||
) | ||
|
||
def action_create_new(self): | ||
"""Create a new Receipt from the Dashboard""" | ||
res = super().action_create_new() | ||
if not self.receipts: | ||
return res | ||
res["name"] = _("Create receipt") | ||
if self.type == "sale": | ||
res["context"]["default_move_type"] = "out_receipt" | ||
elif self.type == "purchase": | ||
res["context"]["default_move_type"] = "in_receipt" | ||
return res | ||
|
||
@api.constrains("sequence", "type", "receipts", "company_id") | ||
def _check_receipts_sequence(self): | ||
"""Ensure that journals with receipts checked, are on a higher sequence | ||
that the rest of journals of the same type""" | ||
for journal in self.filtered("receipts"): | ||
previous_sequence_journals = self.search( | ||
[ | ||
("type", "=", journal.type), | ||
("receipts", "=", False), | ||
("sequence", "<", journal.sequence), | ||
("id", "!=", journal.id), | ||
("company_id", "=", journal.company_id.id), | ||
] | ||
) | ||
if not previous_sequence_journals: | ||
raise exceptions.ValidationError( | ||
_( | ||
"The sequence of the journal '%s' must be higher than " | ||
"the sequence of the other journals of the same type." | ||
) | ||
% journal.name | ||
) |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Lorenzo Battistini | ||
|
||
* `Moduon <https://www.moduon.team>`_: | ||
|
||
* Eduardo de Miguel | ||
* Rafael Blasco |
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 +1 @@ | ||
Define journals dedicated to receipts and automatically use them in sale and purchase receipts | ||
Define journals exclusive to receipts and automatically use them in sale and purchase receipts |
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