Skip to content

Commit

Permalink
[ADD] new module : account_invoice_default_code_column
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 10, 2023
1 parent 6e3c82c commit 48f87e7
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions account_invoice_default_code_column/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions account_invoice_default_code_column/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Invoices - Default Code Column",
"summary": "Display Default code product in a dedicated column on invoice reports",
"version": "12.0.1.0.1",
"category": "Invoicing",
"license": "AGPL-3",
"author": "GRAP,Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/grap/grap-odoo-incubator",
"depends": [
"account",
],
"data": [
"reports/report_account_invoice.xml",
],
"installable": True,
}
Empty file.
1 change: 1 addition & 0 deletions account_invoice_default_code_column/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_invoice_line
22 changes: 22 additions & 0 deletions account_invoice_default_code_column/models/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"

name_without_default_code = fields.Char(
compute="_compute_name_without_default_code"
)

@api.depends("name", "product_id.default_code")
def _compute_name_without_default_code(self):
for line in self:
line.name_without_default_code = line.name

Check warning on line 18 in account_invoice_default_code_column/models/account_invoice_line.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_default_code_column/models/account_invoice_line.py#L18

Added line #L18 was not covered by tests
if line.product_id and line.product_id.default_code:
line.name_without_default_code = line.name_without_default_code.replace(

Check warning on line 20 in account_invoice_default_code_column/models/account_invoice_line.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_default_code_column/models/account_invoice_line.py#L20

Added line #L20 was not covered by tests
f"[{line.product_id.default_code}]", ""
).strip()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
15 changes: 15 additions & 0 deletions account_invoice_default_code_column/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
In odoo, user has the possibility to rename the "description" field of an invoice line, and at the same time delete / alter the product code.
But in some situation, removing the product code is a problem, because it should be present on the invoice report.

This module avoids this problem.

For that purpose, this module adds a new dedicated column "Default code"
in the account invoice report.
As a side effect, it improves readability of the invoices.

**Without this module**

.. figure:: ../static/description/1_without_module.png

**With this module**
.. figure:: ../static/description/2_with_module.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<odoo>
<template
id="report_invoice_document"
inherit_id="account.report_invoice_document"
priority="1000"
>
<!-- Add 'default_code' Column in table header -->
<xpath expr="//th[@name='th_description']" position="before">
<th name="default_code" class="text-start"><span>Code</span></th>
</xpath>

<!-- Add 'default_code' Column in table body -->
<xpath expr="//td[@name='account_invoice_line_name']" position="before">
<td name="account_invoice_line_default_code">
<span t-if="line.product_id" t-field="line.product_id.default_code"/>
</td>
</xpath>

<!-- Replace 'name' column by 'name_without_default_code' column -->
<xpath expr="//td[@name='account_invoice_line_name']" position="replace">
<td name="account_invoice_line_name_without_default_code">
<span t-field="line.name_without_default_code" t-options="{'widget': 'text'}"/>
</td>
</xpath>

</template>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions setup/account_invoice_default_code_column/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 48f87e7

Please sign in to comment.