-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://github.com/avanzosc/odoo-addons/issues>`_. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Unai Beristain <unaiberistain@avanzosc.es> | ||
* Ana Juaristi <anajuaristi@avanzosc.es> | ||
|
||
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 <https://opensource.org/licenses/LGPL-3.0>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_invoice | ||
from . import account_invoice_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
58 changes: 58 additions & 0 deletions
58
account_invoice_margin/views/account_invoice_line_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="view_invoice_line_form_margin" model="ir.ui.view"> | ||
<field name="name">account.move.line.form.margin</field> | ||
<field name="model">account.move.line</field> | ||
<field name="inherit_id" ref="account.view_move_line_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//sheet/group" position="inside"> | ||
<field name="product_cost" /> | ||
<field name="subtotal_cost" /> | ||
<field name="margin" /> | ||
<field name="margin_percent" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_invoice_tree_margin" model="ir.ui.view"> | ||
<field name="name">account.move.tree.margin</field> | ||
<field name="model">account.move.line</field> | ||
<field name="inherit_id" ref="account.view_move_line_tree" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//tree" position="inside"> | ||
<field name="product_cost" optional="hide" /> | ||
<field name="subtotal_cost" optional="show" /> | ||
<field name="margin" optional="show" /> | ||
<field name="margin_percent" optional="show" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_invoice_line_pivot_margin" model="ir.ui.view"> | ||
<field name="name">account.move.line.pivot.margin</field> | ||
<field name="model">account.move.line</field> | ||
<field name="inherit_id" ref="account.view_move_line_pivot" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//pivot" position="inside"> | ||
<field name="product_cost" /> | ||
<field name="subtotal_cost" /> | ||
<field name="margin" /> | ||
<field name="margin_percent" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_invoice_filter_margin" model="ir.ui.view"> | ||
<field name="name">account.move.line.filter.margin</field> | ||
<field name="model">account.move.line</field> | ||
<field name="inherit_id" ref="account.view_account_move_line_filter" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//filter" position="inside"> | ||
<field name="product_cost" /> | ||
<field name="subtotal_cost" /> | ||
<field name="margin" /> | ||
<field name="margin_percent" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="view_out_invoice_tree_margin" model="ir.ui.view"> | ||
<field name="name">account.move.tree.margin</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_out_invoice_tree" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//tree" position="inside"> | ||
<field name="total_subtotal_cost" optional="show" /> | ||
<field name="total_margin" optional="show" /> | ||
<field name="average_margin_percent" optional="show" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_in_invoice_tree_margin" model="ir.ui.view"> | ||
<field name="name">account.move.tree.margin</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_in_invoice_tree" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//tree" position="inside"> | ||
<field name="total_subtotal_cost" optional="show" /> | ||
<field name="total_margin" optional="show" /> | ||
<field name="average_margin_percent" optional="show" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_account_move_kanban_margin" model="ir.ui.view"> | ||
<field name="name">account.move.kanban.margin</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_account_move_kanban" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//kanban" position="inside"> | ||
<field name="total_subtotal_cost" /> | ||
<field name="total_margin" /> | ||
<field name="average_margin_percent" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_move_form_margin" model="ir.ui.view"> | ||
<field name="name">account.move.form.margin</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//sheet/group" position="inside"> | ||
<field name="total_subtotal_cost" /> | ||
<field name="total_margin" /> | ||
<field name="average_margin_percent" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_account_move_filter_margin" model="ir.ui.view"> | ||
<field name="name">account.move.filter.margin</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_account_move_filter" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//filter" position="inside"> | ||
<field name="total_subtotal_cost" /> | ||
<field name="total_margin" /> | ||
<field name="average_margin_percent" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/account_invoice_margin/odoo/addons/account_invoice_margin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_invoice_margin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |