Launchpad automatic translations update.
[odoo/odoo.git] / addons / account_followup / account_followup.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import fields, osv
23
24 class followup(osv.osv):
25     _name = 'account_followup.followup'
26     _description = 'Account Follow Up'
27     _columns = {
28         'name': fields.char('Name', size=64, required=True),
29         'description': fields.text('Description'),
30         'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-Up'),
31         'company_id': fields.many2one('res.company', 'Company'),
32     }
33     _defaults = {
34         'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'account_followup.followup', context=c),
35     }
36     
37     def check_company_uniq(self, cr, uid, ids, context=None):
38         sr_id = self.search(cr,uid,[],context=context)
39         lines = self.browse(cr, uid, sr_id, context=context)
40         company = []
41         for l in lines:
42             if l.company_id.id in company:
43                 return False
44             if l.company_id.id not in company:
45                 company.append(l.company_id.id)
46         return True
47     _constraints = [
48         (check_company_uniq, 'Only One Folllowup by Company.',['company_id'] )
49         ]
50
51 followup()
52
53 class followup_line(osv.osv):
54     _name = 'account_followup.followup.line'
55     _description = 'Follow-Up Criteria'
56     _columns = {
57         'name': fields.char('Name', size=64, required=True),
58         'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of follow-up lines."),
59         'delay': fields.integer('Days of delay'),
60         'start': fields.selection([('days','Net Days'),('end_of_month','End of Month')], 'Type of Term', size=64, required=True),
61         'followup_id': fields.many2one('account_followup.followup', 'Follow Ups', required=True, ondelete="cascade"),
62         'description': fields.text('Printed Message', translate=True),
63     }
64     _defaults = {
65         'start': 'days',
66
67     }
68     def _check_description(self, cr, uid, ids, context=None):
69         for line in self.browse(cr, uid, ids, context=context):
70             if line.description:
71                 try:
72                     line.description % {'partner_name': '', 'date':'', 'user_signature': '', 'company_name': ''}
73                 except:
74                     return False
75         return True
76
77     _constraints = [
78         (_check_description, 'Your description is invalid, use the right legend or %% if you want to use the percent character.', ['description']),
79     ]
80
81 followup_line()
82
83 class account_move_line(osv.osv):
84     _inherit = 'account.move.line'
85     _columns = {
86         'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level'),
87         'followup_date': fields.date('Latest Follow-up', select=True),
88                 }
89
90 account_move_line()
91
92 class res_company(osv.osv):
93     _inherit = "res.company"
94     _columns = {
95         'follow_up_msg': fields.text('Follow-up Message', translate=True),
96     }
97
98     _defaults = {
99         'overdue_msg': '''
100 Date: %(date)s
101
102 Dear %(partner_name)s,
103
104 Please find in attachment a reminder of all your unpaid invoices, for a total amount due of:
105
106 %(followup_amount).2f %(company_currency)s
107
108 Thanks,
109 --
110 %(user_signature)s
111 %(company_name)s
112         '''
113     }
114
115 res_company()
116
117 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: