diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index 3ec040a11827da1bd18044d1e408bfa4380d4a02..d5f5259d6e322073275658478b15e0036eaf7363 100644 --- a/models/hr_timesheet.py +++ b/models/hr_timesheet.py @@ -11,7 +11,27 @@ class ScopHrTimesheetExp(models.Model): comodel_name='hr.expense', inverse_name='timesheet_id', string='Dépenses associées') + expense_amount = fields.Monetary( + string="Montant des dépenses", + currency_field='company_currency_id', + compute="_compute_expense_amount") + company_currency_id = fields.Many2one( + 'res.currency', + related='company_id.currency_id', + string="Company Currency", + readonly=True) + # ------------------------------------------------------ + # Compute Functions + # ------------------------------------------------------ + @api.multi + def _compute_expense_amount(self): + for ts in self: + ts.expense_amount = sum(ts.expense_ids.mapped('total_amount')) + + # ------------------------------------------------------ + # Button Functions + # ------------------------------------------------------ @api.multi def create_expense(self): for ts in self: @@ -27,3 +47,20 @@ class ScopHrTimesheetExp(models.Model): 'default_ur_financial_system_id': ts.ur_financial_system_id.id, }, } + + @api.multi + def show_expense(self): + for ts in self: + return { + "type": "ir.actions.act_window", + "res_model": "hr.expense", + "views": [[False, "tree"], [False, "form"], [False, "pivot"]], + "domain": [['timesheet_id', '=', self.id]], + "name": "Détail Dépenses", + 'context': { + 'default_timesheet_id': ts.id, + 'default_coop_id': ts.partner_id.id, + 'default_account_analytic_id': ts.project_id.id, + 'default_ur_financial_system_id': ts.ur_financial_system_id.id, + }, + } diff --git a/views/hr_timesheet.xml b/views/hr_timesheet.xml index 9682619b7774cacd2960b205222b2a54f7f556eb..bb593f6e78fd46315b79713278e30a95fef2ee57 100644 --- a/views/hr_timesheet.xml +++ b/views/hr_timesheet.xml @@ -12,7 +12,11 @@ <field name="inherit_id" ref="cgscop_timesheet.view_cgscop_hr_timesheet_line_tree"/> <field name="arch" type="xml"> <field name="ur_financial_system_id" position="after"> - <button name="create_expense" type="object" string="Créer dépense" /> + <button name="create_expense" type="object" class="btn btn-secondary btn-sm" string="Créer dépense" /> + <field name="expense_amount" /> + <button name="show_expense" type="object" class="btn btn-link btn-sm" icon="fa-paperclip" > + </button> + <field name="company_currency_id" invisible="1"/> </field> </field> </record>