Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD] hr_expense_advance_vendor #198

Open
wants to merge 3 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions hr_expense_advance_vendor/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
============================
HR Expense Advance to Vendor
============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:65169ced250aa638cee1d715bba0685bee97bd09a04eacc8c27d1caced8bb0d4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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--expense-lightgray.png?logo=github
:target: https://github.com/OCA/hr-expense/tree/15.0/hr_expense_advance_vendor
:alt: OCA/hr-expense
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-expense-15-0/hr-expense-15-0-hr_expense_advance_vendor
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-expense&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows the company to advance an amount to the vendor.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr-expense/issues/new?body=module:%20hr_expense_advance_vendor%0Aversion:%2015.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.

Credits
=======

Authors
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* `Ecosoft <http://ecosoft.co.th>`__:

* Pimolnat Suntian <pimolnats@ecosoft.co.th>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-ps-tubtim| image:: https://github.com/ps-tubtim.png?size=40px
:target: https://github.com/ps-tubtim
:alt: ps-tubtim

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ps-tubtim|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions hr_expense_advance_vendor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizard
18 changes: 18 additions & 0 deletions hr_expense_advance_vendor/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "HR Expense Advance to Vendor",
"version": "15.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-expense",
"license": "AGPL-3",
"category": "Human Resources",
"depends": ["hr_expense_advance_clearing", "hr_expense_pay_to_vendor"],
"data": [
"data/advance_product.xml",
"views/hr_expense_views.xml",
],
"installable": True,
"maintainers": ["ps-tubtim"],
}
13 changes: 13 additions & 0 deletions hr_expense_advance_vendor/data/advance_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="product_vendor_advance" model="product.product">
<field name="name">Vendor Advance</field>
<field name="default_code" />
<field name="type">service</field>
<field name="sale_ok" eval="False" />
<field name="purchase_ok" eval="False" />
<field name="can_be_expensed" eval="False" />
<field name="supplier_taxes_id" eval="False" />
<field name="taxes_id" eval="False" />
</record>
</odoo>
4 changes: 4 additions & 0 deletions hr_expense_advance_vendor/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import hr_expense
from . import hr_expense_sheet
46 changes: 46 additions & 0 deletions hr_expense_advance_vendor/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2023 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import _, api, models
from odoo.exceptions import ValidationError


class HrExpense(models.Model):
_inherit = "hr.expense"

@api.constrains("advance")
def _check_advance(self):
vendor_advance = self.env.ref(
"hr_expense_advance_vendor.product_vendor_advance"
)
for expense in self.filtered("advance"):
if expense.product_id != vendor_advance:
super(HrExpense, expense)._check_advance()
continue
if not vendor_advance.property_account_expense_id:
raise ValidationError(
_("Vendor advance product has no payable account")
)
if expense.account_id != vendor_advance.property_account_expense_id:
raise ValidationError(

Check warning on line 25 in hr_expense_advance_vendor/models/hr_expense.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense.py#L25

Added line #L25 was not covered by tests
_("Vendor advance, account must be the same payable account")
)
if expense.tax_ids:
raise ValidationError(_("Vendor advance, all taxes must be removed"))

Check warning on line 29 in hr_expense_advance_vendor/models/hr_expense.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense.py#L29

Added line #L29 was not covered by tests
if expense.payment_mode != "company_account":
raise ValidationError(_("Vendor advance, paid by must be company"))

Check warning on line 31 in hr_expense_advance_vendor/models/hr_expense.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense.py#L31

Added line #L31 was not covered by tests
return True

def _get_product_advance(self):
if self.advance and self.payment_mode == "company_account":
return self.env.ref("hr_expense_advance_vendor.product_vendor_advance")
return super()._get_product_advance()

Check warning on line 37 in hr_expense_advance_vendor/models/hr_expense.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense.py#L36-L37

Added lines #L36 - L37 were not covered by tests

@api.onchange("advance", "payment_mode")
def onchange_advance(self):
if self.advance and self.payment_mode == "company_account":
self.product_id = self.env.ref(
"hr_expense_advance_vendor.product_vendor_advance"
)
else:
return super().onchange_advance()
48 changes: 48 additions & 0 deletions hr_expense_advance_vendor/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2023 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import UserError


class HrExpenseSheet(models.Model):
_inherit = "hr.expense.sheet"

def _get_product_advance(self):
if any(rec.advance and rec.payment_mode == "company_account" for rec in self):
return self.env.ref("hr_expense_advance_vendor.product_vendor_advance")

Check warning on line 13 in hr_expense_advance_vendor/models/hr_expense_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense_sheet.py#L13

Added line #L13 was not covered by tests
return super()._get_product_advance()

def _update_sheets_pay_to_vendor(self):
"""No change state to post if document is clearing"""
clearing_pay_to_vendor = self.filtered(lambda l: l.advance_sheet_id)
if clearing_pay_to_vendor:
self = self.with_context(skip_check_clearing_amount=1)

Check warning on line 20 in hr_expense_advance_vendor/models/hr_expense_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense_sheet.py#L20

Added line #L20 was not covered by tests
clearing_less_advance = clearing_pay_to_vendor.filtered(
lambda l: not l.amount_residual
)
# clearing less than advance, do not update state to post
if clearing_less_advance:
return

Check warning on line 26 in hr_expense_advance_vendor/models/hr_expense_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense_sheet.py#L26

Added line #L26 was not covered by tests
return super()._update_sheets_pay_to_vendor()

@api.constrains("state")
def _check_constraint_clearing_amount(self):
if not self.env.context.get("skip_check_clearing_amount", False):
return super()._check_constraint_clearing_amount()

def action_submit_sheet(self):
"""Check clearing has value 'Paid By' or 'To Vendor' is not same as advance"""
for rec in self:
advance = rec.advance_sheet_id
if advance and (
rec.payment_mode != advance.payment_mode
or rec.vendor_id != advance.vendor_id
):
raise UserError(

Check warning on line 42 in hr_expense_advance_vendor/models/hr_expense_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_expense_advance_vendor/models/hr_expense_sheet.py#L42

Added line #L42 was not covered by tests
_(
"You cannot create a clearing document when 'Paid By' "
"or 'To Vendor' are not the same as the advance."
)
)
return super().action_submit_sheet()
3 changes: 3 additions & 0 deletions hr_expense_advance_vendor/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Ecosoft <http://ecosoft.co.th>`__:

* Pimolnat Suntian <pimolnats@ecosoft.co.th>
1 change: 1 addition & 0 deletions hr_expense_advance_vendor/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows the company to advance an amount to the vendor.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading