From 056987d9ac4d08e0ca1fd7b9f408dfa96bb8ffc6 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 9 Jun 2015 16:26:27 +0200 Subject: [PATCH] [IMP] account_asset: needed some improvements (described bellow) - put Assets Entries and Deferred Entries in group_no_one and put them in adviser - in customer invoice, deferred revenue category in group_no_one cause taken from product - in form view of asset, depreciation information in an other tab - demo data : maintenance contract is a sale type - split tree view of asset to display different labels - depreciation board : no serial number, next period depreciation --> residual, ... - cumulative depreciation takes into account the current period - account.move and account.move line : wrong ref and name - cron to generates entries of assets (once a month) - reporting of assets analysis : remove date col, add unposted_value --- addons/account_asset/__openerp__.py | 1 + addons/account_asset/account_asset.py | 27 +++--- addons/account_asset/account_asset_cron.xml | 13 +++ addons/account_asset/account_asset_demo.yml | 17 ++-- addons/account_asset/account_asset_invoice.py | 26 ++---- .../report/account_asset_report_view.xml | 13 +-- .../views/account_asset_invoice_view.xml | 2 +- .../views/account_asset_view.xml | 85 ++++++++++++------- .../wizard/wizard_asset_compute_view.xml | 8 +- 9 files changed, 108 insertions(+), 84 deletions(-) create mode 100644 addons/account_asset/account_asset_cron.xml diff --git a/addons/account_asset/__openerp__.py b/addons/account_asset/__openerp__.py index 7a1f36b6f8c..e9c51f87121 100644 --- a/addons/account_asset/__openerp__.py +++ b/addons/account_asset/__openerp__.py @@ -36,6 +36,7 @@ Keeps track of the revenue recognition installments, and creates corresponding j 'views/account_asset_invoice_view.xml', 'report/account_asset_report_view.xml', 'views/account_asset.xml', + 'account_asset_cron.xml', ], 'qweb': [ "static/src/xml/account_asset_template.xml", diff --git a/addons/account_asset/account_asset.py b/addons/account_asset/account_asset.py index ebe22bc408c..aa9d3421d88 100644 --- a/addons/account_asset/account_asset.py +++ b/addons/account_asset/account_asset.py @@ -58,8 +58,8 @@ class AccountAssetAsset(models.Model): account_move_line_ids = fields.One2many('account.move.line', 'asset_id', string='Entries', readonly=True, states={'draft': [('readonly', False)]}) entry_count = fields.Integer(compute='_entry_count', string='# Asset Entries') - name = fields.Char(string='Asset/Deferred Revenue Name', required=True, readonly=True, states={'draft': [('readonly', False)]}) - code = fields.Char(string='Reference', size=32, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env['ir.sequence'].next_by_code('account.asset.code')) + name = fields.Char(string='Asset Name', required=True, readonly=True, states={'draft': [('readonly', False)]}) + code = fields.Char(string='Reference', size=32, readonly=True, states={'draft': [('readonly', False)]}) value = fields.Float(string='Gross Value', required=True, readonly=True, digits=0, states={'draft': [('readonly', False)]}, oldname='purchase_value') currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user.company_id.currency_id.id) @@ -104,6 +104,7 @@ class AccountAssetAsset(models.Model): if asset.account_move_line_ids: raise UserError(_('You cannot delete a document that contains posted lines.')) return super(AccountAssetAsset, self).unlink() + @api.multi def _get_last_depreciation_date(self): """ @@ -119,6 +120,11 @@ class AccountAssetAsset(models.Model): result = dict(self.env.cr.fetchall()) return result + @api.model + def _cron_generate_entries(self): + assets = self.env['account.asset.asset'].search([('state', '=', 'open')]) + assets._compute_entries(datetime.today()) + def _compute_board_amount(self, sequence, residual_amount, amount_to_depr, undone_dotation_number, posted_depreciation_line_ids, total_days, depreciation_date): amount = 0 if sequence == undone_dotation_number: @@ -193,9 +199,9 @@ class AccountAssetAsset(models.Model): 'amount': amount, 'asset_id': self.id, 'sequence': sequence, - 'name': (self.code or str(self.id)) + '/' + str(sequence), + 'name': (self.code or '') + '/' + str(sequence), 'remaining_value': residual_amount, - 'depreciated_value': (self.value - self.salvage_value) - (residual_amount + amount), + 'depreciated_value': self.value - (self.salvage_value + residual_amount), 'depreciation_date': depreciation_date.strftime(DF), } commands.append((0, False, vals)) @@ -329,7 +335,7 @@ class AccountAssetDepreciationLine(models.Model): parent_state = fields.Selection(related='asset_id.state', string='State of Asset') amount = fields.Float(string='Current Depreciation', digits=0, required=True) remaining_value = fields.Float(string='Next Period Depreciation', digits=0, required=True) - depreciated_value = fields.Float(string='Amount Already Depreciated', required=True) + 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) @@ -349,16 +355,15 @@ class AccountAssetDepreciationLine(models.Model): current_currency = line.asset_id.currency_id amount = company_currency.compute(line.amount, current_currency) sign = (line.asset_id.category_id.journal_id.type == 'purchase' or line.asset_id.category_id.journal_id.type == 'sale' and 1) or -1 - asset_name = line.asset_id.name - reference = line.name + asset_name = line.asset_id.name + ' (%s/%s)' % (line.sequence, line.asset_id.method_number) + reference = line.asset_id.code journal_id = line.asset_id.category_id.journal_id.id partner_id = line.asset_id.partner_id.id categ_type = line.asset_id.category_id.type debit_account = line.asset_id.category_id.account_asset_id.id credit_account = line.asset_id.category_id.account_depreciation_id.id move_line_1 = { - 'name': asset_name or reference, - 'ref': reference, + 'name': asset_name, 'account_id': credit_account, 'debit': 0.0, 'credit': amount, @@ -371,8 +376,7 @@ class AccountAssetDepreciationLine(models.Model): 'asset_id': line.asset_id.id if categ_type == 'sale' else False, } move_line_2 = { - 'name': asset_name or reference, - 'ref': reference, + 'name': asset_name, 'account_id': debit_account, 'credit': 0.0, 'debit': amount, @@ -385,7 +389,6 @@ class AccountAssetDepreciationLine(models.Model): 'asset_id': line.asset_id.id if categ_type == 'purchase' else False } move_vals = { - 'name': asset_name, 'ref': reference, 'date': depreciation_date or False, 'journal_id': line.asset_id.category_id.journal_id.id, diff --git a/addons/account_asset/account_asset_cron.xml b/addons/account_asset/account_asset_cron.xml new file mode 100644 index 00000000000..f858fbb2237 --- /dev/null +++ b/addons/account_asset/account_asset_cron.xml @@ -0,0 +1,13 @@ + + + + Generate Asset Entries + 1 + months + -1 + + + + + + \ No newline at end of file diff --git a/addons/account_asset/account_asset_demo.yml b/addons/account_asset/account_asset_demo.yml index 0249efd6943..7ac24f7c803 100644 --- a/addons/account_asset/account_asset_demo.yml +++ b/addons/account_asset/account_asset_demo.yml @@ -2,16 +2,17 @@ Creating demo data that require looking for accounts - !python {model: ir.model.data} : | - expenses_journal_id = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'purchase')]) + company = self.pool.get('res.users').browse(cr, uid, uid).company_id + journal_id = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'general'), ('id', '!=', company.currency_exchange_journal_id.id)]) expense_account_id = self.pool.get('account.account').search(cr, uid, [('user_type', '=', ref('account.data_account_type_expenses'))]) xfa_account_id = self.pool.get('account.account').search(cr, uid, [('user_type', '=', ref('account.data_account_type_fixed_assets'))]) if not xfa_account_id: xfa_account_id = self.pool.get('account.account').search(cr, uid, [('user_type', '=', ref('account.data_account_type_current_assets'))]) from datetime import datetime, timedelta import time - if xfa_account_id and expense_account_id and expenses_journal_id: + if xfa_account_id and expense_account_id and journal_id: vals = { - 'journal_id': expenses_journal_id[0], + 'journal_id': journal_id[0], 'name': 'Hardware - 3 Years', 'method_number': 3, 'account_asset_id': xfa_account_id[0], @@ -20,7 +21,7 @@ } self._update(cr, uid, 'account.asset.category', 'account_asset', vals, 'account_asset_category_fixedassets0') vals = { - 'journal_id': expenses_journal_id[0], + 'journal_id': journal_id[0], 'name': 'Cars - 5 Years', 'method_number': 5, 'account_asset_id': xfa_account_id[0], @@ -64,11 +65,13 @@ sale_account_id = self.pool.get('account.account').search(cr, uid, [('user_type', '=', ref('account.data_account_type_revenue'))]) if xfa_account_id and sale_account_id: vals = { - 'journal_id': expenses_journal_id[0], - 'name': 'Revenue Recognition Maintenance Contract - 3 Years', - 'method_number': 6, + 'journal_id': journal_id[0], + 'name': 'Revenue Recognition Maintenance Contract - 1 Years', + 'method_number': 12, + 'method_period': 1, 'account_asset_id': xfa_account_id[0], 'account_depreciation_id': xfa_account_id[0], 'account_income_recognition_id': sale_account_id[0], + 'type': 'sale', } self._update(cr, uid, 'account.asset.category', 'account_asset', vals, 'account_asset_category_sale') diff --git a/addons/account_asset/account_asset_invoice.py b/addons/account_asset/account_asset_invoice.py index b9b58171745..2814f39d7ba 100644 --- a/addons/account_asset/account_asset_invoice.py +++ b/addons/account_asset/account_asset_invoice.py @@ -70,28 +70,16 @@ class AccountInvoiceLine(models.Model): asset.validate() return True - - @api.multi - def product_id_change(self, product, uom_id, qty=0, name='', type='out_invoice', - partner_id=False, fposition_id=False, price_unit=False, currency_id=False, - company_id=None, date_invoice=None): - res = super(AccountInvoiceLine, self).product_id_change( - product, uom_id, qty=qty, name=name, type=type, partner_id=partner_id, - fposition_id=fposition_id, price_unit=price_unit, currency_id=currency_id, - company_id=company_id, date_invoice=date_invoice - ) - if product and res['value']: - product_obj = self.env['product.product'].browse(product) - if type == 'out_invoice': - res['value']['asset_category_id'] = product_obj.product_tmpl_id.deferred_revenue_category_id - elif type == 'in_invoice': - res['value']['asset_category_id'] = product_obj.product_tmpl_id.asset_category_id - - return res + @api.onchange('product_id') + def onchange_product_id(self): + if self.product_id: + if self.invoice_id.type == 'out_invoice': + self.asset_category_id = self.product_id.product_tmpl_id.deferred_revenue_category_id + elif self.invoice_id.type == 'in_invoice': + self.asset_category_id = self.product_id.product_tmpl_id.asset_category_id class ProductTemplate(models.Model): _inherit = 'product.template' asset_category_id = fields.Many2one('account.asset.category', string='Asset Type', ondelete="restrict") deferred_revenue_category_id = fields.Many2one('account.asset.category', string='Deferred Revenue Type', ondelete="restrict") - diff --git a/addons/account_asset/report/account_asset_report_view.xml b/addons/account_asset/report/account_asset_report_view.xml index 19f95375620..20bcd15cd1b 100644 --- a/addons/account_asset/report/account_asset_report_view.xml +++ b/addons/account_asset/report/account_asset_report_view.xml @@ -7,10 +7,8 @@ - - - + @@ -20,8 +18,8 @@ - + @@ -157,12 +155,7 @@ - - - + parent="account.menu_finance_reports" sequence="22"/> diff --git a/addons/account_asset/views/account_asset_invoice_view.xml b/addons/account_asset/views/account_asset_invoice_view.xml index b4207df4dd6..eb2e3d89380 100644 --- a/addons/account_asset/views/account_asset_invoice_view.xml +++ b/addons/account_asset/views/account_asset_invoice_view.xml @@ -31,7 +31,7 @@ - + diff --git a/addons/account_asset/views/account_asset_view.xml b/addons/account_asset/views/account_asset_view.xml index a9fc98331b9..4ee986e2239 100644 --- a/addons/account_asset/views/account_asset_view.xml +++ b/addons/account_asset/views/account_asset_view.xml @@ -101,7 +101,7 @@
@@ -121,21 +121,24 @@ - + - - +
+
+ + - - - + +