Skip to content

Commit

Permalink
Merge PR #1407 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed May 2, 2024
2 parents b0214c5 + 116d46f commit 5194fce
Show file tree
Hide file tree
Showing 17 changed files with 1,099 additions and 0 deletions.
83 changes: 83 additions & 0 deletions account_invoice_alternate_payer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
===============================
Account Invoice Alternate Payer
===============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Faccount--invoicing-lightgray.png?logo=github
:target: https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_alternate_payer
:alt: OCA/account-invoicing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-invoicing-14-0/account-invoicing-14-0-account_invoice_alternate_payer
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/95/14.0
:alt: Try me on Runbot

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

This module allows to enter an alternative payer in the
customer invoice or vendor bill.

This allows, that we pay or expect to get paid by another partner other
than the main partner.

**Table of contents**

.. contents::
:local:

Usage
=====

Access to the invoice and change the Alternate Payor/Payee of the invoice.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/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/account-invoicing/issues/new?body=module:%20account_invoice_alternate_payer%0Aversion:%2014.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
~~~~~~~

* Eficent

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

* Eficent Business and IT Consulting Services, S.L. (https://www.eficent.com)
* Jordi Ballester Alomar <[email protected]>

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.

This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_alternate_payer>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_invoice_alternate_payer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions account_invoice_alternate_payer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Account Invoice Alternate Payer",
"summary": "Set a alternate payor/payee in invoices",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"category": "Accounting",
"author": "Eficent,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"depends": ["account"],
"data": ["views/account_move_views.xml"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_alternate_payer
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_invoice_alternate_payer
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_bank_statement_line__alternate_payer_id
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move__alternate_payer_id
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment__alternate_payer_id
#: model_terms:ir.ui.view,arch_db:account_invoice_alternate_payer.view_move_form
msgid "Alternate Payer"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move__display_name
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move_line__display_name
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment__display_name
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment_register__display_name
msgid "Display Name"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move__id
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move_line__id
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment__id
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment_register__id
msgid "ID"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model.fields,help:account_invoice_alternate_payer.field_account_bank_statement_line__alternate_payer_id
#: model:ir.model.fields,help:account_invoice_alternate_payer.field_account_move__alternate_payer_id
#: model:ir.model.fields,help:account_invoice_alternate_payer.field_account_payment__alternate_payer_id
msgid ""
"If set, this will be the partner that we expect to pay or to be paid by. If "
"not set, the payor is by default the commercial"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model,name:account_invoice_alternate_payer.model_account_move
msgid "Journal Entry"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model,name:account_invoice_alternate_payer.model_account_move_line
msgid "Journal Item"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move____last_update
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_move_line____last_update
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment____last_update
#: model:ir.model.fields,field_description:account_invoice_alternate_payer.field_account_payment_register____last_update
msgid "Last Modified on"
msgstr ""

#. module: account_invoice_alternate_payer
#: code:addons/account_invoice_alternate_payer/models/account_move.py:0
#, python-format
msgid "Outstanding credits"
msgstr ""

#. module: account_invoice_alternate_payer
#: code:addons/account_invoice_alternate_payer/models/account_move.py:0
#, python-format
msgid "Outstanding debits"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model,name:account_invoice_alternate_payer.model_account_payment
msgid "Payments"
msgstr ""

#. module: account_invoice_alternate_payer
#: model:ir.model,name:account_invoice_alternate_payer.model_account_payment_register
msgid "Register Payment"
msgstr ""
2 changes: 2 additions & 0 deletions account_invoice_alternate_payer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move
from . import account_payment
135 changes: 135 additions & 0 deletions account_invoice_alternate_payer/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import json

from odoo import _, api, fields, models
from odoo.tools import float_is_zero


class AccountMove(models.Model):

_inherit = "account.move"

alternate_payer_id = fields.Many2one(
"res.partner",
string="Alternate Payer",
readonly=True,
states={"draft": [("readonly", False)]},
help="If set, this will be the partner that we expect to pay or to "
"be paid by. If not set, the payor is by default the "
"commercial",
)

@api.depends("commercial_partner_id", "alternate_payer_id")
def _compute_bank_partner_id(self):
res = super(
AccountMove,
self.filtered(lambda r: not r.alternate_payer_id or not r.is_outbound()),
)._compute_bank_partner_id()
for move in self:
if move.is_outbound() and move.alternate_payer_id:
move.bank_partner_id = move.alternate_payer_id
return res

@api.onchange("alternate_payer_id")
def _onchange_alternate_payer_id(self):
return self._onchange_partner_id()

def _recompute_payment_terms_lines(self):
res = super()._recompute_payment_terms_lines()
for invoice in self:
if invoice.alternate_payer_id:
invoice.line_ids.filtered(
lambda r: r.account_id.user_type_id.type
in ("receivable", "payable")
).update({"partner_id": invoice.alternate_payer_id.id})
return res

def _compute_payments_widget_to_reconcile_info(self):
res = super(
AccountMove, self.filtered(lambda r: not r.alternate_payer_id)
)._compute_payments_widget_to_reconcile_info()
for move in self:
if not self.alternate_payer_id:
continue
move.invoice_outstanding_credits_debits_widget = json.dumps(False)
move.invoice_has_outstanding = False
if (
move.state != "posted"
or move.payment_state != "not_paid"
or not move.is_invoice(include_receipts=True)
):
continue
pay_term_line_ids = move.line_ids.filtered(
lambda line: line.account_id.user_type_id.type
in ("receivable", "payable")
)

domain = [
("account_id", "in", pay_term_line_ids.mapped("account_id").ids),
"|",
("move_id.state", "=", "posted"),
"&",
("move_id.state", "=", "draft"),
("partner_id", "=", move.alternate_payer_id.id),
("reconciled", "=", False),
"|",
("amount_residual", "!=", 0.0),
("amount_residual_currency", "!=", 0.0),
]

if move.is_inbound():
domain.extend([("credit", ">", 0), ("debit", "=", 0)])
type_payment = _("Outstanding credits")
else:
domain.extend([("credit", "=", 0), ("debit", ">", 0)])
type_payment = _("Outstanding debits")
info = {"title": "", "outstanding": True, "content": [], "move_id": move.id}
lines = self.env["account.move.line"].search(domain)
currency_id = move.currency_id
if len(lines) != 0:
for line in lines:
# get the outstanding residual value in invoice currency
if line.currency_id and line.currency_id == move.currency_id:
amount_to_show = abs(line.amount_residual_currency)
else:
currency = line.company_id.currency_id
amount_to_show = currency._convert(
abs(line.amount_residual),
move.currency_id,
move.company_id,
line.date or fields.Date.today(),
)
if float_is_zero(
amount_to_show, precision_rounding=move.currency_id.rounding
):
continue
info["content"].append(
{
"journal_name": line.ref or line.move_id.name,
"amount": amount_to_show,
"currency": currency_id.symbol,
"id": line.id,
"position": currency_id.position,
"digits": [69, move.currency_id.decimal_places],
"payment_date": fields.Date.to_string(line.date),
}
)
info["title"] = type_payment
move.invoice_outstanding_credits_debits_widget = json.dumps(info)
move.invoice_has_outstanding = True
return res


class AccountMoveLine(models.Model):

_inherit = "account.move.line"

def write(self, values):
# CHECK ME: this change to commercial partner when find difference between main partner
# https://github.com/odoo/odoo/blob/0f90852818a334d66ed8a6781f5abdc022f76ff7/addons/account/models/account_move.py#L2695 # noqa: B950
if "partner_id" in values and len(values.keys()) == 1:
lines_to_skip = self.filtered(lambda x: x.move_id.alternate_payer_id)
return super(AccountMoveLine, self - lines_to_skip).write(values)
return super(AccountMoveLine, self).write(values)
35 changes: 35 additions & 0 deletions account_invoice_alternate_payer/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class AccountPayment(models.Model):
_inherit = "account.payment"

@api.model
def default_get(self, default_fields):
rec = super().default_get(default_fields)
if self.env.context.get("active_model") != "account.move":
return rec
active_ids = self._context.get("active_ids")
invoices = (
self.env["account.move"]
.browse(active_ids)
.filtered(lambda move: move.is_invoice(include_receipts=True))
)
if invoices and invoices[0].alternate_payer_id:
rec.update({"partner_id": invoices[0].alternate_payer_id.id})
return rec


class AccountPaymentRegister(models.TransientModel):
_inherit = "account.payment.register"

def _prepare_payment_vals(self, invoices):
res = super()._prepare_payment_vals(invoices)
payer_id = (
invoices[0].alternate_payer_id.id or invoices[0].commercial_partner_id.id
)
res["partner_id"] = payer_id
return res
2 changes: 2 additions & 0 deletions account_invoice_alternate_payer/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Eficent Business and IT Consulting Services, S.L. (https://www.eficent.com)
* Jordi Ballester Alomar <[email protected]>
5 changes: 5 additions & 0 deletions account_invoice_alternate_payer/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module allows to enter an alternative payer in the
customer invoice or vendor bill.

This allows, that we pay or expect to get paid by another partner other
than the main partner.
1 change: 1 addition & 0 deletions account_invoice_alternate_payer/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Access to the invoice and change the Alternate Payor/Payee of the invoice.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5194fce

Please sign in to comment.