Skip to content

Commit 5f91d01

Browse files
author
rjaraspearhead
committed
[MIG] account_receipt_journal: Migration to 18.0
1 parent 27eea50 commit 5f91d01

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
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: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
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

1821
@api.model
@@ -34,13 +37,14 @@ def _search_default_receipt_journal(self, journal_types):
3437
return journal
3538

3639
@api.model
37-
def _search_default_journal(self, journal_types):
38-
journal = super()._search_default_journal(journal_types)
40+
def _search_default_journal(self):
41+
journal = super()._search_default_journal()
3942
move_type = self.env.context.get("default_move_type")
4043
# We can assume that if move_type is not in receipts, a journal without
4144
# receipts it's coming because of the Journal constraint
4245
if move_type not in {"in_receipt", "out_receipt"} or journal.receipts:
4346
return journal
47+
journal_types = self._get_valid_journal_types()
4448
return self._search_default_receipt_journal(journal_types) or journal
4549

4650
def _get_journal_types(self, move_type):

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)