[ADD] account_analytic_default_hr_expense: default analytic account in hr.expense

When a product is selected for an expense, an analytic account (and analytic tags) can now be automatically selected based on the settings.

closes odoo/odoo#28673
This commit is contained in:
eco-odoo
2018-11-14 12:39:29 +00:00
committed by qdp-odoo
parent 3c36745672
commit 116d45633b
4 changed files with 42 additions and 0 deletions
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Account Analytic Defaults for expenses.',
'version': '1.0',
'category': 'Accounting',
'description': """
Set default values for your analytic accounts on your hr expenses.
==================================================================
Allows to automatically select analytic accounts based on Product
""",
'depends': ['account_analytic_default', 'hr_expense'],
'auto_install': True,
}
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from . import hr_expense
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
class HrExpense(models.Model):
_inherit = 'hr.expense'
@api.onchange('product_id', 'date')
def _onchange_product_id(self):
res = super(HrExpense, self)._onchange_product_id()
rec = self.env['account.analytic.default'].account_get(self.product_id.id, company_id=self.company_id.id, date=self.date)
self.analytic_account_id = rec.analytic_id.id
self.analytic_tag_ids = rec.analytic_tag_ids.ids
return res