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 0456f5d
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 15 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
37 changes: 37 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,41 @@
</xpath>
</field>
</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="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_reporting"/>
<field name="action" ref="action_account_move_line_margin"/>
<field name="sequence">10</field>
</record>





</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,
}
63 changes: 63 additions & 0 deletions account_invoice_paid_data/i18n/account_invoice_paid_data.pot
Original file line number Diff line number Diff line change
@@ -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 ""
63 changes: 63 additions & 0 deletions account_invoice_paid_data/i18n/es.po
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions account_invoice_paid_data/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move_template
from . import account_move
38 changes: 38 additions & 0 deletions account_invoice_paid_data/models/account_move.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions account_invoice_paid_data/models/account_move_template.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions account_invoice_paid_data/views/account_move_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="account_move_view_tree" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree" />
<field name="arch" type="xml">
<field name="payment_state" position="after">
<field name="paid_date" optional="show" />
<field
name="payment_period"
optional="show"
attrs="{'invisible': ['|', ('paid_date', '=', False), ('invoice_date', '=', False)]}"
/>
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/account_invoice_paid_data/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 0456f5d

Please sign in to comment.