Skip to content

Commit 0e6335c

Browse files
committed
[IMP] new module: account_currency_reports_ux
1 parent 9b81090 commit 0e6335c

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# -*- coding: utf-8 -*-
2+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
3+
4+
from . import report
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
##############################################################################
2+
#
3+
# Copyright (C) 2024 ADHOC SA (http://www.adhoc.com.ar)
4+
# All Rights Reserved.
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as
8+
# published by the Free Software Foundation, either version 3 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Affero General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Affero General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
##############################################################################
20+
{
21+
'name': 'Account Currency Reports UX',
22+
'version': "16.0.1.0.0",
23+
'category': 'Accounting',
24+
'sequence': 14,
25+
'summary': 'Restrict the use of certain journals to certain users',
26+
'author': 'ADHOC SA',
27+
'website': 'www.adhoc.com.ar',
28+
'license': 'AGPL-3',
29+
'images': [
30+
],
31+
'depends': [
32+
'account',
33+
],
34+
'data': [
35+
],
36+
'demo': [
37+
],
38+
'test': [
39+
],
40+
'installable': True,
41+
'auto_install': False,
42+
'application': False,
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# -*- coding: utf-8 -*-
2+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
3+
4+
from . import account_invoice_report
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from odoo import models, api
2+
3+
class AccountInvoiceReport(models.Model):
4+
_inherit = "account.invoice.report"
5+
6+
@api.model
7+
def _select(self):
8+
return '''
9+
WITH currency_rate AS MATERIALIZED (
10+
SELECT
11+
r.currency_id,
12+
COALESCE(r.company_id, c.id) as company_id,
13+
1/r.rate as rate,
14+
r.name AS date_start,
15+
(SELECT name FROM res_currency_rate r2
16+
WHERE r2.name > r.name AND
17+
r2.currency_id = r.currency_id AND
18+
(r2.company_id is null or r2.company_id = c.id)
19+
ORDER BY r2.name ASC
20+
LIMIT 1) AS date_end
21+
FROM res_currency_rate r
22+
JOIN res_company c ON (r.company_id is null or r.company_id = c.id)
23+
WHERE c.id = %s
24+
)
25+
SELECT
26+
line.id,
27+
line.move_id,
28+
line.product_id,
29+
line.account_id,
30+
line.journal_id,
31+
line.company_id,
32+
line.company_currency_id,
33+
line.partner_id AS commercial_partner_id,
34+
account.account_type AS user_type,
35+
move.state,
36+
move.move_type,
37+
move.partner_id,
38+
move.invoice_user_id,
39+
move.fiscal_position_id,
40+
move.payment_state,
41+
move.invoice_date,
42+
move.invoice_date_due,
43+
uom_template.id AS product_uom_id,
44+
template.categ_id AS product_categ_id,
45+
line.quantity / NULLIF(COALESCE(uom_line.factor, 1) / COALESCE(uom_template.factor, 1), 0.0) * (CASE WHEN move.move_type IN ('in_invoice','out_refund','in_receipt') THEN -1 ELSE 1 END)
46+
AS quantity,
47+
CASE WHEN line.currency_id <> rc.currency_id THEN -line.balance * currency_table.rate ELSE -line.balance END AS price_subtotal,
48+
line.price_total * (CASE WHEN move.move_type IN ('in_invoice','out_refund','in_receipt') THEN -1 ELSE 1 END)
49+
AS price_total,
50+
CASE WHEN line.currency_id <> rc.currency_id THEN
51+
-COALESCE(
52+
-- Average line price
53+
(line.balance / NULLIF(line.quantity, 0.0)) * (CASE WHEN move.move_type IN ('in_invoice','out_refund','in_receipt') THEN -1 ELSE 1 END)
54+
-- convert to template uom
55+
* (NULLIF(COALESCE(uom_line.factor, 1), 0.0) / NULLIF(COALESCE(uom_template.factor, 1), 0.0)),
56+
0.0) * currency_table.rate
57+
ELSE -COALESCE(
58+
-- Average line price
59+
(line.balance / NULLIF(line.quantity, 0.0)) * (CASE WHEN move.move_type IN ('in_invoice','out_refund','in_receipt') THEN -1 ELSE 1 END)
60+
-- convert to template uom
61+
* (NULLIF(COALESCE(uom_line.factor, 1), 0.0) / NULLIF(COALESCE(uom_template.factor, 1), 0.0)),
62+
0.0) END
63+
AS price_average,
64+
COALESCE(partner.country_id, commercial_partner.country_id) AS country_id,
65+
line.currency_id AS currency_id
66+
''' % self.env.company.id
67+
68+
@api.model
69+
def _from(self):
70+
return '''
71+
FROM account_move_line line
72+
LEFT JOIN res_partner partner ON partner.id = line.partner_id
73+
LEFT JOIN product_product product ON product.id = line.product_id
74+
LEFT JOIN account_account account ON account.id = line.account_id
75+
LEFT JOIN product_template template ON template.id = product.product_tmpl_id
76+
LEFT JOIN uom_uom uom_line ON uom_line.id = line.product_uom_id
77+
LEFT JOIN uom_uom uom_template ON uom_template.id = template.uom_id
78+
INNER JOIN account_move move ON move.id = line.move_id
79+
LEFT JOIN res_partner commercial_partner ON commercial_partner.id = move.commercial_partner_id
80+
lEFT JOIN currency_rate currency_table on
81+
(currency_table.company_id = line.company_id and
82+
currency_table.currency_id = line.currency_id and
83+
currency_table.date_start <= COALESCE(line.date, NOW()) and
84+
(currency_table.date_end IS NULL OR currency_table.date_end > COALESCE(line.date, NOW())))
85+
LEFT JOIN res_company rc on rc.id=line.company_id
86+
'''

0 commit comments

Comments
 (0)