Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] hr_expense: reuse 'account.register.payments' model to pay empl…
…oyee expenses as well.
- Loading branch information
1 parent
9c37b68
commit 5f7061b
Showing
7 changed files
with
121 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import account_register_payments | ||
from . import hr_expense_refuse_reason | ||
from . import hr_expense_sheet_register_payment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from werkzeug import url_encode | ||
from odoo import api, fields, models, _ | ||
|
||
|
||
class AccountRegisterPayments(models.TransientModel): | ||
_inherit = "account.register.payments" | ||
|
||
expense_sheet_id = fields.Many2one('hr.expense.sheet') | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
vals = super(AccountRegisterPayments, self).default_get(fields) | ||
if not vals.get('expense_sheet_id'): | ||
return vals | ||
expense_sheet = self.env['hr.expense.sheet'].browse(vals.get('expense_sheet_id')) | ||
partner = expense_sheet.address_id or expense_sheet.employee_id.address_home_id | ||
vals.update( | ||
partner_type='supplier', | ||
payment_type='outbound', | ||
amount=abs(expense_sheet.total_amount), | ||
currency_id=expense_sheet.currency_id.id, | ||
partner_id=partner.id | ||
) | ||
return vals | ||
|
||
def _prepare_expense_payment_vals(self): | ||
partner = self.expense_sheet_id.address_id or self.expense_sheet_id.employee_id.address_home_id | ||
return { | ||
'journal_id': self.journal_id.id, | ||
'payment_method_id': self.payment_method_id.id, | ||
'payment_date': self.payment_date, | ||
'communication': self.communication, | ||
'partner_type': 'supplier', | ||
'payment_type': 'outbound', | ||
'amount': abs(self.expense_sheet_id.total_amount), | ||
'currency_id': self.expense_sheet_id.currency_id.id, | ||
'partner_id': partner.id | ||
} | ||
|
||
@api.multi | ||
def get_payments_vals(self): | ||
self.ensure_one() | ||
res = super(AccountRegisterPayments, self).get_payments_vals() | ||
if not self.expense_sheet_id: | ||
return res | ||
return [self._prepare_expense_payment_vals()] | ||
|
||
def _create_payments(self): | ||
payment = super(AccountRegisterPayments, self)._create_payments() | ||
if not self.expense_sheet_id: | ||
return payment | ||
|
||
# Log the payment in the chatter | ||
msg = _("A payment of %s %s with the reference <a href='/mail/view?%s'>%s</a> related to your expense <i>%s</i> has been made.") | ||
body = (msg % (payment.amount, payment.currency_id.symbol, url_encode({'model': 'account.payment', 'res_id': payment.id}), payment.name, self.expense_sheet_id.name)) | ||
self.expense_sheet_id.message_post(body=body) | ||
|
||
# Reconcile the payment and the expense, i.e. lookup on the payable account move lines | ||
account_move_lines_to_reconcile = self.env['account.move.line'] | ||
for line in payment.move_line_ids + self.expense_sheet_id.account_move_id.line_ids: | ||
if line.account_id.internal_type == 'payable': | ||
account_move_lines_to_reconcile |= line | ||
account_move_lines_to_reconcile.reconcile() | ||
return payment | ||
|
||
@api.multi | ||
def create_payments(self): | ||
self.ensure_one() | ||
res = super(AccountRegisterPayments, self).create_payments() | ||
if not self.expense_sheet_id: | ||
return res | ||
return {'type': 'ir.actions.act_window_close'} |
42 changes: 42 additions & 0 deletions
42
addons/hr_expense/wizard/account_register_payments_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_account_payment_from_invoices_inherit_hr_expense" model="ir.ui.view"> | ||
<field name="name">account.register.payments.wizard.inherited</field> | ||
<field name="model">account.register.payments</field> | ||
<field name="inherit_id" ref="account.view_account_payment_from_invoices"/> | ||
<field name="mode">primary</field> | ||
<field name="arch" type="xml"> | ||
<data> | ||
<field name="partner_id" position="attributes"> | ||
<attribute name="invisible">False</attribute> | ||
<attribute name="required">True</attribute> | ||
<attribute name="readonly">True</attribute> | ||
</field> | ||
<field name="journal_id" position="attributes"> | ||
<attribute name="default_focus">1</attribute> | ||
</field> | ||
<field name="payment_date" position="after"> | ||
<field name="expense_sheet_id" invisible="1"/> | ||
</field> | ||
<field name="currency_id" position="replace"/> | ||
<xpath expr="//field[@name='amount']" position="replace"> | ||
<label for="amount"/> | ||
<div name="amount_div" class="o_row"> | ||
<field name="amount"/> | ||
<field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency"/> | ||
</div> | ||
</xpath> | ||
</data> | ||
</field> | ||
</record> | ||
<!-- Expenses --> | ||
<record id="account_register_payments_wizard_action" model="ir.actions.act_window"> | ||
<field name="name">Register Payment</field> | ||
<field name="res_model">account.register.payments</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">form</field> | ||
<field name="view_id" ref="hr_expense.view_account_payment_from_invoices_inherit_hr_expense"/> | ||
<field name="target">new</field> | ||
<field name="context">{'default_expense_sheet_id': active_id}</field> | ||
</record> | ||
</odoo> |
93 changes: 0 additions & 93 deletions
93
addons/hr_expense/wizard/hr_expense_sheet_register_payment.py
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
addons/hr_expense/wizard/hr_expense_sheet_register_payment.xml
This file was deleted.
Oops, something went wrong.