diff --git a/addons/account/wizard/account_payment_register.py b/addons/account/wizard/account_payment_register.py index a4a6fdca2a4..0d996f20ddc 100644 --- a/addons/account/wizard/account_payment_register.py +++ b/addons/account/wizard/account_payment_register.py @@ -89,7 +89,7 @@ class AccountPaymentRegister(models.TransientModel): compute='_compute_payment_difference') payment_difference_handling = fields.Selection([ ('open', 'Keep open'), - ('reconcile', 'Mark invoice as fully paid'), + ('reconcile', 'Mark as fully paid'), ], default='open', string="Payment Difference Handling") writeoff_account_id = fields.Many2one('account.account', string="Difference Account", copy=False, domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") diff --git a/addons/hr_expense/__manifest__.py b/addons/hr_expense/__manifest__.py index 006b2b39e56..a0b22f423d0 100644 --- a/addons/hr_expense/__manifest__.py +++ b/addons/hr_expense/__manifest__.py @@ -35,7 +35,6 @@ This module also uses analytic accounting and is compatible with the invoice on 'data/hr_expense_sequence.xml', 'data/hr_expense_data.xml', 'wizard/hr_expense_refuse_reason_views.xml', - 'wizard/hr_expense_sheet_register_payment.xml', 'views/hr_expense_views.xml', 'views/mail_activity_views.xml', 'security/ir_rule.xml', diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 741867c0a4d..025363ab5d5 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -772,6 +772,10 @@ class HrExpenseSheet(models.Model): payment_mode = fields.Selection(related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Paid By", tracking=True) user_id = fields.Many2one('res.users', 'Manager', compute='_compute_from_employee_id', store=True, readonly=True, copy=False, states={'draft': [('readonly', False)]}, tracking=True, domain=lambda self: [('groups_id', 'in', self.env.ref('hr_expense.group_hr_expense_team_approver').id)]) total_amount = fields.Monetary('Total Amount', currency_field='currency_id', compute='_compute_amount', store=True, tracking=True) + amount_residual = fields.Monetary( + string="Amount Due", store=True, + currency_field='currency_id', + compute='_compute_amount_residual') 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') @@ -794,6 +798,22 @@ class HrExpenseSheet(models.Model): for sheet in self: sheet.total_amount = sum(sheet.expense_line_ids.mapped('total_amount_company')) + @api.depends( + 'currency_id', + 'account_move_id.line_ids.amount_residual', + 'account_move_id.line_ids.amount_residual_currency', + 'account_move_id.line_ids.account_internal_type',) + def _compute_amount_residual(self): + for sheet in self: + if sheet.currency_id == sheet.company_id.currency_id: + residual_field = 'amount_residual' + else: + residual_field = 'amount_residual_currency' + + payment_term_lines = sheet.account_move_id.line_ids\ + .filtered(lambda line: line.account_internal_type in ('receivable', 'payable')) + sheet.amount_residual = -sum(payment_term_lines.mapped(residual_field)) + def _compute_attachment_number(self): for sheet in self: sheet.attachment_number = sum(sheet.expense_line_ids.mapped('attachment_number')) @@ -983,3 +1003,19 @@ class HrExpenseSheet(models.Model): user_id=expense_report.sudo()._get_responsible_for_approval().id or self.env.user.id) self.filtered(lambda hol: hol.state == 'approve').activity_feedback(['hr_expense.mail_act_expense_approval']) self.filtered(lambda hol: hol.state == 'cancel').activity_unlink(['hr_expense.mail_act_expense_approval']) + + def action_register_payment(self): + ''' Open the account.payment.register wizard to pay the selected journal entries. + :return: An action opening the account.payment.register wizard. + ''' + return { + 'name': _('Register Payment'), + 'res_model': 'account.payment.register', + 'view_mode': 'form', + 'context': { + 'active_model': 'account.move', + 'active_ids': self.account_move_id.ids, + }, + 'target': 'new', + 'type': 'ir.actions.act_window', + } diff --git a/addons/hr_expense/security/ir.model.access.csv b/addons/hr_expense/security/ir.model.access.csv index dfd8400da55..20b500b26c6 100644 --- a/addons/hr_expense/security/ir.model.access.csv +++ b/addons/hr_expense/security/ir.model.access.csv @@ -15,4 +15,3 @@ access_account_move_line_user,account.move.line.hr.expense.approver,account.mode access_account_analytic_line_user,account.analytic.line.user,account.model_account_analytic_line,hr_expense.group_hr_expense_team_approver,1,1,1,1 access_mail_activity_type_expense_user,mail.activity.type.expense.user,mail.model_mail_activity_type,hr_expense.group_hr_expense_manager,1,1,1,1 access_hr_expense_refuse_wizard,access.hr.expense.refuse.wizard,model_hr_expense_refuse_wizard,hr_expense.group_hr_expense_team_approver,1,1,1,0 -access_hr_expense_sheet_register_payment_wizard,access.hr.expense.sheet.register.payment.wizard,model_hr_expense_sheet_register_payment_wizard,account.group_account_manager,1,1,1,0 diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index 6e3120f0231..03b0a867595 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -495,7 +495,14 @@