1
- from odoo import models , api
1
+ from odoo import api
2
+ from odoo .addons .account .report .account_invoice_report import AccountInvoiceReport
2
3
3
- class AccountInvoiceReport (models .Model ):
4
- _inherit = "account.invoice.report"
4
+ def monkey_patches ():
5
5
6
+ # monkey patch
6
7
@api .model
7
- def _select (self ):
8
+ def _select_patch (self ):
8
9
return '''
9
10
WITH currency_rate AS MATERIALIZED (
10
11
SELECT
@@ -66,7 +67,7 @@ def _select(self):
66
67
''' % self .env .company .id
67
68
68
69
@api .model
69
- def _from (self ):
70
+ def _from_patch (self ):
70
71
return '''
71
72
FROM account_move_line line
72
73
LEFT JOIN res_partner partner ON partner.id = line.partner_id
@@ -78,9 +79,19 @@ def _from(self):
78
79
INNER JOIN account_move move ON move.id = line.move_id
79
80
LEFT JOIN res_partner commercial_partner ON commercial_partner.id = move.commercial_partner_id
80
81
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
82
+ (currency_table.currency_id = line.currency_id and
83
83
currency_table.date_start <= COALESCE(line.date, NOW()) and
84
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
85
+ LEFT JOIN res_company rc on rc.id=currency_table .company_id
86
86
'''
87
+
88
+ def _patch_method (cls , name , method ):
89
+ origin = getattr (cls , name )
90
+ method .origin = origin
91
+ # propagate decorators from origin to method, and apply api decorator
92
+ wrapped = api .propagate (origin , method )
93
+ wrapped .origin = origin
94
+ setattr (cls , name , wrapped )
95
+
96
+ _patch_method (AccountInvoiceReport , '_select' , _select_patch )
97
+ _patch_method (AccountInvoiceReport , '_from' , _from_patch )
0 commit comments