Skip to content

Commit 857ea0e

Browse files
author
rjaraspearhead
committed
[MIG] account_receipt_journal: Migration to 18.0
1 parent a2b43dd commit 857ea0e

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

account_receipt_journal/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from openupgradelib import openupgrade
33

44

5-
def rename_old_italian_data(cr):
6-
if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi"):
5+
def rename_old_italian_data(env):
6+
if not openupgrade.is_module_installed(env.cr, "l10n_it_corrispettivi"):
77
return
88

99
openupgrade.rename_xmlids(
10-
cr,
10+
env.cr,
1111
[
1212
(
1313
"l10n_it_corrispettivi.corrispettivi_journal",

account_receipt_journal/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Receipts Journals",
55
"summary": "Define and use journals dedicated to receipts",
6-
"version": "15.0.1.0.1",
6+
"version": "18.0.1.0.1",
77
"development_status": "Beta",
88
"category": "Accounting & Finance",
99
"website": "https://github.com/OCA/account-invoicing",

account_receipt_journal/models/account_journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _check_receipts_sequence(self):
3939
if not journals:
4040
continue
4141
previous_sequence_journals = journals.filtered(
42-
lambda j: j.sequence < receipt_journal.sequence
42+
lambda j, r=receipt_journal: j.sequence < r.sequence
4343
)
4444
if not previous_sequence_journals:
4545
raise exceptions.ValidationError(

account_receipt_journal/models/account_move.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
class AccountMove(models.Model):
55
_inherit = "account.move"
66

7-
@api.depends("company_id", "invoice_filter_type_domain", "move_type")
7+
@api.depends("company_id", "invoice_filter_type_domain")
88
def _compute_suitable_journal_ids(self):
99
res = super()._compute_suitable_journal_ids()
10-
for m in self:
11-
dedicated_journals = m.suitable_journal_ids.filtered(
12-
lambda j: j.receipts == m.move_type in {"out_receipt", "in_receipt"}
10+
for move in self:
11+
if move.move_type in {"in_receipt", "out_receipt"}:
12+
move.suitable_journal_ids = move.suitable_journal_ids.filtered(
13+
"receipts"
14+
)
15+
continue
16+
move.suitable_journal_ids = move.suitable_journal_ids.filtered(
17+
lambda x: not x.receipts
1318
)
14-
# Suitable journals dedicated to receipts if exists
15-
m.suitable_journal_ids = dedicated_journals or m.suitable_journal_ids
1619
return res
1720

18-
@api.model
1921
def _search_default_receipt_journal(self, journal_types):
2022
company_id = self.env.context.get("default_company_id", self.env.company.id)
2123
currency_id = self.env.context.get("default_currency_id")
@@ -33,14 +35,13 @@ def _search_default_receipt_journal(self, journal_types):
3335
journal = self.env["account.journal"].search(domain, limit=1)
3436
return journal
3537

36-
@api.model
37-
def _search_default_journal(self, journal_types):
38-
journal = super()._search_default_journal(journal_types)
39-
move_type = self.env.context.get("default_move_type")
38+
def _search_default_journal(self):
39+
journal = super()._search_default_journal()
4040
# We can assume that if move_type is not in receipts, a journal without
4141
# receipts it's coming because of the Journal constraint
42-
if move_type not in {"in_receipt", "out_receipt"} or journal.receipts:
42+
if self.move_type not in {"in_receipt", "out_receipt"} or journal.receipts:
4343
return journal
44+
journal_types = self._get_valid_journal_types()
4445
return self._search_default_receipt_journal(journal_types) or journal
4546

4647
def _get_journal_types(self, move_type):
@@ -88,8 +89,10 @@ def create(self, vals_list):
8889

8990
@api.constrains("move_type", "journal_id")
9091
def _check_receipts_journal(self):
91-
"""Ensure that Receipt Journal is only used in Receipts
92-
if exists Receipt Journals for its type"""
92+
"""
93+
Ensure that Receipt Journal is only used in Receipts
94+
if exists Receipt Journals for its type
95+
"""
9396
aj_model = self.env["account.journal"]
9497
receipt_domain = [("receipts", "=", True)]
9598
has_in_rjournals = aj_model.search([("type", "=", "purchase")] + receipt_domain)

account_receipt_journal/tests/test_receipts.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66

77
@tagged("post_install", "-at_install")
88
class TestReceipts(AccountTestInvoicingCommon):
9-
def setUp(self):
10-
super().setUp()
11-
self.out_receipt_journal = self.env["account.journal"].create(
9+
@classmethod
10+
def setUpClass(cls):
11+
super().setUpClass()
12+
cls.out_receipt_journal = cls.env["account.journal"].create(
1213
{
1314
"name": "Sale Receipts Journal",
14-
"code": "S-REC",
15+
"code": "SREC",
1516
"type": "sale",
1617
"receipts": True,
1718
"sequence": 99,
1819
}
1920
)
20-
self.in_receipt_journal = self.env["account.journal"].create(
21+
cls.in_receipt_journal = cls.env["account.journal"].create(
2122
{
2223
"name": "Purchase Receipts Journal",
23-
"code": "P-REC",
24+
"code": "PREC",
2425
"type": "purchase",
2526
"receipts": True,
2627
"sequence": 99,

account_receipt_journal/views/account_journal_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<group
1010
name="receipts"
1111
string="Receipts"
12-
attrs="{'invisible': [('type', 'not in', ('sale', 'purchase'))]}"
12+
invisible="type not in ('sale', 'purchase')"
1313
>
1414
<field name="receipts" />
1515
</group>

0 commit comments

Comments
 (0)