Skip to content

Commit

Permalink
[13.0][MIG] : hr_expense_invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Apr 7, 2020
1 parent ccf971b commit 12f0ea5
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 104 deletions.
18 changes: 10 additions & 8 deletions hr_expense_invoice/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Supplier invoices on HR expenses
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/12.0/hr_expense_invoice
:alt: OCA/hr
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--expense-lightgray.png?logo=github
:target: https://github.com/OCA/hr-expense/tree/13.0/hr_expense_invoice
:alt: OCA/hr-expense
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_expense_invoice
:target: https://translation.odoo-community.org/projects/hr-expense-13-0/hr-expense-13-0-hr_expense_invoice
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/116/12.0
:target: https://runbot.odoo-community.org/runbot/289/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -68,10 +68,10 @@ Known issues / Roadmap
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-expense/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_expense_invoice%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr-expense/issues/new?body=module:%20hr_expense_invoice%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -92,6 +92,8 @@ Contributors
* Vicent Cubells

* Kitti Upariphutthiphong <[email protected]>
* Rattapong Chokmasermkul <[email protected]>
* Saran Lim. <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -106,6 +108,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/12.0/hr_expense_invoice>`_ project on GitHub.
This module is part of the `OCA/hr-expense <https://github.com/OCA/hr-expense/tree/13.0/hr_expense_invoice>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_expense_invoice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"category": "Human Resources",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/hr",
"website": "https://github.com/OCA/hr-expense",
"depends": ["hr_expense"],
"data": ["views/hr_expense_views.xml", "wizard/expense_create_invoice.xml"],
"installable": True,
Expand Down
3 changes: 3 additions & 0 deletions hr_expense_invoice/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import hr_expense
from . import hr_expense_sheet
from . import account_payment
from . import account_move_line
from . import account_move
17 changes: 17 additions & 0 deletions hr_expense_invoice/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2019 Ecosoft <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

def _get_cash_basis_matched_percentage(self):
res = super()._get_cash_basis_matched_percentage()
if (
res == 1
and self._context.get("use_hr_expense_invoice")
and self._context.get("default_expense_line_ids")
):
return False
return res
5 changes: 2 additions & 3 deletions hr_expense_invoice/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright 2019 Kitti U. <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.multi
def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False):
if self._context.get("use_hr_expense_invoice"):
self = self.filtered(lambda l: not l.reconciled)
Expand Down
2 changes: 1 addition & 1 deletion hr_expense_invoice/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2019 Kitti U. <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, models
from odoo.exceptions import ValidationError

Expand Down
17 changes: 8 additions & 9 deletions hr_expense_invoice/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2015 Pedro M. Baeza <[email protected]>
# Copyright 2017 Vicent Cubells <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError
Expand All @@ -10,25 +10,22 @@ class HrExpense(models.Model):
_inherit = "hr.expense"

invoice_id = fields.Many2one(
comodel_name="account.invoice",
comodel_name="account.move",
string="Vendor Bill",
domain="[('type', '=', 'in_invoice'), ('state', '=', 'open')]",
oldname="invoice",
domain="[('type', '=', 'in_invoice'), ('state', '=', 'posted')]",
copy=False,
)

@api.multi
@api.constrains("invoice_id")
def _check_invoice_id(self):
for expense in self: # Only non binding expense
if (
not expense.sheet_id
and expense.invoice_id
and expense.invoice_id.state != "open"
and expense.invoice_id.state != "posted"
):
raise UserError(_("Vendor bill state must be Open"))
raise UserError(_("Vendor bill state must be Posted"))

@api.multi
def _get_account_move_line_values(self):
move_line_values_by_expense = super()._get_account_move_line_values()
for expense_id, move_lines in move_line_values_by_expense.items():
Expand All @@ -40,5 +37,7 @@ def _get_account_move_line_values(self):
move_line[
"partner_id"
] = expense.invoice_id.partner_id.commercial_partner_id.id
move_line["account_id"] = expense.invoice_id.account_id.id
move_line["account_id"] = expense.invoice_id.line_ids.filtered(
lambda l: l.account_internal_type == "payable"
).account_id.id
return move_line_values_by_expense
26 changes: 13 additions & 13 deletions hr_expense_invoice/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2015 Pedro M. Baeza <[email protected]>
# Copyright 2017 Vicent Cubells <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError
Expand All @@ -13,7 +13,6 @@ class HrExpenseSheet(models.Model):
invoice_count = fields.Integer(compute="_compute_invoice_count")
invoice_fully_created = fields.Boolean(compute="_compute_invoice_count")

@api.multi
def action_sheet_move_create(self):
expense_line_ids = self.mapped("expense_line_ids").filtered("invoice_id")
self._validate_expense_invoice(expense_line_ids)
Expand All @@ -27,17 +26,19 @@ def action_sheet_move_create(self):
c_move_lines |= move_lines.filtered(
lambda x: x.partner_id == partner and x.debit and not x.reconciled
)
c_move_lines |= line.invoice_id.move_id.line_ids.filtered(
lambda x: x.account_id == line.invoice_id.account_id
c_move_lines |= line.invoice_id.line_ids.filtered(
lambda x: x.account_id
== line.invoice_id.line_ids.filtered(
lambda l: l.account_internal_type == "payable"
).account_id
and x.credit
and not x.reconciled
)
c_move_lines.reconcile()
c_move_lines.with_context(use_hr_expense_invoice=True).reconcile()
return res

@api.multi
def _compute_invoice_count(self):
Invoice = self.env["account.invoice"]
Invoice = self.env["account.move"]
can_read = Invoice.check_access_rights("read", raise_exception=False)
for sheet in self:
sheet.invoice_count = (
Expand All @@ -55,10 +56,10 @@ def _validate_expense_invoice(self, expense_lines):
if not invoices:
return
# All invoices must confirmed
if any(invoices.filtered(lambda i: i.state != "open")):
raise UserError(_("Vendor bill state must be Open"))
if any(invoices.filtered(lambda i: i.state != "posted")):
raise UserError(_("Vendor bill state must be Posted"))
expense_amount = sum(expense_lines.mapped("total_amount"))
invoice_amount = sum(invoices.mapped("residual"))
invoice_amount = sum(invoices.mapped("amount_residual"))
# Expense amount must equal invoice amount
if float_compare(expense_amount, invoice_amount, precision) != 0:
raise UserError(
Expand All @@ -68,17 +69,16 @@ def _validate_expense_invoice(self, expense_lines):
)
)

@api.multi
def action_view_invoices(self):
self.ensure_one()
action = {
"name": _("Invoices"),
"type": "ir.actions.act_window",
"res_model": "account.invoice",
"res_model": "account.move",
"target": "current",
}
invoice_ids = self.expense_line_ids.mapped("invoice_id").ids
view = self.env.ref("account.invoice_supplier_form")
view = self.env.ref("account.view_move_form")
if len(invoice_ids) == 1:
invoice = invoice_ids[0]
action["res_id"] = invoice
Expand Down
2 changes: 2 additions & 0 deletions hr_expense_invoice/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
* Vicent Cubells

* Kitti Upariphutthiphong <[email protected]>
* Rattapong Chokmasermkul <[email protected]>
* Saran Lim. <[email protected]>
10 changes: 6 additions & 4 deletions hr_expense_invoice/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Supplier invoices on HR expenses</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/hr/tree/12.0/hr_expense_invoice"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_expense_invoice"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/116/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/hr-expense/tree/13.0/hr_expense_invoice"><img alt="OCA/hr-expense" src="https://img.shields.io/badge/github-OCA%2Fhr--expense-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/hr-expense-13-0/hr-expense-13-0-hr_expense_invoice"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/289/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module should be used when a supplier invoice is paid by an employee. It
allows to set a supplier invoice for each expense line, adding the
corresponding journal items to transfer the debt to the employee.</p>
Expand Down Expand Up @@ -419,10 +419,10 @@ <h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr-expense/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20hr_expense_invoice%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/hr-expense/issues/new?body=module:%20hr_expense_invoice%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -442,6 +442,8 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
</ul>
</li>
<li>Kitti Upariphutthiphong &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li>
<li>Rattapong Chokmasermkul &lt;<a class="reference external" href="mailto:rattapongc&#64;ecosoft.co.th">rattapongc&#64;ecosoft.co.th</a>&gt;</li>
<li>Saran Lim. &lt;<a class="reference external" href="mailto:saranl&#64;ecosoft.co.th">saranl&#64;ecosoft.co.th</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -451,7 +453,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/12.0/hr_expense_invoice">OCA/hr</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-expense/tree/13.0/hr_expense_invoice">OCA/hr-expense</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 12f0ea5

Please sign in to comment.