mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
hide fields for type view assets
This commit is contained in:
committed by
Akim Juillerat
parent
088f12101f
commit
2e7fe380c9
@@ -4,7 +4,7 @@
|
||||
|
||||
{
|
||||
'name': 'Assets Management',
|
||||
'version': '10.0.3.0.3',
|
||||
'version': '10.0.3.1.0',
|
||||
'license': 'AGPL-3',
|
||||
'depends': [
|
||||
'account_fiscal_year',
|
||||
|
||||
@@ -277,9 +277,10 @@ class AccountAsset(models.Model):
|
||||
self.depreciation_base = purchase_value - salvage_value
|
||||
dl_create_line = self.depreciation_line_ids.filtered(
|
||||
lambda r: r.type == 'create')
|
||||
dl_create_line.write({
|
||||
'amount': self.depreciation_base,
|
||||
'line_date': self.date_start})
|
||||
if dl_create_line:
|
||||
dl_create_line.write({
|
||||
'amount': self.depreciation_base,
|
||||
'line_date': self.date_start})
|
||||
|
||||
@api.onchange('profile_id')
|
||||
def _onchange_profile_id(self):
|
||||
@@ -325,20 +326,7 @@ class AccountAsset(models.Model):
|
||||
# Trigger compute of depreciation_base
|
||||
asset.salvage_value = 0.0
|
||||
if asset.type == 'normal':
|
||||
# create first asset line
|
||||
asset_line_obj = self.env['account.asset.line']
|
||||
line_name = asset._get_depreciation_entry_name(0)
|
||||
asset_line_vals = {
|
||||
'amount': asset.depreciation_base,
|
||||
'asset_id': asset.id,
|
||||
'name': line_name,
|
||||
'line_date': asset.date_start,
|
||||
'init_entry': True,
|
||||
'type': 'create',
|
||||
}
|
||||
asset_line = asset_line_obj.create(asset_line_vals)
|
||||
if self._context.get('create_asset_from_move_line'):
|
||||
asset_line.move_id = self._context['move_id']
|
||||
asset._create_first_asset_line()
|
||||
return asset
|
||||
|
||||
@api.multi
|
||||
@@ -352,6 +340,7 @@ class AccountAsset(models.Model):
|
||||
if asset_type == 'view' or \
|
||||
self._context.get('asset_validate_from_write'):
|
||||
continue
|
||||
asset._create_first_asset_line()
|
||||
if asset.profile_id.open_asset and \
|
||||
self._context.get('create_asset_from_move_line'):
|
||||
asset.compute_depreciation_board()
|
||||
@@ -360,6 +349,23 @@ class AccountAsset(models.Model):
|
||||
asset.with_context(ctx).validate()
|
||||
return True
|
||||
|
||||
def _create_first_asset_line(self):
|
||||
self.ensure_one()
|
||||
if self.depreciation_base and not self.depreciation_line_ids:
|
||||
asset_line_obj = self.env['account.asset.line']
|
||||
line_name = self._get_depreciation_entry_name(0)
|
||||
asset_line_vals = {
|
||||
'amount': self.depreciation_base,
|
||||
'asset_id': self.id,
|
||||
'name': line_name,
|
||||
'line_date': self.date_start,
|
||||
'init_entry': True,
|
||||
'type': 'create',
|
||||
}
|
||||
asset_line = asset_line_obj.create(asset_line_vals)
|
||||
if self._context.get('create_asset_from_move_line'):
|
||||
asset_line.move_id = self._context['move_id']
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
for asset in self:
|
||||
|
||||
@@ -157,7 +157,7 @@ class AccountAssetLine(models.Model):
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
for dl in self:
|
||||
if dl.type == 'create':
|
||||
if dl.type == 'create' and dl.amount:
|
||||
raise UserError(_(
|
||||
"You cannot remove an asset line "
|
||||
"of type 'Depreciation Base'."))
|
||||
@@ -170,7 +170,7 @@ class AccountAssetLine(models.Model):
|
||||
lambda l: l.previous_id == dl and l not in self)
|
||||
if next:
|
||||
next.previous_id = previous
|
||||
ctx = dict(self._context, no_compute_asset_line_ids=self.ids)
|
||||
ctx = dict(self._context, no_compute_asset_line_ids=self.ids)
|
||||
return super(
|
||||
AccountAssetLine, self.with_context(ctx)).unlink()
|
||||
|
||||
|
||||
@@ -6,17 +6,20 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Asset">
|
||||
<header>
|
||||
<button name="validate" states="draft" string="Confirm Asset" type="object" class="oe_highlight"/>
|
||||
<button name="validate" string="Confirm Asset" type="object" class="oe_highlight"
|
||||
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('type', '=', 'view')]}"/>
|
||||
<button name="set_to_draft" states="open,close"
|
||||
string="Set to Draft" type="object" groups="account.group_account_manager"/>
|
||||
<button name="remove" string="Remove" type="object" groups="account.group_account_manager"
|
||||
attrs="{'invisible':['|', ('method_time', '!=', 'year'), ('state', 'not in', ['open', 'close'])]}"
|
||||
help="Asset removal."/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,open,close,removed"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,open,close,removed"
|
||||
attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box oe_right">
|
||||
<button name="open_entries" string="Journal Entries" type="object" class="oe_inline"/>
|
||||
<button name="open_entries" string="Journal Entries" type="object" class="oe_inline"
|
||||
attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
</div>
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only"/>
|
||||
@@ -173,13 +176,13 @@
|
||||
<field name="name"/>
|
||||
<field name="type" invisible="1"/>
|
||||
<field name="code"/>
|
||||
<field name="depreciation_base"/>
|
||||
<field name="value_depreciated"/>
|
||||
<field name="value_residual"/>
|
||||
<field name="depreciation_base" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="value_residual" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="value_residual" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_remove"/>
|
||||
<field name="profile_id"/>
|
||||
<field name="state"/>
|
||||
<field name="state" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -225,13 +228,13 @@
|
||||
<field name="name"/>
|
||||
<field name="type" invisible="1"/>
|
||||
<field name="code"/>
|
||||
<field name="depreciation_base"/>
|
||||
<field name="value_depreciated"/>
|
||||
<field name="value_residual"/>
|
||||
<field name="depreciation_base" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="value_depreciated" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="value_residual" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_remove"/>
|
||||
<field name="profile_id"/>
|
||||
<field name="state"/>
|
||||
<field name="state" attrs="{'invisible': [('type', '=', 'view')]}"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user