summaryrefslogtreecommitdiff
path: root/addons/hr_expense
diff options
context:
space:
mode:
authorjem-odoo <jem@openerp.com>2019-08-22 07:01:14 +0000
committerjem-odoo <jem@openerp.com>2019-08-22 07:37:23 +0000
commit8d0aee229364e9db36d5406b4b7a377f146e5f7c (patch)
treec42879781691a3244b0fe9777deb5c2346f91fc3 /addons/hr_expense
parenta2c52e9efd5f97aea56b997f015862840fb0f55e (diff)
[IMP] hr_expense: multicompany hard constraint
This commit provides hard constraints (SQL level) for expense to work in multi company environement. This is related to a R&D task, the rest of the code need to be adapt, but freeze is coming. As expense implies accounting entries, it is required to generate them in the right company, the company field should then be required. Task-1999686 closes odoo/odoo#35953 Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
Diffstat (limited to 'addons/hr_expense')
-rw-r--r--addons/hr_expense/models/hr_expense.py10
-rw-r--r--addons/hr_expense/tests/common.py2
2 files changed, 8 insertions, 4 deletions
diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py
index af4a154e0a4..5188a95fdd3 100644
--- a/addons/hr_expense/models/hr_expense.py
+++ b/addons/hr_expense/models/hr_expense.py
@@ -57,11 +57,11 @@ class HrExpense(models.Model):
total_amount = fields.Monetary("Total", compute='_compute_amount', store=True, currency_field='currency_id')
company_currency_id = fields.Many2one('res.currency', string="Report Company Currency", related='sheet_id.currency_id', store=True, readonly=False)
total_amount_company = fields.Monetary("Total (Company Currency)", compute='_compute_total_amount_company', store=True, currency_field='company_currency_id')
- company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company)
+ company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company)
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company.currency_id)
analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', states={'post': [('readonly', True)], 'done': [('readonly', True)]}, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
- account_id = fields.Many2one('account.account', domain="[('company_id', '=', company_id)]", string='Account', default=_default_account_id, help="An expense account is expected")
+ account_id = fields.Many2one('account.account', string='Account', default=_default_account_id, domain="[('internal_type', '=', 'other'), ('company_id', '=', company_id)]", help="An expense account is expected")
description = fields.Text('Notes...', readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]})
payment_mode = fields.Selection([
("own_account", "Employee (to reimburse)"),
@@ -662,7 +662,7 @@ class HrExpenseSheet(models.Model):
payment_mode = fields.Selection(related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Paid By")
user_id = fields.Many2one('res.users', 'Manager', readonly=True, copy=False, states={'draft': [('readonly', False)]}, tracking=True)
total_amount = fields.Monetary('Total Amount', currency_field='currency_id', compute='_compute_amount', store=True)
- company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company)
+ company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company)
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company.currency_id)
attachment_number = fields.Integer(compute='_compute_attachment_number', string='Number of Attachments')
journal_id = fields.Many2one('account.journal', string='Expense Journal', states={'done': [('readonly', True)], 'post': [('readonly', True)]}, default=_default_journal_id, domain="[('company_id', '=', company_id)]", help="The journal used when the expense is done.")
@@ -673,6 +673,10 @@ class HrExpenseSheet(models.Model):
is_multiple_currency = fields.Boolean("Handle lines with different currencies", compute='_compute_is_multiple_currency')
can_reset = fields.Boolean('Can Reset', compute='_compute_can_reset')
+ _sql_constraints = [
+ ('journal_id_required_posted', "CHECK((state IN ('post', 'done') AND journal_id IS NOT NULL) OR (state NOT IN ('post', 'done')))", 'The journal must be set on posted expense'),
+ ]
+
@api.depends('expense_line_ids.total_amount_company')
def _compute_amount(self):
for sheet in self:
diff --git a/addons/hr_expense/tests/common.py b/addons/hr_expense/tests/common.py
index 7c40688db48..b045a539a1a 100644
--- a/addons/hr_expense/tests/common.py
+++ b/addons/hr_expense/tests/common.py
@@ -45,7 +45,7 @@ class TestExpenseCommon(TestAccountNoChartCommon):
'name': 'Purchase Journal - Test',
'code': 'HRTPJ',
'type': 'purchase',
- 'company_id': cls.env.user.company_id.id,
+ 'company_id': cls.env.company.id,
})
cls.expense_sheet = cls.env['hr.expense.sheet'].create({
'name': 'Expense for Johnny Employee',