From 8207ab53ffa2bd743d391599fc7123b09dd883b1 Mon Sep 17 00:00:00 2001 From: Berezi Date: Thu, 7 Nov 2024 15:48:13 +0100 Subject: [PATCH 1/2] [14.0][ADD] account_invoice_paid_data: Pay fields in invoice. --- account_invoice_paid_data/README.rst | 33 ++++++++++ account_invoice_paid_data/__init__.py | 1 + account_invoice_paid_data/__manifest__.py | 17 +++++ .../i18n/account_invoice_paid_data.pot | 63 +++++++++++++++++++ account_invoice_paid_data/i18n/es.po | 63 +++++++++++++++++++ account_invoice_paid_data/models/__init__.py | 2 + .../models/account_move.py | 38 +++++++++++ .../models/account_move_template.py | 9 +++ .../views/account_move_views.xml | 17 +++++ .../odoo/addons/account_invoice_paid_data | 1 + setup/account_invoice_paid_data/setup.py | 6 ++ 11 files changed, 250 insertions(+) create mode 100644 account_invoice_paid_data/README.rst create mode 100644 account_invoice_paid_data/__init__.py create mode 100644 account_invoice_paid_data/__manifest__.py create mode 100644 account_invoice_paid_data/i18n/account_invoice_paid_data.pot create mode 100644 account_invoice_paid_data/i18n/es.po create mode 100644 account_invoice_paid_data/models/__init__.py create mode 100644 account_invoice_paid_data/models/account_move.py create mode 100644 account_invoice_paid_data/models/account_move_template.py create mode 100644 account_invoice_paid_data/views/account_move_views.xml create mode 120000 setup/account_invoice_paid_data/odoo/addons/account_invoice_paid_data create mode 100644 setup/account_invoice_paid_data/setup.py diff --git a/account_invoice_paid_data/README.rst b/account_invoice_paid_data/README.rst new file mode 100644 index 0000000000..487160d7e8 --- /dev/null +++ b/account_invoice_paid_data/README.rst @@ -0,0 +1,33 @@ +========================= +Account invoice paid data +========================= + +.. |badge1| 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 + +|badge1| + +This module extends accounting for Gausark: + +* paid date field in invoices tree that is filled when payment state changes to paid +* payment period field, days between invoice date and paid date + +**Table of contents** + +.. contents:: + :local: + +Credits +======= + +Authors +~~~~~~~ + +* Avanzosc + +Contributors +~~~~~~~~~~~~ + +* Oihane Crucelaegui +* Ana Juaristi diff --git a/account_invoice_paid_data/__init__.py b/account_invoice_paid_data/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/account_invoice_paid_data/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_paid_data/__manifest__.py b/account_invoice_paid_data/__manifest__.py new file mode 100644 index 0000000000..8be0ed805d --- /dev/null +++ b/account_invoice_paid_data/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2023 Oihane Crucelaegui - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account invoice paid data", + "version": "14.0.1.1.0", + "category": "Hidden", + "license": "AGPL-3", + "author": "AvanzOSC", + "website": "https://github.com/avanzosc/odoo-addons", + "depends": ["account", "account_move_template"], + "excludes": [], + "data": [ + "views/account_move_views.xml", + ], + "installable": True, +} diff --git a/account_invoice_paid_data/i18n/account_invoice_paid_data.pot b/account_invoice_paid_data/i18n/account_invoice_paid_data.pot new file mode 100644 index 0000000000..d5863b58d9 --- /dev/null +++ b/account_invoice_paid_data/i18n/account_invoice_paid_data.pot @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_paid_data +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-11-07 14:40+0000\n" +"PO-Revision-Date: 2024-11-07 14:40+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_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__display_name +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template__display_name +msgid "Display Name" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__id +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template__id +msgid "ID" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model,name:account_invoice_paid_data.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model,name:account_invoice_paid_data.model_account_move_template +msgid "Journal Entry Template" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move____last_update +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template__line_ids +msgid "Lines" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_bank_statement_line__paid_date +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__paid_date +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_payment__paid_date +msgid "Paid Date" +msgstr "" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_bank_statement_line__payment_period +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__payment_period +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_payment__payment_period +msgid "Payment Period" +msgstr "" diff --git a/account_invoice_paid_data/i18n/es.po b/account_invoice_paid_data/i18n/es.po new file mode 100644 index 0000000000..86df702f47 --- /dev/null +++ b/account_invoice_paid_data/i18n/es.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_paid_data +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-11-07 14:40+0000\n" +"PO-Revision-Date: 2024-11-07 14:40+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_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__display_name +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template__display_name +msgid "Display Name" +msgstr "Mostrar nombre" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__id +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template__id +msgid "ID" +msgstr "Identificador" + +#. module: account_invoice_paid_data +#: model:ir.model,name:account_invoice_paid_data.model_account_move +msgid "Journal Entry" +msgstr "Asiento contable" + +#. module: account_invoice_paid_data +#: model:ir.model,name:account_invoice_paid_data.model_account_move_template +msgid "Journal Entry Template" +msgstr "Plantilla de asiento" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move____last_update +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move_template__line_ids +msgid "Lines" +msgstr "Líneas" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_bank_statement_line__paid_date +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__paid_date +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_payment__paid_date +msgid "Paid Date" +msgstr "Fecha de pago" + +#. module: account_invoice_paid_data +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_bank_statement_line__payment_period +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_move__payment_period +#: model:ir.model.fields,field_description:account_invoice_paid_data.field_account_payment__payment_period +msgid "Payment Period" +msgstr "Periodo de pago" diff --git a/account_invoice_paid_data/models/__init__.py b/account_invoice_paid_data/models/__init__.py new file mode 100644 index 0000000000..904add1185 --- /dev/null +++ b/account_invoice_paid_data/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move_template +from . import account_move diff --git a/account_invoice_paid_data/models/account_move.py b/account_invoice_paid_data/models/account_move.py new file mode 100644 index 0000000000..6e9a91f853 --- /dev/null +++ b/account_invoice_paid_data/models/account_move.py @@ -0,0 +1,38 @@ +# Copyright 2023 Oihane Crucelaegui - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + paid_date = fields.Date( + compute="_compute_paid_date", + store=True, + copy=False, + readonly=True, + ) + payment_period = fields.Integer( + compute="_compute_payment_period", + store=True, + copy=False, + readonly=True, + ) + + @api.depends("payment_state") + def _compute_paid_date(self): + for move in self: + move.paid_date = ( + fields.Date.context_today(move) + if move.payment_state == "paid" + else False + ) + + @api.depends("paid_date", "invoice_date") + def _compute_payment_period(self): + for move in self: + period = 0 + if move.paid_date and move.invoice_date: + period = (move.paid_date - move.invoice_date).days + move.payment_period = period diff --git a/account_invoice_paid_data/models/account_move_template.py b/account_invoice_paid_data/models/account_move_template.py new file mode 100644 index 0000000000..0a3a69726a --- /dev/null +++ b/account_invoice_paid_data/models/account_move_template.py @@ -0,0 +1,9 @@ +# Copyright 2023 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class AccountMoveTemplate(models.Model): + _inherit = "account.move.template" + + line_ids = fields.One2many(copy=True) diff --git a/account_invoice_paid_data/views/account_move_views.xml b/account_invoice_paid_data/views/account_move_views.xml new file mode 100644 index 0000000000..01074b018b --- /dev/null +++ b/account_invoice_paid_data/views/account_move_views.xml @@ -0,0 +1,17 @@ + + + + account.move + + + + + + + + + diff --git a/setup/account_invoice_paid_data/odoo/addons/account_invoice_paid_data b/setup/account_invoice_paid_data/odoo/addons/account_invoice_paid_data new file mode 120000 index 0000000000..7e59f91729 --- /dev/null +++ b/setup/account_invoice_paid_data/odoo/addons/account_invoice_paid_data @@ -0,0 +1 @@ +../../../../account_invoice_paid_data \ No newline at end of file diff --git a/setup/account_invoice_paid_data/setup.py b/setup/account_invoice_paid_data/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/account_invoice_paid_data/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 61bffbff118a94614c40b3b09cc1674d4a0d53c5 Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Wed, 13 Nov 2024 10:47:05 +0100 Subject: [PATCH 2/2] [ADD] account_invoice_margin --- account_invoice_margin/README.rst | 75 +++++++++++++++++++ account_invoice_margin/__init__.py | 1 + account_invoice_margin/__manifest__.py | 15 ++++ account_invoice_margin/models/__init__.py | 2 + .../models/account_invoice.py | 44 +++++++++++ .../models/account_invoice_line.py | 44 +++++++++++ .../views/account_invoice_line_views.xml | 58 ++++++++++++++ .../views/account_invoice_views.xml | 67 +++++++++++++++++ .../odoo/addons/account_invoice_margin | 1 + setup/account_invoice_margin/setup.py | 6 ++ 10 files changed, 313 insertions(+) create mode 100644 account_invoice_margin/README.rst create mode 100644 account_invoice_margin/__init__.py create mode 100644 account_invoice_margin/__manifest__.py create mode 100644 account_invoice_margin/models/__init__.py create mode 100644 account_invoice_margin/models/account_invoice.py create mode 100644 account_invoice_margin/models/account_invoice_line.py create mode 100644 account_invoice_margin/views/account_invoice_line_views.xml create mode 100644 account_invoice_margin/views/account_invoice_views.xml create mode 120000 setup/account_invoice_margin/odoo/addons/account_invoice_margin create mode 100644 setup/account_invoice_margin/setup.py diff --git a/account_invoice_margin/README.rst b/account_invoice_margin/README.rst new file mode 100644 index 0000000000..09d04b5449 --- /dev/null +++ b/account_invoice_margin/README.rst @@ -0,0 +1,75 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: https://opensource.org/licenses/LGPL-3.0 + :alt: License: LGPL-3 + +=========================================== +Account Invoice Margin +=========================================== + +Overview +======== + +The **Account Invoice Margin** module adds margin calculation fields to invoice lines and invoice totals. It allows businesses to track and analyze the margin on individual invoice lines and the overall invoice margin, as well as the margin percentage. + +Features +======== + +- **Margin Fields on Invoice Lines**: Adds fields for calculating product cost, subtotal cost, margin, and margin percentage on invoice lines. + +- **Margin Calculation on Invoice**: Computes the total margin, total subtotal cost, and average margin percentage at the invoice level. + +Usage +===== + +1. **Install the Module**: + + - Install the **Account Invoice Margin** module via the Apps menu. + +2. **View Margin Information**: + + - On the **Invoice Line** form, you will see the calculated fields for **Product Cost**, **Subtotal Cost**, **Margin**, and **Margin Percent**. + + - The **Invoice Form** will display the **Total Subtotal Cost**, **Total Margin**, and **Average Margin Percent**. + +3. **Analyze Invoice Margins**: + + - Use the **Invoice Pivot** view to analyze the total margin, subtotal cost, and average margin percentage for invoices. + +Configuration +============= + +No additional configuration is required. Simply install the module to start using the margin calculation features. + +Testing +======= + +Test the following scenarios to ensure the module functions as expected: + +- **Test Margin Calculation**: + + - Create an invoice and check that the **Subtotal Cost**, **Margin**, and **Margin Percent** are calculated correctly for each invoice line. + +- **Test Total and Average Margin**: + + - Verify that the **Total Subtotal Cost**, **Total Margin**, and **Average Margin Percent** are correctly calculated at the invoice level. + +Bug Tracker +=========== + +If you encounter any issues, please report them on the GitHub repository at `GitHub Issues `_. + +Credits +======= + +Contributors +------------ + +* Unai Beristain +* Ana Juaristi + +For specific questions regarding this module, please contact the contributors. For support, please use the official issue tracker. + +License +======= + +This project is licensed under the LGPL-3 License. For more details, refer to the LICENSE file or visit . diff --git a/account_invoice_margin/__init__.py b/account_invoice_margin/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/account_invoice_margin/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_margin/__manifest__.py b/account_invoice_margin/__manifest__.py new file mode 100644 index 0000000000..f75f9f44b4 --- /dev/null +++ b/account_invoice_margin/__manifest__.py @@ -0,0 +1,15 @@ +{ + "name": "Account Invoice Margin", + "version": "14.0.1.0.0", + "author": "Avanzosc", + "summary": "Adds margin calculation fields to invoice lines and invoice totals.", + "website": "https://github.com/avanzosc/odoo-addons", + "license": "LGPL-3", + "depends": ["account"], + "data": [ + "views/account_invoice_line_views.xml", + "views/account_invoice_views.xml", + ], + "installable": True, + "application": False, +} diff --git a/account_invoice_margin/models/__init__.py b/account_invoice_margin/models/__init__.py new file mode 100644 index 0000000000..114ef8e753 --- /dev/null +++ b/account_invoice_margin/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_invoice +from . import account_invoice_line diff --git a/account_invoice_margin/models/account_invoice.py b/account_invoice_margin/models/account_invoice.py new file mode 100644 index 0000000000..202be7b579 --- /dev/null +++ b/account_invoice_margin/models/account_invoice.py @@ -0,0 +1,44 @@ +from odoo import api, fields, models + + +class AccountInvoice(models.Model): + _inherit = "account.move" + + total_product_cost = fields.Float( + string="Total Product Cost", + compute="_compute_total_product_cost", + store=True, + ) + total_margin = fields.Float( + string="Total Margin", + compute="_compute_total_margin", + store=True, + ) + average_margin_percent = fields.Float( + string="Average Margin Percent", + compute="_compute_average_margin_percent", + store=True, + ) + + @api.depends("invoice_line_ids.subtotal_cost") + def _compute_total_product_cost(self): + for invoice in self: + invoice.total_subtotal_cost = sum( + invoice.invoice_line_ids.mapped("product_cost") + ) + + @api.depends("invoice_line_ids.margin") + def _compute_total_margin(self): + for invoice in self: + invoice.total_margin = sum(invoice.invoice_line_ids.mapped("margin")) + + @api.depends("invoice_line_ids.margin_percent") + def _compute_average_margin_percent(self): + for invoice in self: + margin_percent_values = invoice.invoice_line_ids.mapped("margin_percent") + if margin_percent_values: + invoice.average_margin_percent = sum(margin_percent_values) / len( + margin_percent_values + ) + else: + invoice.average_margin_percent = 0 diff --git a/account_invoice_margin/models/account_invoice_line.py b/account_invoice_margin/models/account_invoice_line.py new file mode 100644 index 0000000000..d3cf2452e0 --- /dev/null +++ b/account_invoice_margin/models/account_invoice_line.py @@ -0,0 +1,44 @@ +from odoo import api, fields, models + + +class AccountInvoiceLine(models.Model): + _inherit = "account.move.line" + + product_cost = fields.Float( + string="Product Cost", + related="product_id.standard_price", + store=True, + ) + subtotal_cost = fields.Float( + string="Subtotal Cost", + compute="_compute_subtotal_cost", + store=True, + ) + margin = fields.Float( + string="Margin", + compute="_compute_margin", + store=True, + ) + margin_percent = fields.Float( + string="Margin Percent", + compute="_compute_margin_percent", + store=True, + ) + + @api.depends("product_cost", "quantity") + def _compute_subtotal_cost(self): + for line in self: + line.subtotal_cost = line.product_cost * line.quantity + + @api.depends("subtotal_cost", "price_subtotal") + def _compute_margin(self): + for line in self: + line.margin = line.price_subtotal - line.subtotal_cost + + @api.depends("margin", "price_subtotal") + def _compute_margin_percent(self): + for line in self: + if line.price_subtotal != 0: + line.margin_percent = (line.margin / line.price_subtotal) * 100 + else: + line.margin_percent = 0 diff --git a/account_invoice_margin/views/account_invoice_line_views.xml b/account_invoice_margin/views/account_invoice_line_views.xml new file mode 100644 index 0000000000..2b3d3df87a --- /dev/null +++ b/account_invoice_margin/views/account_invoice_line_views.xml @@ -0,0 +1,58 @@ + + + + account.move.line.form.margin + account.move.line + + + + + + + + + + + + + account.move.tree.margin + account.move.line + + + + + + + + + + + + + account.move.line.pivot.margin + account.move.line + + + + + + + + + + + + + account.move.line.filter.margin + account.move.line + + + + + + + + + + + diff --git a/account_invoice_margin/views/account_invoice_views.xml b/account_invoice_margin/views/account_invoice_views.xml new file mode 100644 index 0000000000..eb17a9b6e3 --- /dev/null +++ b/account_invoice_margin/views/account_invoice_views.xml @@ -0,0 +1,67 @@ + + + + account.move.tree.margin + account.move + + + + + + + + + + + + account.move.tree.margin + account.move + + + + + + + + + + + + account.move.kanban.margin + account.move + + + + + + + + + + + + account.move.form.margin + account.move + + + + + + + + + + + + account.move.filter.margin + account.move + + + + + + + + + + diff --git a/setup/account_invoice_margin/odoo/addons/account_invoice_margin b/setup/account_invoice_margin/odoo/addons/account_invoice_margin new file mode 120000 index 0000000000..d31e24ea96 --- /dev/null +++ b/setup/account_invoice_margin/odoo/addons/account_invoice_margin @@ -0,0 +1 @@ +../../../../account_invoice_margin \ No newline at end of file diff --git a/setup/account_invoice_margin/setup.py b/setup/account_invoice_margin/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/account_invoice_margin/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)