Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Codice dei cespiti generato da sequenza #4277

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions l10n_it_asset_management/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def get_default_company_id(self):
code = fields.Char(
default="",
)
code_sequence_id = fields.Many2one(
related="category_id.code_sequence_id",
)

company_id = fields.Many2one(
"res.company",
Expand Down Expand Up @@ -114,6 +117,9 @@ def create(self, vals_list):
asset = super().create(vals)
if create_deps_from_categ:
asset.onchange_category_id()
code_sequence = asset.code_sequence_id
if code_sequence and not asset.code:
asset.code = code_sequence.next_by_id()
assets |= asset
return assets

Expand Down
5 changes: 5 additions & 0 deletions l10n_it_asset_management/models/asset_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def get_default_type_ids(self):
" printing assets' reports.",
)

code_sequence_id = fields.Many2one(
comodel_name="ir.sequence",
help="Sequence to generate the Code of new assets.",
)

tag_ids = fields.Many2many(
"asset.tag",
string="Tag",
Expand Down
19 changes: 19 additions & 0 deletions l10n_it_asset_management/tests/test_assets_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,22 @@ def test_open_manage_asset_wiz(self):
asset_wiz.with_user(forbidden_user).link_asset()
asset_wiz.with_user(manager_user).link_asset()
asset_wiz.with_user(account_user).link_asset()

def test_create_category_code_sequence(self):
"""If the category has a "Code Sequence",
it is used for created assets."""
# Arrange
category = self.asset_category_1
sequence = self.env["ir.sequence"].create(
{
"name": "Test Sequence",
}
)
sequence_next = sequence.number_next
category.code_sequence_id = sequence

# Act
asset = self._create_asset()

# Assert
self.assertEqual(asset.code, str(sequence_next))
32 changes: 31 additions & 1 deletion l10n_it_asset_management/views/asset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,37 @@
name="category_id"
attrs="{'readonly': [('state', '!=', 'non_depreciated')]}"
/>
<field name="code" />
<field
name="code"
attrs="{
'invisible': [
'&amp;',
('code_sequence_id', '!=', False),
('id', '=', False),
],
}"
/>
<!-- Invisibility domain of `code_sequence_details` could be simpler,
but like this it is easier to maintain and more obvious that it is
the opposite of `code`'s invisibility domain. -->
<div
name="code_sequence_details"
class="text-muted"
colspan="2"
attrs="{
'invisible': [
'!',
'&amp;',
('code_sequence_id', '!=', False),
('id', '=', False),
],
}"
>
The Code will be generated from the Category's Code Sequence <field
name="code_sequence_id"
class="d-inline"
/>
</div>
<field
name="used"
attrs="{'readonly': [('state', '!=', 'non_depreciated')]}"
Expand Down
1 change: 1 addition & 0 deletions l10n_it_asset_management/views/asset_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<group>
<group>
<field name="tag_ids" widget="many2many_tags" />
<field name="code_sequence_id" />
</group>
<group>
<field name="print_by_default" />
Expand Down
3 changes: 3 additions & 0 deletions l10n_it_asset_management/wizard/account_move_manage_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def get_default_move_ids(self):
code = fields.Char(
default="",
)
code_sequence_id = fields.Many2one(
related="category_id.code_sequence_id",
)

company_id = fields.Many2one(
"res.company",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,33 @@
options="{'no_create': True}"
attrs="{'required': [('management_type', '=', 'create')]}"
/>
<field name="code" />
<field
name="code"
attrs="{
'invisible': [
('code_sequence_id', '!=', False),
],
}"
/>
<!-- Invisibility domain of `code_sequence_details` could be simpler,
but like this it is easier to maintain and more obvious that it is
the opposite of `code`'s invisibility domain. -->
<div
name="code_sequence_details"
class="text-muted"
colspan="2"
attrs="{
'invisible': [
'!',
('code_sequence_id', '!=', False),
],
}"
>
The Code will be generated from the Category's Code Sequence <field
name="code_sequence_id"
class="d-inline"
/>
</div>
<field name="used" />
</group>
<group>
Expand Down
Loading