2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2010-07-03 09:30:47 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-07-03 09:30:47 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from osv import fields, osv
|
2012-10-19 17:29:17 +00:00
|
|
|
from datetime import date
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class followup(osv.osv):
|
2008-07-22 15:11:28 +00:00
|
|
|
_name = 'account_followup.followup'
|
2012-06-27 06:28:21 +00:00
|
|
|
_description = 'Account Follow-up'
|
2008-07-22 15:11:28 +00:00
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Name', size=64, required=True),
|
|
|
|
'description': fields.text('Description'),
|
2012-06-27 06:28:21 +00:00
|
|
|
'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-up'),
|
2012-10-19 08:07:37 +00:00
|
|
|
'company_id': fields.many2one('res.company', 'Company', required=True),
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2010-07-03 09:30:47 +00:00
|
|
|
_defaults = {
|
|
|
|
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'account_followup.followup', context=c),
|
2010-10-11 10:51:16 +00:00
|
|
|
}
|
2011-05-10 13:55:57 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
followup()
|
|
|
|
|
|
|
|
class followup_line(osv.osv):
|
2008-07-22 15:11:28 +00:00
|
|
|
_name = 'account_followup.followup.line'
|
2012-06-27 06:28:21 +00:00
|
|
|
_description = 'Follow-up Criteria'
|
2008-07-22 15:11:28 +00:00
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Name', size=64, required=True),
|
2011-05-09 10:06:20 +00:00
|
|
|
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of follow-up lines."),
|
2008-07-22 15:11:28 +00:00
|
|
|
'delay': fields.integer('Days of delay'),
|
|
|
|
'start': fields.selection([('days','Net Days'),('end_of_month','End of Month')], 'Type of Term', size=64, required=True),
|
|
|
|
'followup_id': fields.many2one('account_followup.followup', 'Follow Ups', required=True, ondelete="cascade"),
|
2009-01-28 14:43:31 +00:00
|
|
|
'description': fields.text('Printed Message', translate=True),
|
2012-10-19 08:07:37 +00:00
|
|
|
'send_email':fields.boolean('Send email', help="When processing, it will send an email"),
|
|
|
|
'send_letter':fields.boolean('Print email'),
|
|
|
|
'phonecall':fields.boolean('Phone call'),
|
2010-10-11 10:51:16 +00:00
|
|
|
}
|
2011-05-10 13:55:57 +00:00
|
|
|
_defaults = {
|
|
|
|
'start': 'days',
|
2012-10-19 08:07:37 +00:00
|
|
|
'send_email': True,
|
|
|
|
'send_letter': False,
|
2011-05-10 13:55:57 +00:00
|
|
|
}
|
2011-09-24 10:42:25 +00:00
|
|
|
def _check_description(self, cr, uid, ids, context=None):
|
|
|
|
for line in self.browse(cr, uid, ids, context=context):
|
|
|
|
if line.description:
|
|
|
|
try:
|
|
|
|
line.description % {'partner_name': '', 'date':'', 'user_signature': '', 'company_name': ''}
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
_constraints = [
|
|
|
|
(_check_description, 'Your description is invalid, use the right legend or %% if you want to use the percent character.', ['description']),
|
|
|
|
]
|
2010-07-03 09:30:47 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
followup_line()
|
|
|
|
|
|
|
|
class account_move_line(osv.osv):
|
2008-07-22 15:11:28 +00:00
|
|
|
_inherit = 'account.move.line'
|
|
|
|
_columns = {
|
|
|
|
'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level'),
|
2011-01-17 11:20:56 +00:00
|
|
|
'followup_date': fields.date('Latest Follow-up', select=True),
|
2012-10-19 08:07:37 +00:00
|
|
|
'payment_commitment':fields.text('Commitment'),
|
|
|
|
'payment_date':fields.date('Date'),
|
2012-10-23 12:23:24 +00:00
|
|
|
#'payment_note':fields.text('Payment note'),
|
2012-10-25 08:08:22 +00:00
|
|
|
'payment_next_action':fields.text('New action'),
|
2011-10-28 15:43:37 +00:00
|
|
|
}
|
2010-07-03 09:30:47 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
account_move_line()
|
|
|
|
|
2009-09-15 05:45:34 +00:00
|
|
|
class res_company(osv.osv):
|
|
|
|
_inherit = "res.company"
|
|
|
|
_columns = {
|
2010-10-12 05:17:13 +00:00
|
|
|
'follow_up_msg': fields.text('Follow-up Message', translate=True),
|
2012-10-19 08:07:37 +00:00
|
|
|
|
2010-10-11 10:51:16 +00:00
|
|
|
}
|
2009-09-15 05:45:34 +00:00
|
|
|
|
|
|
|
_defaults = {
|
2012-05-04 12:19:58 +00:00
|
|
|
'follow_up_msg': '''
|
2010-10-12 05:17:13 +00:00
|
|
|
Date: %(date)s
|
2009-09-15 05:45:34 +00:00
|
|
|
|
|
|
|
Dear %(partner_name)s,
|
|
|
|
|
|
|
|
Please find in attachment a reminder of all your unpaid invoices, for a total amount due of:
|
|
|
|
|
|
|
|
%(followup_amount).2f %(company_currency)s
|
|
|
|
|
|
|
|
Thanks,
|
|
|
|
--
|
|
|
|
%(user_signature)s
|
|
|
|
%(company_name)s
|
|
|
|
'''
|
2010-10-11 10:51:16 +00:00
|
|
|
}
|
2008-07-23 14:41:47 +00:00
|
|
|
|
2010-07-03 09:30:47 +00:00
|
|
|
res_company()
|
2008-07-23 14:41:47 +00:00
|
|
|
|
2012-10-19 17:29:17 +00:00
|
|
|
|
|
|
|
|
2012-10-19 08:07:37 +00:00
|
|
|
class res_partner(osv.osv):
|
2012-10-19 17:29:17 +00:00
|
|
|
|
|
|
|
|
2012-10-23 12:23:24 +00:00
|
|
|
def _get_latest_followup_date(self, cr, uid, ids, name, arg, context=None):
|
2012-10-19 17:29:17 +00:00
|
|
|
res = {}
|
|
|
|
for partner in self.browse(cr, uid, ids):
|
|
|
|
|
2012-10-23 12:23:24 +00:00
|
|
|
|
|
|
|
accountmovelines = partner.accountmoveline_ids
|
|
|
|
#max(x.followup_date for x in accountmovelines)
|
|
|
|
#latest_date = lambda a: date(2011, 1, 1)
|
|
|
|
#for accountmoveline in accountmovelines:
|
|
|
|
# if (accountmoveline.followup_date != False) and (latest_date < accountmoveline.followup_date):
|
|
|
|
# latest_date = accountmoveline.followup_date
|
|
|
|
#if accountmovelines:
|
2012-10-24 15:37:34 +00:00
|
|
|
amls2 = filter(lambda a: (a.state != 'draft') and (a.debit > 0), accountmovelines)
|
2012-10-23 12:23:24 +00:00
|
|
|
res[partner.id] = max(x.followup_date for x in amls2) if len(amls2) else False
|
|
|
|
#else:
|
|
|
|
# res[partner.id] = False
|
|
|
|
|
|
|
|
#res[partner.id] = max(x.followup_date for x in accountmovelines) if len(accountmovelines) else False
|
2012-10-19 17:29:17 +00:00
|
|
|
return res
|
|
|
|
|
2012-10-22 08:59:42 +00:00
|
|
|
|
2012-10-19 17:29:17 +00:00
|
|
|
|
|
|
|
|
2012-10-23 12:23:24 +00:00
|
|
|
def _get_latest_followup_level_id(self, cr, uid, ids, name, arg, context=None):
|
2012-10-19 17:29:17 +00:00
|
|
|
res = {}
|
2012-10-23 12:23:24 +00:00
|
|
|
for partner in self.browse(cr, uid, ids):
|
|
|
|
amls = partner.accountmoveline_ids
|
2012-10-19 17:29:17 +00:00
|
|
|
level_id = 0
|
2012-10-23 12:23:24 +00:00
|
|
|
level_days = -1000 #TO BE IMPROVED with boolean checking first time or by using MAX
|
|
|
|
latest_level = False
|
|
|
|
res[partner.id] = False
|
|
|
|
|
|
|
|
for accountmoveline in amls:
|
2012-10-24 15:37:34 +00:00
|
|
|
if (accountmoveline.followup_line_id != False) and (level_days < accountmoveline.followup_line_id.delay):
|
|
|
|
# and (accountmoveline.debit > 0): (accountmoveline.state != "draft") and
|
|
|
|
#and (accountmoveline.reconcile_id == None)
|
2012-10-23 12:23:24 +00:00
|
|
|
level_days = accountmoveline.followup_line_id.delay
|
|
|
|
latest_level = accountmoveline.followup_line_id.id
|
|
|
|
res[partner.id] = latest_level
|
|
|
|
#res[partner.id] = max(x.followup_line_id.delay for x in amls) if len(amls) else False
|
|
|
|
return res
|
2012-10-19 17:29:17 +00:00
|
|
|
|
2012-10-24 15:37:34 +00:00
|
|
|
def get_latest_followup_level(self):
|
|
|
|
amls = self.accountmoveline_ids
|
|
|
|
|
|
|
|
|
|
|
|
def _get_next_followup_level_id(self, cr, uid, ids, name, arg, context=None):
|
|
|
|
res = {}
|
|
|
|
for partner in self.browse(cr, uid, ids):
|
|
|
|
latest_id = self._get_latest_followup_level_id(cr, uid, [partner.id], name, arg, context)[partner.id]
|
|
|
|
latest = self.pool.get('account_followup.followup.line').browse(cr, uid, [latest_id], context)[0]
|
|
|
|
delay = False
|
|
|
|
newlevel = False
|
|
|
|
if latest: #if latest exists
|
|
|
|
newlevel = latest.id
|
|
|
|
old_delay = latest.delay
|
|
|
|
else:
|
|
|
|
old_delay = False
|
|
|
|
|
|
|
|
for fl in self.pool.get('account_followup.followup.line').search(cr, uid, []): #('followup_id.company_id','=',latest.followup_id.company_id)
|
|
|
|
fl_obj = self.pool.get('account_followup.followup.line').browse(cr, uid, [fl])[0]
|
|
|
|
if not old_delay:
|
|
|
|
if not delay or fl_obj.delay < delay:
|
|
|
|
delay = fl_obj.delay
|
|
|
|
newlevel = fl_obj.id
|
|
|
|
else:
|
|
|
|
if (not delay and (fl_obj.delay > old_delay)) or ((fl_obj.delay < delay) and (fl_obj.delay > old_delay)):
|
|
|
|
delay = fl_obj.delay
|
|
|
|
newlevel = fl_obj.id
|
|
|
|
res[partner.id] = newlevel
|
|
|
|
#Now search one level higher
|
|
|
|
return res
|
|
|
|
|
2012-10-19 08:07:37 +00:00
|
|
|
_inherit = "res.partner"
|
|
|
|
_columns = {
|
2012-10-24 15:37:34 +00:00
|
|
|
'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Responsible', help="Responsible"),
|
2012-10-23 12:23:24 +00:00
|
|
|
#'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'),
|
2012-10-24 15:37:34 +00:00
|
|
|
'payment_note':fields.text('Payment note', help="Payment note"),
|
2012-10-25 08:08:22 +00:00
|
|
|
'payment_next_action':fields.text('Next action', help="Write here the comments of your customer"), #Just a note
|
|
|
|
'payment_next_action_date':fields.date('Next action date', help="Next date to take action"), # next action date
|
2012-10-24 15:37:34 +00:00
|
|
|
'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id', domain=['&', ('debit', '>', 0.0), '&', ('reconcile_id', '=', False), '&',
|
|
|
|
('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]),
|
|
|
|
'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date", store=True),
|
2012-10-23 12:23:24 +00:00
|
|
|
'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True,
|
2012-10-24 15:37:34 +00:00
|
|
|
type='many2one', relation='account_followup.followup.line', string="latest followup level", store=True),
|
|
|
|
'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line', string="next level"),
|
2012-10-19 08:07:37 +00:00
|
|
|
}
|
2012-10-23 12:23:24 +00:00
|
|
|
|
|
|
|
|
2012-10-19 08:07:37 +00:00
|
|
|
res_partner()
|
|
|
|
|
2011-09-24 10:42:25 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|