From 28a7bcd83c67970683c0a9505535ccc74cf4602a Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 6 Jun 2016 13:26:19 +0200 Subject: [PATCH] [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 --- addons/account_asset/account_asset.py | 21 ++++++++++++++++--- .../static/src/js/account_asset.js | 10 ++++++--- .../static/src/less/account_asset.less | 5 ++++- .../views/account_asset_view.xml | 1 + 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/addons/account_asset/account_asset.py b/addons/account_asset/account_asset.py index 3c2290ece72..d7ceeeb0c1e 100644 --- a/addons/account_asset/account_asset.py +++ b/addons/account_asset/account_asset.py @@ -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: diff --git a/addons/account_asset/static/src/js/account_asset.js b/addons/account_asset/static/src/js/account_asset.js index 69c4fc1f523..5fe995a98a8 100644 --- a/addons/account_asset/static/src/js/account_asset.js +++ b/addons/account_asset/static/src/js/account_asset.js @@ -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 $('
').append((this.parent_state === 'open')? $('