Skip to content
Snippets Groups Projects
Commit 28a7bcd8 authored by Goffin Simon's avatar Goffin Simon
Browse files

[FIX] account_asset: create move for a depreciation line

The color of the button "create_move" in a depreciation line is
green if the related move is posted, orange if it exists but not posted and
red in the other case.

opw:678905
parent 5032cdf6
No related branches found
No related tags found
No related merge requests found
......@@ -418,12 +418,20 @@ class AccountAssetDepreciationLine(models.Model):
depreciated_value = fields.Float(string='Cumulative Depreciation', required=True)
depreciation_date = fields.Date('Depreciation Date', index=True)
move_id = fields.Many2one('account.move', string='Depreciation Entry')
move_check = fields.Boolean(compute='_get_move_check', string='Posted', track_visibility='always', store=True)
move_check = fields.Boolean(compute='_get_move_check', string='Linked', track_visibility='always', store=True)
move_posted_check = fields.Boolean(compute='_get_move_posted_check', string='Posted', track_visibility='always', store=True)
@api.one
@api.multi
@api.depends('move_id')
def _get_move_check(self):
self.move_check = bool(self.move_id)
for line in self:
line.move_check = bool(line.move_id)
@api.multi
@api.depends('move_id.state')
def _get_move_posted_check(self):
for line in self:
line.move_posted_check = True if line.move_id and line.move_id.state == 'posted' else False
@api.multi
def create_move(self, post_move=True):
......@@ -567,6 +575,13 @@ class AccountMove(models.Model):
asset_depreciation_ids = fields.One2many('account.asset.depreciation.line', 'move_id', string='Assets Depreciation Lines', ondelete="restrict")
@api.multi
def button_cancel(self):
for move in self:
for line in move.asset_depreciation_ids:
line.move_posted_check = False
return super(AccountMove, self).button_cancel()
@api.multi
def post(self):
for move in self:
......
......@@ -16,14 +16,18 @@ var _t = core._t;
var WidgetOnButton = core.list_widget_registry.get('field').extend({
format: function(row_data, options) {
this._super.apply(this, arguments);
this.has_value = !!row_data.move_check.value;
this.is_posted = !!row_data.move_posted_check.value;
this.parent_state = row_data.parent_state.value;
var class_color = '';
if (this.is_posted){class_color = 'o_is_posted';}
else{
if (row_data.move_check.value){class_color = 'o_unposted';}
}
return $('<div/>').append((this.parent_state === 'open')? $('<button/>', {
type: 'button',
title: (this.has_value)? _t('Posted') : _t('Unposted'),
disabled: !!this.has_value,
'class': 'btn btn-sm btn-link fa fa-circle o_widgetonbutton' + ((this.has_value)? ' o_has_value' : ''),
'class': 'btn btn-sm btn-link fa fa-circle o_widgetonbutton ' + class_color,
}) : '').html();
},
});
......
.o_web_client .o_widgetonbutton {
color: @brand-danger;
&.o_has_value {
&.o_is_posted {
color: @brand-success;
}
&.o_unposted{
color: @brand-warning;
}
}
......@@ -148,6 +148,7 @@
<field name="amount" widget="monetary" string="Depreciation"/>
<field name="remaining_value" readonly="1" widget="monetary" string="Residual"/>
<field name="move_check" invisible="1"/>
<field name="move_posted_check" invisible="1"/>
<field name="parent_state" invisible="1"/>
<button name="create_move" type="object" widget="widgetonbutton"/>
</tree>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment