Skip to content

Commit

Permalink
Merge branch '14.0-account_invoice_margin' of github.com:unaiberis/od…
Browse files Browse the repository at this point in the history
…oo-addons into 14.0-account_invoice_margin
  • Loading branch information
unaiberis committed Nov 25, 2024
2 parents 3d9c1b6 + 61bffbf commit a127dc1
Show file tree
Hide file tree
Showing 15 changed files with 443 additions and 25 deletions.
2 changes: 1 addition & 1 deletion account_invoice_margin/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"summary": "Adds margin calculation fields to invoice lines and invoice totals.",
"website": "https://github.com/avanzosc/odoo-addons",
"license": "LGPL-3",
"depends": ["account"],
"depends": ["account", "account_invoice_line_report"],
"data": [
"views/account_invoice_line_views.xml",
"views/account_invoice_views.xml",
Expand Down
30 changes: 16 additions & 14 deletions account_invoice_margin/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@ class AccountInvoice(models.Model):
compute="_compute_total_margin",
store=True,
)
average_margin_percent = fields.Float(
string="Average Margin Percent",
compute="_compute_average_margin_percent",
total_margin_percent = fields.Float(
string="Total Margin Percent",
compute="_compute_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.total_product_cost = sum(
invoice.invoice_line_ids.mapped("product_cost")
)

@api.depends("invoice_line_ids.margin")
@api.depends("invoice_line_ids.subtotal_cost", "invoice_line_ids.price_total")
def _compute_total_margin(self):
for invoice in self:
invoice.total_margin = sum(invoice.invoice_line_ids.mapped("margin"))
total_cost = sum(invoice.invoice_line_ids.mapped("product_cost"))
total_sales = sum(invoice.invoice_line_ids.mapped("price_total"))
invoice.total_margin = total_sales - total_cost

@api.depends("invoice_line_ids.margin_percent")
def _compute_average_margin_percent(self):
@api.depends("total_margin", "invoice_line_ids.price_total")
def _compute_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
)
total_sales = sum(invoice.invoice_line_ids.mapped("price_total"))
if total_sales != 0:
invoice.total_margin_percent = (
invoice.total_margin / total_sales
) * 100
else:
invoice.average_margin_percent = 0
invoice.total_margin_percent = 0
140 changes: 140 additions & 0 deletions account_invoice_margin/views/account_invoice_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,144 @@
</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="arch" type="xml">
<pivot string="Invoice Line Margin Overview">
<field name="product_id" type="row"/>
<field name="move_id" type="col"/>
<field name="subtotal_cost" type="measure" widget="float"/>
<field name="margin" type="measure" widget="float"/>
<field name="margin_percent" type="measure" widget="float"/>
</pivot>
</field>
</record>

<record id="action_invoice_line_pivot_margin" model="ir.actions.act_window">
<field name="name">Invoice Line Margin Pivot</field>
<field name="res_model">account.move.line</field>
<field name="view_mode">pivot</field>
<field name="view_id" ref="view_invoice_line_pivot_margin"/>
</record>

<!-- CREATE TREE VIEW -->


<record id="view_invoice_tree_margin" model="ir.ui.view">
<field name="name">account.move.line.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="sequence" widget="handle" />
<field name="move_name" />
<field
name="product_id"
optional="show"
domain="context.get('default_move_type') in ('out_invoice', 'out_refund', 'out_receipt') and [('sale_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)] or [('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)] "
/>
<field
name="name"
widget="section_and_note_text"
attrs="{'required': [('parent.move_type', 'not in', ('in_invoice', 'in_refund','in_receipt'))]}"
/>
<field
name="account_id"
groups="account.group_account_readonly"
options="{'no_create': True}"
domain="[('deprecated', '=', False), ('user_type_id.type', 'not in', ('receivable', 'payable')), ('company_id', '=', parent.company_id), ('is_off_balance', '=', False)]"
attrs="{'required': [('display_type', '=', False)]}"
/>
<field
name="analytic_account_id"
domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
groups="analytic.group_analytic_accounting"
optional="show"
/>
<field
name="analytic_tag_ids"
domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
groups="analytic.group_analytic_tags"
optional="show"
widget="many2many_tags"
/>
<field name="quantity" />
<field name="product_uom_category_id" invisible="1" />
<field
name="product_uom_id"
string="UoM"
groups="uom.group_uom"
optional="show"
/>
<field name="price_unit" string="Price" />
<field name="discount" string="Disc.%" optional="hide" />
<field
name="tax_ids"
widget="many2many_tags"
domain="[('type_tax_use', '=?', parent.invoice_filter_type_domain), ('company_id', '=', parent.company_id)]"
context="{'append_type_to_tax_name': not parent.invoice_filter_type_domain}"
options="{'no_create': True}"
optional="show"
/>
<field
name="price_subtotal"
string="Subtotal"
groups="account.group_show_line_subtotals_tax_excluded"
/>
<field
name="price_total"
string="Total"
groups="account.group_show_line_subtotals_tax_included"
/>

<!-- Others fields -->
<field name="partner_id" invisible="1" />
<field name="amount_currency" invisible="1" />
<field name="currency_id" invisible="1" />
<field name="debit" invisible="1" />
<field name="credit" invisible="1" />
<field name="date" invisible="1" />
<field name="date_maturity" invisible="1" />

<field name="tax_line_id" invisible="1" />
<field name="tax_repartition_line_id" invisible="1" />
<field name="tax_tag_ids" invisible="1" />
<field name="tax_base_amount" invisible="1" />
<field name="tax_exigible" invisible="1" />
<field name="company_id" invisible="1" />
<field name="company_currency_id" invisible="1" />
<field name="recompute_tax_line" invisible="1" force_save="1" />
<field name="display_type" force_save="1" invisible="1" />
<field name="is_rounding_line" invisible="1" />
<field name="exclude_from_invoice_tab" invisible="1" />
<field name="account_internal_type" invisible="1" />
<field name="account_internal_group" invisible="1" />


<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="action_account_move_line_margin" model="ir.actions.act_window">
<field name="name">Invoice Lines (with Margin)</field>
<field name="res_model">account.move.line</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_invoice_tree_margin" />
<field name="target">current</field>
<field name="domain">[]</field>
</record>

<record id="account_move_line_menu_margin" model="ir.ui.menu">
<field name="name">Invoice Lines with Margin</field>
<field name="parent_id" ref="account.menu_finance_entries" />
<field name="action" ref="action_account_move_line_margin" />
<field name="sequence">10</field>
</record>
</odoo>
46 changes: 36 additions & 10 deletions account_invoice_margin/views/account_invoice_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<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_product_cost" optional="show" />
<field name="total_margin" optional="show" />
<field name="average_margin_percent" optional="show" />
<field name="total_margin_percent" optional="show" />
</xpath>
</field>
</record>
Expand All @@ -19,9 +19,9 @@
<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_product_cost" optional="show" />
<field name="total_margin" optional="show" />
<field name="average_margin_percent" optional="show" />
<field name="total_margin_percent" optional="show" />
</xpath>
</field>
</record>
Expand All @@ -32,9 +32,9 @@
<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_product_cost" />
<field name="total_margin" />
<field name="average_margin_percent" />
<field name="total_margin_percent" />
</xpath>
</field>
</record>
Expand All @@ -45,9 +45,9 @@
<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_product_cost" />
<field name="total_margin" />
<field name="average_margin_percent" />
<field name="total_margin_percent" />
</xpath>
</field>
</record>
Expand All @@ -58,10 +58,36 @@
<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_product_cost" />
<field name="total_margin" />
<field name="average_margin_percent" />
<field name="total_margin_percent" />
</xpath>
</field>
</record>

<record id="view_invoice_pivot_margin" model="ir.ui.view">
<field name="name">account.move.pivot.margin</field>
<field name="model">account.move</field>
<field name="arch" type="xml">
<pivot string="Invoice Margin Overview">
<field name="partner_id" type="row" />
<field name="invoice_date" type="col" />
<field name="total_product_cost" type="measure" widget="float" />
<field name="total_margin" type="measure" widget="float" />
<field name="total_margin_percent" type="measure" widget="float" />
</pivot>
</field>
</record>

<record id="action_invoice_pivot_margin" model="ir.actions.act_window">
<field name="name">Invoice Margin Overview</field>
<field name="res_model">account.move</field>
<field name="view_mode">pivot</field>
<field name="view_id" ref="view_invoice_pivot_margin" />
<field name="target">current</field>
<field name="context">{'search_default_filter_invoice': 1}</field>
</record>

<menuitem id="account_invoice_pivot_margin_menu" name="Invoice Margin Overview" parent="account.menu_finance_entries" action="action_invoice_pivot_margin"/>

</odoo>
33 changes: 33 additions & 0 deletions account_invoice_paid_data/README.rst
Original file line number Diff line number Diff line change
@@ -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 <oihanecrucelaegi@avanzosc.es>
* Ana Juaristi <anajuaristi@avanzosc.es>
1 change: 1 addition & 0 deletions account_invoice_paid_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions account_invoice_paid_data/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
Loading

0 comments on commit a127dc1

Please sign in to comment.