Skip to content

Commit

Permalink
[ADD] portal_multicurrency_totals: Show multicurrency totals on portal
Browse files Browse the repository at this point in the history
This module adds te feature to display total amounts by currency when
accessing documents through the portal:
- Quotations
- Sale orders
- Invoices
  • Loading branch information
luisg123v committed Dec 30, 2021
1 parent d581142 commit 08280b0
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 0 deletions.
56 changes: 56 additions & 0 deletions portal_multicurrency_totals/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Multi-Currency Totals in Portal
===============================

This module adds te feature to display total amounts by currency when accessing
documents through the portal:

- Quotations
- Sale orders
- Invoices

Usage
=====

To use this module, just go to the portal and open a document list; you will see an extra footer with totals by currency.

When accessing quotations or sale orders, a total will be displayed per
currency:

.. image:: portal_multicurrency_totals/static/description/totals_in_so.png
:width: 400pt
:alt: Totals in sale orders

When accessing invoices, paid and unpaid amounts will also be available:

.. image:: portal_multicurrency_totals/static/description/totals_in_invoices.png
:width: 400pt
:alt: Totals in invoices

**Note**:
Even though records in state draft or cancelled may be displayed if they were
validated in some point, they're not considered when computing totals.

Credits
=======

Contributors
------------

* Luis González <lgonzalez@vauxoo.com>


Maintainer
==========

.. image:: https://www.vauxoo.com/logo.png
:alt: Vauxoo
:target: https://vauxoo.com

This module is maintained by Vauxoo.

a latinamerican company that provides training, coaching,
development and implementation of enterprise management
systems and bases its entire operation strategy in the use
of Open Source Software and its main product is Odoo.

To contribute to this module, please visit https://www.vauxoo.com.
1 change: 1 addition & 0 deletions portal_multicurrency_totals/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
21 changes: 21 additions & 0 deletions portal_multicurrency_totals/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Multi-Currency Totals in Portal",
"author": "Vauxoo",
"website": "https://www.vauxoo.com",
"license": "LGPL-3",
"category": "Sales/Sales",
"version": "14.0.1.0.0",
"depends": [
"sale",
],
"data": [
"views/portal_templates.xml",
],
"demo": [
"demo/product_pricelist_demo.xml",
"demo/res_partner_demo.xml",
"demo/sale_order_demo.xml",
],
"installable": True,
"auto_install": False,
}
1 change: 1 addition & 0 deletions portal_multicurrency_totals/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
53 changes: 53 additions & 0 deletions portal_multicurrency_totals/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from odoo import http

from odoo.addons.account.controllers.portal import PortalAccount as PA
from odoo.addons.sale.controllers.portal import CustomerPortal as CP


class CustomerPortal(CP):
def _totals_by_currency(self, records):
"""Compute total amounts for invoices and sale orders, grouped by currency"""
if not records:
return {}
currencies = records.currency_id
totals_by_currency = {
currency: {
"amount": 0.0,
}
for currency in currencies
}
for record in records.filtered(lambda inv: inv.state not in ("draft", "cancel")):
totals_this_currency = totals_by_currency[record.currency_id]
totals_this_currency["amount"] += record.amount_total
if "amount_residual" in record:
totals_this_currency.setdefault("unpaid", 0.0)
totals_this_currency.setdefault("paid", 0.0)
totals_this_currency["unpaid"] += record.amount_residual
totals_this_currency["paid"] += record.amount_total - record.amount_residual

return totals_by_currency

@http.route(["/my/quotes", "/my/quotes/page/<int:page>"], type="http", auth="user", website=True)
def portal_my_quotes(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
response = super().portal_my_quotes(page=page, date_begin=date_begin, date_end=date_end, sortby=sortby, **kw)
quotations = response.qcontext.get("quotations")
response.qcontext["totals_by_currency"] = self._totals_by_currency(quotations)
return response

@http.route(["/my/orders", "/my/orders/page/<int:page>"], type="http", auth="user", website=True)
def portal_my_orders(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
response = super().portal_my_orders(page=page, date_begin=date_begin, date_end=date_end, sortby=sortby, **kw)
orders = response.qcontext.get("orders")
response.qcontext["totals_by_currency"] = self._totals_by_currency(orders)
return response


class PortalAccount(PA):
@http.route(["/my/invoices", "/my/invoices/page/<int:page>"], type="http", auth="user", website=True)
def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw):
response = super().portal_my_invoices(
page=page, date_begin=date_begin, date_end=date_end, sortby=sortby, filterby=filterby, **kw
)
invoices = response.qcontext.get("invoices")
response.qcontext["totals_by_currency"] = self._totals_by_currency(invoices)
return response
10 changes: 10 additions & 0 deletions portal_multicurrency_totals/demo/product_pricelist_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="pricelist_usd" model="product.pricelist">
<field name="name">Pricelist in USD</field>
<field name="sequence" eval="10" />
<field name="currency_id" ref="base.USD" />
</record>

</odoo>
44 changes: 44 additions & 0 deletions portal_multicurrency_totals/demo/res_partner_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<!-- Grant portal access to the customer -->
<record id="grant_portal_access" model="portal.wizard">
<field
name="user_ids"
model="res.partner"
eval="[
(0, 0, {
'partner_id': ref('base.res_partner_3'),
'email': obj(ref('base.res_partner_3')).email,
'in_portal': True,
}),
]"
/>
</record>
<function
model="portal.wizard"
name="action_apply"
eval="[ref('grant_portal_access')]"
/>

<!-- Set a password for the portal user so it may log-in -->
<record id="set_password_portal_user" model="change.password.wizard">
<field
name="user_ids"
model="res.partner"
eval="[
(0, 0, {
'user_id': obj(ref('base.res_partner_3')).user_ids.id,
'user_login': obj(ref('base.res_partner_3')).email,
'new_passwd': obj(ref('base.res_partner_3')).email,
}),
]"
/>
</record>
<function
model="change.password.wizard"
name="change_password_button"
eval="[ref('set_password_portal_user')]"
/>

</odoo>
31 changes: 31 additions & 0 deletions portal_multicurrency_totals/demo/sale_order_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="sale_order_usd" model="sale.order">
<field name="partner_id" ref="base.res_partner_3" />
<field name="partner_invoice_id" ref="base.res_partner_address_25" />
<field name="partner_shipping_id" ref="base.res_partner_address_25" />
<field name="user_id" ref="base.user_admin" />
<field name="pricelist_id" ref="pricelist_usd" />
</record>

<record id="sale_order_usd_line" model="sale.order.line">
<field name="order_id" ref="sale_order_usd" />
<field
name="name"
model="product.product"
eval="obj(ref('product.product_product_1')).get_product_multiline_description_sale()"
/>
<field name="product_id" ref="product.product_product_1" />
<field name="product_uom_qty" eval="2" />
<field name="product_uom" ref="uom.product_uom_hour" />
<field name="price_unit" eval="75.0" />
</record>

<function
model="sale.order"
name="action_confirm"
eval="[[ref('sale_order_usd')]]"
/>

</odoo>
46 changes: 46 additions & 0 deletions portal_multicurrency_totals/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * portal_multicurrency_totals
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-28 22:52+0000\n"
"PO-Revision-Date: 2021-12-28 22:52+0000\n"
"Last-Translator: Luis González <lgonzalez@vauxoo.com>\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: portal_multicurrency_totals
#: model_terms:ir.ui.view,arch_db:portal_multicurrency_totals.totals_footer
msgid "Currency"
msgstr "Moneda"

#. module: portal_multicurrency_totals
#: model_terms:ir.ui.view,arch_db:portal_multicurrency_totals.totals_footer
msgid "Paid"
msgstr "Pagado"

#. module: portal_multicurrency_totals
#: model:product.pricelist,name:portal_multicurrency_totals.pricelist_usd
msgid "Pricelist in USD"
msgstr "Tarifa en USD"

#. module: portal_multicurrency_totals
#: model_terms:ir.ui.view,arch_db:portal_multicurrency_totals.totals_footer
msgid "Total"
msgstr ""

#. module: portal_multicurrency_totals
#: model_terms:ir.ui.view,arch_db:portal_multicurrency_totals.totals_footer
msgid "Totals by Currency"
msgstr "Totales por Moneda"

#. module: portal_multicurrency_totals
#: model_terms:ir.ui.view,arch_db:portal_multicurrency_totals.totals_footer
msgid "Unpaid"
msgstr "Sin Pagar"
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.
99 changes: 99 additions & 0 deletions portal_multicurrency_totals/views/portal_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<template id="totals_footer">
<h4 t-if="totals_by_currency" class="mt16">Totals by Currency</h4>
<t t-if="totals_by_currency" t-call="portal.portal_table">
<t t-set="pager" t-value="False" />
<t t-set="currencies" t-value="list(totals_by_currency)" />
<t
t-set="show_paid"
t-value="'paid' in totals_by_currency[currencies[0]]"
/>
<t
t-set="show_unpaid"
t-value="'unpaid' in totals_by_currency[currencies[0]]"
/>
<thead>
<tr>
<th>Currency</th>
<th class="text-right">Total</th>
<th t-if="show_paid" class="text-right">Paid</th>
<th t-if="show_unpaid" class="text-right">Unpaid</th>
</tr>
</thead>
<tbody>
<tr t-foreach="currencies" t-as="currency">
<t
t-set="totals_this_currency"
t-value="totals_by_currency[currency]"
/>
<td>
<span t-esc="currency.name" />
</td>
<td class="text-right">
<span
t-esc="totals_this_currency['amount']"
t-options="{
'widget': 'monetary',
'display_currency': currency,
}"
/>
</td>
<td t-if="show_paid" class="text-right">
<span
t-esc="totals_this_currency['paid']"
t-options="{
'widget': 'monetary',
'display_currency': currency,
}"
/>
</td>
<td t-if="show_unpaid" class="text-right">
<span
t-esc="totals_this_currency['unpaid']"
t-options="{
'widget': 'monetary',
'display_currency': currency,
}"
/>
</td>
</tr>
</tbody>
</t>
</template>

<template
id="portal_my_orders"
inherit_id="sale.portal_my_orders"
name="Show Multi-Currency Totals in Quotations"
customize_show="True"
>
<xpath expr="//t[@t-call='portal.portal_table']" position="after">
<t t-call="portal_multicurrency_totals.totals_footer" />
</xpath>
</template>

<template
id="portal_my_quotations"
inherit_id="sale.portal_my_quotations"
name="Show Multi-Currency Totals in Sale orders"
customize_show="True"
>
<xpath expr="//t[@t-call='portal.portal_table']" position="after">
<t t-call="portal_multicurrency_totals.totals_footer" />
</xpath>
</template>

<template
id="portal_my_invoices"
inherit_id="account.portal_my_invoices"
name="Show Multi-Currency Totals in Invoices"
customize_show="True"
>
<xpath expr="//t[@t-call='portal.portal_table']" position="after">
<t t-call="portal_multicurrency_totals.totals_footer" />
</xpath>
</template>

</odoo>

0 comments on commit 08280b0

Please sign in to comment.