-
Notifications
You must be signed in to change notification settings - Fork 8
Execute code at update or install
Michael Karrer edited this page Sep 30, 2015
·
2 revisions
Information found here:
- https://www.odoo.com/fr_FR/forum/help-1/question/how-can-i-execute-a-sql-statement-on-module-update-and-installation-6131
- http://www.mindissoftware.com/2014/11/22/Odoo-Load-Addons-And-Modules/
The init function will only be called at addon update or install! See most reports e.g.: addons/account/report/account_report
:
class report_account_receivable(osv.osv):
_name = "report.account.receivable"
_description = "Receivable accounts"
_auto = False
_columns = {
'name': fields.char('Week of Year', size=7, readonly=True),
'type': fields.selection(_code_get, 'Account Type', required=True),
'balance':fields.float('Balance', readonly=True),
'debit':fields.float('Debit', readonly=True),
'credit':fields.float('Credit', readonly=True),
}
_order = 'name desc'
def init(self, cr):
tools.drop_view_if_exists(cr, 'report_account_receivable')
cr.execute("""
create or replace view report_account_receivable as (
select
min(l.id) as id,
to_char(date,'YYYY:IW') as name,
sum(l.debit-l.credit) as balance,
sum(l.debit) as debit,
sum(l.credit) as credit,
a.type
from
account_move_line l
left join
account_account a on (l.account_id=a.id)
where
l.state <> 'draft'
group by
to_char(date,'YYYY:IW'), a.type
)""")