diff options
| author | Mansi Gandhi <mag@odoo.com> | 2017-10-20 13:45:36 +0200 |
|---|---|---|
| committer | Jérome Maes <jem@openerp.com> | 2017-10-23 14:27:21 +0200 |
| commit | 7ec5f093de10c965b217714fa3f78834f0386b10 (patch) | |
| tree | 6cda2275a6961374b0b1346adf2e69a343dbbbc8 /addons | |
| parent | 5c77f2c512020ddd0d703570946a3bc6fc3bf8ef (diff) | |
[IMP] hr_expense: amount in company current in reports
When printing expense report, we want to see the
amount in the expense company and its total, to
know how much the company have to reimbourse.
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/hr_expense/models/hr_expense.py | 35 | ||||
| -rw-r--r-- | addons/hr_expense/report/report_expense_sheet.xml | 6 | ||||
| -rw-r--r-- | addons/hr_expense/views/hr_expense_views.xml | 15 |
3 files changed, 39 insertions, 17 deletions
diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 17cbc2b14bf..7563b34e424 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -26,9 +26,11 @@ class HrExpense(models.Model): quantity = fields.Float(required=True, readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, digits=dp.get_precision('Product Unit of Measure'), default=1) tax_ids = fields.Many2many('account.tax', 'expense_tax', 'expense_id', 'tax_id', string='Taxes', states={'done': [('readonly', True)], 'post': [('readonly', True)]}) untaxed_amount = fields.Float(string='Subtotal', store=True, compute='_compute_amount', digits=dp.get_precision('Account')) - total_amount = fields.Float(string='Total', store=True, compute='_compute_amount', digits=dp.get_precision('Account')) + total_amount = fields.Monetary("Total", compute='_compute_amount', store=True, currency_field='currency_id', digits=dp.get_precision('Account')) + total_amount_company = fields.Monetary("Total submitted amount in company currency", compute='_compute_total_amount_company', store=True, currency_field='company_currency_id', digits=dp.get_precision('Account')) company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.user.company_id) currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.user.company_id.currency_id) + company_currency_id = fields.Many2one('res.currency', string="Report Company Currency", related='sheet_id.currency_id', store=True) analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', states={'post': [('readonly', True)], 'done': [('readonly', True)]}, oldname='analytic_account') account_id = fields.Many2one('account.account', string='Account', states={'post': [('readonly', True)], 'done': [('readonly', True)]}, default=lambda self: self.env['ir.property'].get('property_account_expense_categ_id', 'product.category'), help="An expense account is expected") @@ -68,6 +70,15 @@ class HrExpense(models.Model): taxes = expense.tax_ids.compute_all(expense.unit_amount, expense.currency_id, expense.quantity, expense.product_id, expense.employee_id.user_id.partner_id) expense.total_amount = taxes.get('total_included') + @api.depends('date', 'total_amount', 'company_currency_id') + def _compute_total_amount_company(self): + for expense in self: + amount = 0 + if expense.company_currency_id: + date_expense = expense.date + amount = expense.currency_id.with_context(date=date_expense, company_id=expense.company_id.id).compute(expense.total_amount, expense.company_currency_id) + expense.total_amount_company = amount + @api.multi def _compute_attachment_number(self): attachment_data = self.env['ir.attachment'].read_group([('res_model', '=', 'hr.expense'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id']) @@ -418,8 +429,8 @@ class HrExpenseSheet(models.Model): employee_id = fields.Many2one('hr.employee', string="Employee", required=True, readonly=True, states={'submit': [('readonly', False)]}, default=lambda self: self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)) address_id = fields.Many2one('res.partner', string="Employee Home Address") payment_mode = fields.Selection([("own_account", "Employee (to reimburse)"), ("company_account", "Company")], related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Payment By") - responsible_id = fields.Many2one('res.users', 'Validation By', readonly=True, copy=False, states={'submit': [('readonly', False)], 'submit': [('readonly', False)]}) - total_amount = fields.Float(string='Total Amount', store=True, compute='_compute_amount', digits=dp.get_precision('Account')) + responsible_id = fields.Many2one('res.users', 'Validation By', readonly=True, copy=False, states={'submit': [('readonly', False)]}) + total_amount = fields.Monetary('Total Amount', currency_field='currency_id', compute='_compute_amount', store=True, digits=dp.get_precision('Account')) company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'submit': [('readonly', False)]}, default=lambda self: self.env.user.company_id) currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'submit': [('readonly', False)]}, default=lambda self: self.env.user.company_id.currency_id) attachment_number = fields.Integer(compute='_compute_attachment_number', string='Number of Attachments') @@ -430,6 +441,7 @@ class HrExpenseSheet(models.Model): accounting_date = fields.Date(string="Date") account_move_id = fields.Many2one('account.move', string='Journal Entry', ondelete='restrict', copy=False) department_id = fields.Many2one('hr.department', string='Department', states={'post': [('readonly', True)], 'done': [('readonly', True)]}) + is_multiple_currency = fields.Boolean("Handle lines with different currencies", compute='_compute_is_multiple_currency') @api.multi def check_consistency(self): @@ -505,16 +517,15 @@ class HrExpenseSheet(models.Model): self.address_id = self.employee_id.address_home_id self.department_id = self.employee_id.department_id - @api.one - @api.depends('expense_line_ids', 'expense_line_ids.total_amount', 'expense_line_ids.currency_id') + @api.depends('expense_line_ids.total_amount_company') def _compute_amount(self): - total_amount = 0.0 - for expense in self.expense_line_ids: - total_amount += expense.currency_id.with_context( - date=expense.date, - company_id=expense.company_id.id - ).compute(expense.total_amount, self.currency_id) - self.total_amount = total_amount + for sheet in self: + sheet.total_amount = sum(sheet.expense_line_ids.mapped('total_amount_company')) + + @api.depends('expense_line_ids.currency_id') + def _compute_is_multiple_currency(self): + for sheet in self: + sheet.is_multiple_currency = len(sheet.expense_line_ids.mapped('currency_id')) > 1 # FIXME: A 4 command is missing to explicitly declare the one2many relation # between the sheet and the lines when using 'default_expense_line_ids':[ids] diff --git a/addons/hr_expense/report/report_expense_sheet.xml b/addons/hr_expense/report/report_expense_sheet.xml index 1934b7cb64b..375616a8f42 100644 --- a/addons/hr_expense/report/report_expense_sheet.xml +++ b/addons/hr_expense/report/report_expense_sheet.xml @@ -40,13 +40,14 @@ <th>Taxes</th> <th class="text-center">Qty</th> <th class="text-right">Price</th> + <th t-if="o.is_multiple_currency" class="text-right">Price in Company Currency</th> </tr> </thead> <tbody> <tr t-foreach="o.expense_line_ids" t-as="line"> <td><span t-field="line.date"/></td> <td> - <span t-field="line.name"/> + <span t-field="line.name"/> <span t-field="line.description"/><br/> <span t-field="line.analytic_account_id.name"/> </td> @@ -73,6 +74,9 @@ <span t-field="line.total_amount" t-options='{"widget": "monetary", "display_currency": line.currency_id}'/> </td> + <td t-if="o.is_multiple_currency" class="text-right"> + <span t-field="line.total_amount_company"/> + </td> </tr> </tbody> </table> diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index 49d3019db14..7b4666161bc 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -412,8 +412,6 @@ <field name="employee_id"/> <field name="payment_mode"/> <field name="responsible_id" invisible="1"/> - <field name="total_amount" invisible="1"/> - <field name="currency_id" invisible="1"/> <field name="address_id" invisible="1"/> <field name="department_id" invisible="1"/> <field name="company_id" groups="base.group_multi_company"/> @@ -426,17 +424,26 @@ <field name="date"/> <field name="name"/> <field name="state" invisible="1"/> - <field name="currency_id" invisible="1"/> <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/> <field name="message_unread" invisible="1"/> <field name="attachment_number" string=" "/> <button name="action_get_attachment_view" string="View Attachments" type="object" icon="fa-paperclip"/> <field name="tax_ids" widget="many2many_tags"/> - <field name="total_amount" sum="Total Amount" widget="monetary" options="{'currency_field': 'currency_id'}"/> + <field name="currency_id" invisible="1"/> + <field name="total_amount"/> + <field name="company_currency_id" invisible="1"/> + <field name="total_amount_company" groups="base.group_multi_currency"/> <field name="is_refused" invisible="True"/> <button name="%(hr_expense.hr_expense_refuse_wizard_action)d" states="reported, refused" string="Refuse" context="{'hr_expense_refuse_model':'hr.expense'}" type="action" groups="hr_expense.group_hr_expense_user, account.group_account_user" icon="fa-times" attrs="{'invisible': ['|', ('is_refused', '=', True),('state', 'in', ['done'])]}"/> </tree> </field> + <field name="currency_id" invisible="1"/> + <group class="oe_subtotal_footer oe_right" colspan="2" name="expense_total"> + <div class="oe_subtotal_footer_separator oe_inline o_td_label"> + <label for="total_amount"/> + </div> + <field name="total_amount" nolabel="1" class="oe_subtotal_footer_separator"/> + </group> </page> <page string="Other Info"> <group> |
