Skip to content

Commit 3fdabc0

Browse files
committed
[MIG] account_asset_number: Migration to 18.0
1 parent 6ea9f0a commit 3fdabc0

File tree

5 files changed

+97
-24
lines changed

5 files changed

+97
-24
lines changed

account_asset_number/models/account_asset_profile.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class AccountAssetProfile(models.Model):
99

1010
use_sequence = fields.Boolean(
1111
string="Auto Asset Number by Sequence",
12-
default=False,
1312
help="If check, asset number auto run by sequence.",
1413
)
1514
sequence_id = fields.Many2one(

account_asset_number/report/account_asset_report_xls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import _, models
4+
from odoo import models
55

66

77
class AssetReportXlsx(models.AbstractModel):
@@ -12,7 +12,7 @@ def _get_asset_template(self):
1212
res.update(
1313
{
1414
"number": {
15-
"header": {"type": "string", "value": _("Number")},
15+
"header": {"type": "string", "value": self.env._("Number")},
1616
"asset": {
1717
"type": "string",
1818
"value": self._render("asset.number or ''"),

account_asset_number/tests/test_account_asset_number.py

+85-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class TestAssetNumber(TestAssetManagement):
1515
@classmethod
1616
def setUpClass(cls):
17+
"""Setup."""
1718
super().setUpClass()
1819
cls.sequence_asset = cls.env["ir.sequence"].create(
1920
{
@@ -26,7 +27,8 @@ def setUpClass(cls):
2627
)
2728

2829
def test_01_asset_number(self):
29-
# use sequence number on profile_id
30+
"""Test asset creation with a sequence."""
31+
3032
self.car5y.write(
3133
{
3234
"use_sequence": True,
@@ -55,3 +57,85 @@ def test_01_asset_number(self):
5557
asset.validate()
5658
self.assertTrue(asset.number)
5759
self.assertEqual(asset.number[:2], "AC")
60+
61+
def test_02_asset_number_without_sequence(self):
62+
"""Test asset creation without a sequence."""
63+
self.car5y.write(
64+
{
65+
"use_sequence": False,
66+
"sequence_id": self.sequence_asset.id,
67+
}
68+
)
69+
70+
asset = self.asset_model.create(
71+
{
72+
"name": "test asset without sequence",
73+
"profile_id": self.car5y.id,
74+
"purchase_value": 1500,
75+
"salvage_value": 100,
76+
"date_start": time.strftime("%Y-08-01"),
77+
"method_time": "year",
78+
"method": "degr-linear",
79+
"method_number": 5,
80+
"method_period": "year",
81+
"prorata": False,
82+
}
83+
)
84+
85+
asset.validate()
86+
87+
self.assertFalse(
88+
asset.number,
89+
"The asset number should not be generated when sequence is disabled.",
90+
)
91+
92+
def test_03_xls_fields(self):
93+
"""Test XLS fields include the number field."""
94+
acquisition_fields = self.env["account.asset"]._xls_acquisition_fields()
95+
active_fields = self.env["account.asset"]._xls_active_fields()
96+
removal_fields = self.env["account.asset"]._xls_removal_fields()
97+
98+
self.assertIn(
99+
"number",
100+
acquisition_fields,
101+
"The number field should be included in acquisition fields.",
102+
)
103+
self.assertIn(
104+
"number",
105+
active_fields,
106+
"The number field should be included in active fields.",
107+
)
108+
self.assertIn(
109+
"number",
110+
removal_fields,
111+
"The number field should be included in removal fields.",
112+
)
113+
114+
def test_04_profile_barcode_type_onchange(self):
115+
"""Test the onchange logic for barcode_type."""
116+
self.ict3Y.write(
117+
{
118+
"barcode_width": 350,
119+
"barcode_height": 75,
120+
}
121+
)
122+
123+
self.ict3Y.barcode_type = "qr"
124+
self.ict3Y._onchange_barcode_type()
125+
self.assertEqual(
126+
self.ict3Y.barcode_width, 150, "QR barcode width should default to 150."
127+
)
128+
self.assertEqual(
129+
self.ict3Y.barcode_height,
130+
75,
131+
"Barcode height should remain unchanged for QR.",
132+
)
133+
134+
self.ict3Y.barcode_type = "barcode"
135+
self.ict3Y._onchange_barcode_type()
136+
self.assertEqual(
137+
self.ict3Y.barcode_width, 300, "Barcode width should default to 300."
138+
)
139+
self.assertEqual(
140+
self.ict3Y.barcode_height, 75, "Barcode height should default to 75."
141+
)

account_asset_number/views/account_asset.xml

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
<field name="use_sequence" invisible="True" />
1313
<label for="number" class="oe_edit_only" />
1414
<h2>
15-
<field
16-
name="number"
17-
class="oe_inline"
18-
attrs="{'readonly':[('use_sequence', '=', True)]}"
19-
/>
15+
<field name="number" class="oe_inline" readonly="use_sequence" />
2016
</h2>
2117
</h1>
2218
</field>
@@ -43,9 +39,9 @@
4339
/>
4440
<field name="arch" type="xml">
4541
<xpath expr="//field[@name='name']" position="attributes">
46-
<attribute
47-
name="filter_domain"
48-
>['|', ('name', 'ilike', self), ('number', 'ilike', self)]</attribute>
42+
<attribute name="filter_domain">
43+
['|', ('name', 'ilike', self), ('number', 'ilike', self)]
44+
</attribute>
4945
</xpath>
5046
</field>
5147
</record>

account_asset_number/views/account_asset_profile.xml

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,18 @@
1010
<field name="arch" type="xml">
1111
<xpath expr="//sheet/group/group[last()]" position="after">
1212
<group string="QR/Barcode Configuration">
13-
<field
14-
name="barcode_type"
15-
attrs="{'required': [('use_sequence', '=', True)]}"
16-
/>
17-
<field
18-
name="barcode_width"
19-
attrs="{'required': [('use_sequence', '=', True)]}"
20-
/>
13+
<field name="barcode_type" required="use_sequence" />
14+
<field name="barcode_width" required="use_sequence" />
2115
<field
2216
name="barcode_height"
23-
attrs="{'invisible': [('barcode_type', '=', 'qr')],
24-
'required': [('use_sequence', '=', True)]}"
17+
required="use_sequence"
18+
invisible="barcode_type == 'qr'"
2519
/>
2620
<field name="use_sequence" />
2721
<field
2822
name="sequence_id"
29-
attrs="{'invisible': [('use_sequence', '!=', True)],
30-
'required': [('use_sequence', '=', True)]}"
23+
required="use_sequence"
24+
invisible="not use_sequence"
3125
/>
3226
</group>
3327
</xpath>

0 commit comments

Comments
 (0)