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

[ADD] credit note information on res partner #384

Open
wants to merge 3 commits into
base: 16.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
1 change: 1 addition & 0 deletions account_invoice_overdue_warn/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"website": "https://github.com/OCA/credit-control",
"depends": ["account"],
"data": [
"views/res_config_settings_views.xml",
"views/res_partner.xml",
],
"installable": True,
Expand Down
46 changes: 44 additions & 2 deletions account_invoice_overdue_warn/i18n/account_invoice_overdue_warn.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,68 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-26 16:06+0000\n"
"PO-Revision-Date: 2024-06-26 16:06+0000\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_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__credit_note_count
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__credit_note_count
msgid "# of Credit Note"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__overdue_invoice_count
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__overdue_invoice_count
msgid "# of Overdue Invoices"
msgstr ""

#. module: account_invoice_overdue_warn
#: model_terms:ir.ui.view,arch_db:account_invoice_overdue_warn.res_config_settings_view_form
msgid "Activate to show credit note due alert on partner"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model,name:account_invoice_overdue_warn.model_res_company
msgid "Companies"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model,name:account_invoice_overdue_warn.model_res_config_settings
msgid "Config Settings"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model,name:account_invoice_overdue_warn.model_res_partner
msgid "Contact"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__credit_note
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__credit_note
#: model_terms:ir.ui.view,arch_db:account_invoice_overdue_warn.view_partner_form_overdue_warn
msgid "Credit Note"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__credit_note_amount
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__credit_note_amount
msgid "Credit Note Residual"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_company__credit_note_partner
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_config_settings__credit_note_partner
msgid "Credit note on partner"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__overdue_invoice_amount
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__overdue_invoice_amount
Expand All @@ -49,4 +91,4 @@ msgstr ""
#. module: account_invoice_overdue_warn
#: model_terms:ir.ui.view,arch_db:account_invoice_overdue_warn.view_partner_form_overdue_warn
msgid "overdue invoice(s)"
msgstr ""
msgstr ""
65 changes: 47 additions & 18 deletions account_invoice_overdue_warn/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,67 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-08-28 16:49+0000\n"
"PO-Revision-Date: 2024-03-02 14:37+0000\n"
"Last-Translator: Alexis de Lattre <[email protected]>\n"
"POT-Creation-Date: 2024-06-26 16:02+0000\n"
"PO-Revision-Date: 2024-06-26 16:02+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"X-Generator: Weblate 4.17\n"
"Plural-Forms: \n"

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__credit_note_count
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__credit_note_count
msgid "# of Credit Note"
msgstr "# de Note de Crédit"

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__overdue_invoice_count
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__overdue_invoice_count
msgid "# of Overdue Invoices"
msgstr "Nb de factures échues impayées"

#. module: account_invoice_overdue_warn
#: model_terms:ir.ui.view,arch_db:account_invoice_overdue_warn.res_config_settings_view_form
msgid "Activate to show credit note due alert on partner"
msgstr "Activer pour voir les notes de crédit due sur le partenaire"

#. module: account_invoice_overdue_warn
#: model:ir.model,name:account_invoice_overdue_warn.model_res_company
msgid "Companies"
msgstr "Sociétés"

#. module: account_invoice_overdue_warn
#: model:ir.model,name:account_invoice_overdue_warn.model_res_config_settings
msgid "Config Settings"
msgstr "Paramètres de configuration"

#. module: account_invoice_overdue_warn
#: model:ir.model,name:account_invoice_overdue_warn.model_res_partner
msgid "Contact"
msgstr "Contact"
msgstr ""

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__credit_note
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__credit_note
#: model_terms:ir.ui.view,arch_db:account_invoice_overdue_warn.view_partner_form_overdue_warn
msgid "Credit Note"
msgstr "Note de crédit"

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__credit_note_amount
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_users__credit_note_amount
msgid "Credit Note Residual"
msgstr "Note de crédit résiduel"

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_company__credit_note_partner
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_config_settings__credit_note_partner
msgid "Credit note on partner"
msgstr "Note de crédit sur le partenaire"

#. module: account_invoice_overdue_warn
#: model:ir.model.fields,field_description:account_invoice_overdue_warn.field_res_partner__overdue_invoice_amount
Expand Down Expand Up @@ -54,13 +92,4 @@ msgstr "pour un montant impayé de"
#. module: account_invoice_overdue_warn
#: model_terms:ir.ui.view,arch_db:account_invoice_overdue_warn.view_partner_form_overdue_warn
msgid "overdue invoice(s)"
msgstr "facture(s) échue(s) impayées(s)"

#~ msgid "Display Name"
#~ msgstr "Nom affiché"

#~ msgid "ID"
#~ msgstr "ID"

#~ msgid "Last Modified on"
#~ msgstr "Dernière modification le"
msgstr "facture(s) échue(s) impayées(s)"
2 changes: 2 additions & 0 deletions account_invoice_overdue_warn/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import res_company
from . import res_config_settings
from . import res_partner
13 changes: 13 additions & 0 deletions account_invoice_overdue_warn/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Akretion France (http://www.akretion.com/)
# @author: Mathieu Delva <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

credit_note_partner = fields.Boolean(
string="Credit note on partner",
)
13 changes: 13 additions & 0 deletions account_invoice_overdue_warn/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Akretion France (http://www.akretion.com/)
# @author: Mathieu Delva <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

credit_note_partner = fields.Boolean(
related="company_id.credit_note_partner", readonly=False
)
81 changes: 81 additions & 0 deletions account_invoice_overdue_warn/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
help="Overdue invoice total residual amount in company currency.",
)

credit_note = fields.Boolean(compute="_compute_credit_note", compute_sudo=True)
credit_note_count = fields.Integer(
compute="_compute_credit_note_count_amount",
string="# of Credit Note",
compute_sudo=True,
)

credit_note_amount = fields.Monetary(
compute="_compute_credit_note_count_amount",
string="Credit Note Residual",
compute_sudo=True,
)

def _compute_overdue_invoice_count_amount(self):
for partner in self:
company_id = partner.company_id.id or partner.env.company.id
Expand Down Expand Up @@ -82,3 +95,71 @@
company_id = self.company_id.id or self.env.company.id
action = self._prepare_jump_to_overdue_invoices(company_id)
return action

def _compute_credit_note(self):
for partner in self:
company_id = partner.company_id or partner.env.company
partner.credit_note = company_id.credit_note_partner

def _compute_credit_note_count_amount(self):
for partner in self:
company_id = partner.company_id.id or partner.env.company.id
(
count,
amount_company_currency,
) = partner._prepare_credit_note_count_amount(company_id)
partner.credit_note_count = count
partner.credit_note_amount = amount_company_currency

def _prepare_credit_note_count_amount(self, company_id):
self.ensure_one()
domain = self._prepare_credit_note_domain(company_id)
# amount_residual_signed is in company currency
rg_res = self.env["account.move"].read_group(
domain, ["amount_residual_signed"], []
)
count = 0
overdue_invoice_amount = 0.0
if rg_res:
count = rg_res[0]["__count"]
overdue_invoice_amount = (
abs(rg_res[0]["amount_residual_signed"])
if rg_res[0]["amount_residual_signed"]
else rg_res[0]["amount_residual_signed"]
)
return (count, overdue_invoice_amount)

def _prepare_credit_note_domain(self, company_id):
# The use of commercial_partner_id is in this method
self.ensure_one()
today = fields.Date.context_today(self)
if company_id is None:
company_id = self.env.company.id

Check warning on line 137 in account_invoice_overdue_warn/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_warn/models/res_partner.py#L137

Added line #L137 was not covered by tests
domain = [
("move_type", "=", "out_refund"),
("company_id", "=", company_id),
("commercial_partner_id", "=", self.commercial_partner_id.id),
("invoice_date", "<", today),
("state", "=", "posted"),
("payment_state", "in", ("not_paid", "partial")),
]
return domain

def _prepare_jump_to_credit_note(self, company_id):
action = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 149 in account_invoice_overdue_warn/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_warn/models/res_partner.py#L149

Added line #L149 was not covered by tests
"account.action_move_out_refund_type"
)
action["domain"] = self._prepare_credit_note_domain(company_id)
action["context"] = {

Check warning on line 153 in account_invoice_overdue_warn/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_warn/models/res_partner.py#L152-L153

Added lines #L152 - L153 were not covered by tests
"journal_type": "sale",
"move_type": "out_refund",
"default_move_type": "out_refund",
"default_partner_id": self.id,
}
return action

Check warning on line 159 in account_invoice_overdue_warn/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_warn/models/res_partner.py#L159

Added line #L159 was not covered by tests

def jump_to_credit_note(self):
self.ensure_one()
company_id = self.company_id.id or self.env.company.id
action = self._prepare_jump_to_credit_note(company_id)
return action

Check warning on line 165 in account_invoice_overdue_warn/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_warn/models/res_partner.py#L162-L165

Added lines #L162 - L165 were not covered by tests
12 changes: 7 additions & 5 deletions account_invoice_overdue_warn/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -422,7 +422,9 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<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>
Expand Down
1 change: 1 addition & 0 deletions account_invoice_overdue_warn/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_credit_note_warn
from . import test_overdue_warn
Loading
Loading