[IMP] removal of usages of the deprecated node.getchildren call, better usage of...
[odoo/odoo.git] / addons / account / company.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from osv import fields, osv
24
25 class res_company(osv.osv):
26     _inherit = "res.company"
27     _columns = {
28         'overdue_msg' : fields.text('Overdue Payments Message', translate=True),
29     }
30
31     _defaults = {
32         'overdue_msg': lambda *a: 'Would your payment have been carried \
33 out after this mail was sent, please consider the present one as \
34 void. Do not hesitate to contact our accounting department'
35     }
36 res_company()
37
38 class company_setup(osv.osv_memory):
39     """
40     Insert Information for a company.
41     Wizard asks for:
42         * A Company with its partner
43         * Insert a suitable message for Overdue Payment Report.
44     """
45     _name='wizard.company.setup'
46
47     _columns = {
48         'company_id':fields.many2one('res.company','Company',required=True),
49         'partner_id':fields.many2one('res.partner','Partner'),
50         'overdue_msg': fields.text('Overdue Payment Message'),
51     }
52     def get_message(self,cr,uid,context={}):
53         company =self.pool.get('res.users').browse(cr,uid,[uid],context)[0].company_id
54         msg = company.overdue_msg
55         phone = company.partner_id.address and (company.partner_id.address[0].phone and ' at ' + str(company.partner_id.address[0].phone) + '.' or '.') or '.'
56         msg += str(phone)
57         return msg
58
59     _defaults = {
60         'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr,uid,[uid],c)[0].company_id.id,
61         'partner_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr,uid,[uid],c)[0].company_id.partner_id.id,
62         'overdue_msg': get_message,
63     }
64
65     def onchange_company_id(self, cr, uid, ids, company, context=None):
66         res = {}
67         if not company:
68             return {}
69         comp_obj = self.pool.get('res.company').browse(cr,uid,company)
70         res['partner_id'] = comp_obj.partner_id.id
71         phone = comp_obj.partner_id.address and (comp_obj.partner_id.address[0].phone and ' at ' + str(comp_obj.partner_id.address[0].phone) + '.' or '.') or '.'
72         res['overdue_msg'] = comp_obj.overdue_msg + str(phone)
73         
74         return {'value': res }
75
76     def action_create(self, cr, uid, ids, context=None):
77         content_wiz = self.pool.get('wizard.company.setup').read(cr,uid,ids,['company_id','overdue_msg'])
78         if content_wiz:
79             wiz_data = content_wiz[0]
80             self.pool.get('res.company').write(cr, uid, [wiz_data['company_id']], {'overdue_msg':wiz_data['overdue_msg']})
81
82         return {
83                 'view_type': 'form',
84                 "view_mode": 'form',
85                 'res_model': 'ir.actions.configuration.wizard',
86                 'type': 'ir.actions.act_window',
87                 'target':'new',
88         }
89
90     def action_cancel(self,cr,uid,ids,conect=None):
91         return {
92                 'view_type': 'form',
93                 "view_mode": 'form',
94                 'res_model': 'ir.actions.configuration.wizard',
95                 'type': 'ir.actions.act_window',
96                 'target':'new',
97         }
98
99 company_setup()