diff --git a/hr_expense_usability/hr_expense.py b/hr_expense_usability/hr_expense.py
index 5379ee3..e3210e0 100644
--- a/hr_expense_usability/hr_expense.py
+++ b/hr_expense_usability/hr_expense.py
@@ -117,6 +117,7 @@ class HrExpense(models.Model):
store=True, string='Tax Amount in Company Currency',
currency_field='company_currency_id')
# I don't use the native field 'untaxed_amount' (computed, store=True)
+ has_description = fields.Boolean(compute='_compute_has_description', store=True)
@api.depends(
'currency_id', 'company_id', 'total_amount', 'date',
@@ -135,6 +136,13 @@ class HrExpense(models.Model):
exp.untaxed_amount_company_currency = untaxed_cc
exp.tax_amount_company_currency = total_cc - untaxed_cc
+ @api.multi
+ @api.depends('description')
+ def _compute_has_description(self):
+ for rec in self:
+ rec.has_description = (
+ rec.description and bool(rec.description.strip()))
+
@api.onchange('untaxed_amount_usability')
def untaxed_amount_usability_change(self):
self.tax_amount = self.total_amount - self.untaxed_amount_usability
@@ -331,6 +339,32 @@ class HrExpenseSheet(models.Model):
sheet.untaxed_amount_company_currency = untaxed
sheet.tax_amount_company_currency = total - untaxed
+ @api.multi
+ def _compute_attachment_number(self):
+ AttachmentObj = self.env['ir.attachment']
+ for rec in self:
+ sheet_attachment_count = AttachmentObj.search_count([
+ ('res_model', '=', self._name),
+ ('res_id', '=', rec.id)])
+ rec.attachment_number = (
+ sum(self.expense_line_ids.mapped('attachment_number')) +
+ sheet_attachment_count)
+
+ @api.multi
+ def action_get_attachment_view(self):
+ self.ensure_one()
+ res = super(HrExpenseSheet, self).action_get_attachment_view()
+ res['domain'] = [
+ '|',
+ '&',
+ ('res_model', '=', 'hr.expense'),
+ ('res_id', 'in', self.expense_line_ids.ids),
+ '&',
+ ('res_model', '=', 'hr.expense.sheet'),
+ ('res_id', '=', self.id),
+ ]
+ return res
+
@api.one
@api.constrains('expense_line_ids')
def _check_amounts(self):
diff --git a/hr_expense_usability/hr_expense_view.xml b/hr_expense_usability/hr_expense_view.xml
index ef5e02b..d62196c 100644
--- a/hr_expense_usability/hr_expense_view.xml
+++ b/hr_expense_usability/hr_expense_view.xml
@@ -103,6 +103,9 @@
+
+