[IMP] action adds instead of replace, when no email, use of credit field

bzr revid: jco@openerp.com-20121120124026-xkdw3vjj71monlf8
This commit is contained in:
Josse Colpaert 2012-11-20 13:40:26 +01:00
commit feaa99bdb4
7 changed files with 215 additions and 285 deletions

View File

@ -20,11 +20,7 @@
##############################################################################
from osv import fields, osv
from datetime import date
import time
import datetime
from lxml import etree
from copy import deepcopy
from tools.translate import _
@ -61,16 +57,16 @@ class followup_line(osv.osv):
_columns = {
'name': fields.char('Name', size=64, required=True),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of follow-up lines."),
'delay': fields.integer('Days of delay', help="The number of days after the due date of the invoice. Could be negative if you want to send a polite alert beforehand. "),
'delay': fields.integer('Days due', help="The number of days after the due date of the invoice. Could be negative if you want to send a polite alert beforehand. "),
#'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"),
'description': fields.text('Printed Message', translate=True),
'send_email':fields.boolean('Send email', help="When processing, it will send an email"),
'send_letter':fields.boolean('Send letter', help="When processing, it will print a letter"),
'manual_action':fields.boolean('Manual action', help="When processing, it will set the manual action to be taken for that customer. "),
'manual_action_note':fields.text('Action text', placeholder="e.g. Give a phone call, check with others , ..."),
'send_email':fields.boolean('Send Email', help="When processing, it will send an email"),
'send_letter':fields.boolean('Send Letter', help="When processing, it will print a letter"),
'manual_action':fields.boolean('Manual Action', help="When processing, it will set the manual action to be taken for that customer. "),
'manual_action_note':fields.text('Action Text', placeholder="e.g. Give a phone call, check with others , ..."),
'manual_action_responsible_id':fields.many2one('res.users', 'Responsible', ondelete='set null'),
'email_template_id':fields.many2one('email.template', 'Email template', ondelete='set null'),
'email_template_id':fields.many2one('email.template', 'Email Template', ondelete='set null'),
'email_body':fields.related('email_template_id', 'body_html', type='text', string="Email Message", relation="email.template", translate="True"),
}
_order = 'delay'
@ -142,7 +138,7 @@ class account_move_line(osv.osv):
'payment_commitment':fields.text('Commitment'),
'payment_date':fields.date('Date'),
#'payment_note':fields.text('Payment note'),
'payment_next_action':fields.text('New action'),
'payment_next_action':fields.text('Next Action'),
'result':fields.function(_get_result, type='float', method=True, string="Balance")
}
@ -176,21 +172,18 @@ class res_partner(osv.osv):
return res
def _get_latest_followup_date(self, cr, uid, ids, name, arg, context=None):
res = {}
for partner in self.browse(cr, uid, ids, context):
amls = partner.accountmoveline_ids
res[partner.id] = max([x.followup_date for x in amls]) if len(amls) else False
return res
# def _get_latest_followup_date(self, cr, uid, ids, name, arg, context=None):
# res = {}
# for partner in self.browse(cr, uid, ids, context):
# amls = partner.accountmoveline_ids
# res[partner.id] = max([x.followup_date for x in amls]) if len(amls) else False
# return res
#
#
def _get_latest_followup_level_id(self, cr, uid, ids, name, arg, context=None):
res = {}
for partner in self.browse(cr, uid, ids, context):
amls = partner.accountmoveline_ids
level_id = 0
level_days = False
latest_level = False
res[partner.id] = False
@ -205,7 +198,6 @@ class res_partner(osv.osv):
def _get_latest(self, cr, uid, ids, names, arg, context=None):
res={}
print "change field"
for partner in self.browse(cr, uid, ids, context):
amls = partner.accountmoveline_ids
latest_date = False
@ -233,56 +225,8 @@ class res_partner(osv.osv):
return res
# def _get_latest_followup_level_id_without_lit(self, cr, uid, ids, name, arg, context=None):
# res = {}
# for partner in self.browse(cr, uid, ids):
# amls = partner.accountmoveline_ids
# level_id = 0
# level_days = False
# latest_level = False
# res[partner.id] = False
# for accountmoveline in amls:
# if (not accountmoveline.blocked) and (accountmoveline.followup_line_id != False) and (not level_days or level_days < accountmoveline.followup_line_id.delay):
# level_days = accountmoveline.followup_line_id.delay
# latest_level = accountmoveline.followup_line_id.id
# res[partner.id] = latest_level
# return res
#def get_latest_followup_level(self):
# amls = self.accountmoveline_ids
# def _get_next_followup_level_id_optimized(self, cr, uid, ids, name, arg, context=None):
# #Apparently there is still an error in this function
# res = {}
# for partner in self.browse(cr, uid, ids):
# latest_id = partner.latest_followup_level_id
# if latest_id:
# latest = latest_id
# else:
# latest = False
# delay = False
# newlevel = False
# if latest: #if latest exists
# newlevel = latest.id
# old_delay = latest.delay
# else:
# old_delay = False
# fl_ar = self.pool.get('account_followup.followup.line').search(cr, uid, [('followup_id.company_id.id','=', partner.company_id.id)])
# for fl_obj in self.pool.get('account_followup.followup.line').browse(cr, uid, fl_ar):
# 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
#Problems company id? / Method necessary?
def _get_next_followup_level_id(self, cr, uid, ids, name, arg, context=None):
res = {}
for partner in self.browse(cr, uid, ids):
@ -311,28 +255,53 @@ class res_partner(osv.osv):
return res
def _get_amount_overdue(self, cr, uid, ids, name, arg, context=None):
#Get the total amount in the account move lines that is overdue (passed or equal to due date)
res={}
# def _get_amount_overdue(self, cr, uid, ids, name, arg, context=None):
# #Get the total amount in the account move lines that the customer owns us
# res={}
# print "get amount overdue"
# for partner in self.browse(cr, uid, ids, context):
# res[partner.id] = 0.0
# for aml in partner.accountmoveline_ids:
# res[partner.id] = res[partner.id] + aml.debit - aml.credit #or by using function field
# return res
#
def _get_amount_due(self, cr, uid, ids, name, arg, context=None):
res = {}
for partner in self.browse(cr, uid, ids, context):
res[partner.id] = 0.0
for aml in partner.accountmoveline_ids:
#if ((not aml.date_maturity) and (aml.date <= fields.date.context_today(cr, uid, context))) or (aml.date_maturity <= fields.date.context_today(cr, uid, context)):
res[partner.id] = res[partner.id] + aml.debit - aml.credit #or by using function field
res[partner.id] = partner.credit
return res
def do_partner_manual_action(self, cr, uid, partner_ids, context=None):
#partner_ids are res.partner ids
for partner in self.browse(cr, uid, partner_ids, context):
if (not partner.payment_next_action_date) and (not partner.payment_next_action) and (not partner.payment_responsible_id) :
self.write(cr, uid, [partner.id], {'payment_next_action_date': fields.date.context_today(cr, uid, context),
'payment_next_action': partner.latest_followup_level_id_without_lit.manual_action_note,
'payment_responsible_id': partner.latest_followup_level_id_without_lit.manual_action_responsible_id.id})
if True: #(not partner.payment_next_action_date) and (not partner.payment_next_action) and (not partner.payment_responsible_id)
action_text= ""
#Check action
if partner.payment_next_action:
action_text = partner.payment_next_action + " + " + partner.latest_followup_level_id_without_lit.manual_action_note
else:
action_text = partner.latest_followup_level_id_without_lit.manual_action_note
#Check minimum date
action_date = False
if partner.payment_next_action_date:
action_date = min(partner.payment_next_action_date, fields.date.context_today(cr, uid, context))
else:
action_date = fields.date.context_today(cr, uid, context)
responsible_id = False
#Check responsible
if partner.payment_responsible_id:
responsible_id = partner.payment_responsible_id.id
else:
if partner.latest_followup_level_id_without_lit.manual_action_responsible_id:
responsible_id = partner.latest_followup_level_id_without_lit.manual_action_responsible_id.id
self.write(cr, uid, [partner.id], {'payment_next_action_date': action_date,
'payment_next_action': action_text,
'payment_responsible_id': responsible_id})
def do_partner_print(self, cr, uid, partner_ids, data, context=None):
#partner_ids are ids from special view, not from res.partner
#partner_ids are ids from special view, not from res.partner
#data.update({'date': context['date']})
if not partner_ids:
return {}
@ -352,13 +321,28 @@ class res_partner(osv.osv):
#partner_ids are res.partner ids
# If not defined by latest level, it will the default template if it can find it
mtp = self.pool.get('email.template')
unknown_mails = 0
for partner in self.browse(cr, uid, partner_ids, context):
if partner.latest_followup_level_id_without_lit and partner.latest_followup_level_id_without_lit.send_email and partner.latest_followup_level_id_without_lit.email_template_id.id != False :
mtp.send_mail(cr, uid, partner.latest_followup_level_id_without_lit.email_template_id.id, partner.id, context=context)
else :
mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup_default')
mtp.send_mail(cr, uid, mail_template_id[1], partner.id, context=context)
if partner.email != '' and partner.email != ' ':
if partner.latest_followup_level_id_without_lit and partner.latest_followup_level_id_without_lit.send_email and partner.latest_followup_level_id_without_lit.email_template_id.id != False :
mtp.send_mail(cr, uid, partner.latest_followup_level_id_without_lit.email_template_id.id, partner.id, context=context)
else :
mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup_default')
mtp.send_mail(cr, uid, mail_template_id[1], partner.id, context=context)
else:
unknown_mails = unknown_mails + 1
action_text = _("Email not sent because of email address of partner not filled in")
if partner.payment_next_action_date:
payment_action_date = min(fields.date.context_today(cr, uid, context), partner.payment_next_action_date)
else:
payment_action_date = fields.date.context_today(cr, uid, context)
if partner.payment_next_action:
payment_next_action = partner.payment_next_action + " + " + action_text
else:
payment_next_action = action_text
self.write(cr, uid, [partner.id], {'payment_next_action_date': payment_action_date,
'payment_next_action': payment_next_action}, context)
return unknown_mails
def action_done(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'payment_next_action_date': False, 'payment_next_action':'', 'payment_responsible_id': False}, context)
@ -385,40 +369,36 @@ class res_partner(osv.osv):
def _get_aml_storeids(self, cr, uid, ids, context=None):
partnerlist = []
for aml in self.pool.get("account.move.line").browse(cr, uid, ids, context):
if aml.partner_id not in partnerlist:
if aml.partner_id.id not in partnerlist:
partnerlist.append(aml.partner_id.id)
return partnerlist
#
# def _get_am_storeids(self, cr, uid, ids, context=None):
# partnerlist = []
# for am in self.pool.get("account.move").browse(cr, uid, ids, context):
# if am.partner_id.id not in partnerlist:
# partnerlist.append(am.partner_id.id)
# print am.partner_id.id
# return partnerlist
#
# def _get_rec_storeids(self, cr, uid, ids, context=None):
# partnerlist = []
# for rec in self.pool.get("account.move.reconcile").browse(cr, uid, ids, context):
# for am in self.pool.get("account.move.line").browse(cr, uid, [x.id for x in rec.line_partial_ids], context):
# if am.partner_id.id not in partnerlist:
# partnerlist.append(am.partner_id.id)
# return partnerlist
#
#
# def _get_aml_storeids2(self, cr, uid, ids, context=None):
# partnerlist = []
# for aml in self.pool.get("account.move.line").browse(cr, uid, ids, context):
# if aml.partner_id not in partnerlist:
# partnerlist.append(aml.partner_id.id)
# return partnerlist
#
def _get_aml_storeids2(self, cr, uid, ids, context=None):
partnerlist = []
for aml in self.pool.get("account.move.line").browse(cr, uid, ids, context):
if aml.partner_id not in partnerlist:
partnerlist.append(aml.partner_id.id)
return partnerlist
def _search_amount(self, cr, uid, obj, name, args, context):
ids = set()
for cond in args:
amount = cond[2]
if isinstance(cond[2],(list,tuple)):
if cond[1] in ['in','not in']:
amount = tuple(cond[2])
else:
continue
else:
if cond[1] in ['=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of']:
continue
cr.execute("select move_id from account_move_line group by move_id having sum(debit) %s %%s" % (cond[1]),(amount,))
res_ids = set(id[0] for id in cr.fetchall())
ids = ids and (ids & res_ids) or res_ids
if ids:
return [('id', 'in', tuple(ids))]
return [('id', '=', '0')]
_inherit = "res.partner"
_columns = {
@ -448,11 +428,14 @@ class res_partner(osv.osv):
'next_followup_level_id':fields.function(_get_next_followup_level_id, method=True, type='many2one', relation='account_followup.followup.line',
string="Next Level", help="The next follow-up level to come when the customer still refuses to pay",
store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date'], 10)}),
'payment_amount_overdue':fields.function(_get_amount_overdue, method=True, type='float', string="Amount Overdue",
help="Amount Overdue: The amount the customer owns us",
store=True, #{'account.move.line': (_get_aml_storeids2, ['followup_line_id', 'followup_date', 'debit', 'credit', 'invoice'], 10)},
),
'payment_amount_due':fields.function(_get_amount_due, method=True, type='float', store=False),
#'credit':fields.function(_get_amount_overdue, method=True, type='float', string="Amount Overdue",
# help="Amount Overdue: The amount the customer owns us",
# store={'account.move.line': (_get_aml_storeids, ['followup_line_id', 'followup_date', 'debit', 'credit', 'invoice', 'reconcile_partial_id'], 10),
# 'account.move': (_get_am_storeids, ['ref', 'name'], 10),
# #'account.move.reconcile': (_get_rec_storeids, ['name', 'type'], 10),
# },
# ),
}
res_partner()

View File

@ -25,7 +25,7 @@
<field name="parent_id" invisible="1"/>
<!--<field name="payment_note"/>
<field name="phone"/>-->
<field name="payment_amount_overdue"/>
<field name="credit"/>
<field name="payment_responsible_id"/>
<!--<field name="email"/>-->
<field name="latest_followup_level_id"/>
@ -48,7 +48,7 @@
<!--<filter string="Actions to be taken with overdue amount" domain="['&amp;', ('payment_amount_outstanding', '>', 0.0), ('payment_next_action_date', '&lt;=', time.strftime('%%Y-%%m-%%d'))]"/>
<separator/>-->
<group string="Follow-up">
<filter string="Partners with Credits" domain="[('payment_amount_overdue', '>', 0.0)]" name="credits"/>
<filter string="Partners with Credits" domain="[('credit', '>', 0.0)]" name="credits"/>
<separator/>
<filter string="Follow-ups to do" domain="[('payment_next_action_date', '&lt;=', time.strftime('%%Y-%%m-%%d'))]" name="todo"/>
<separator/>
@ -78,7 +78,7 @@
<!--<filter string="Actions to be taken with overdue amount" domain="['&amp;', ('payment_amount_outstanding', '>', 0.0), ('payment_next_action_date', '&lt;=', time.strftime('%%Y-%%m-%%d'))]"/>
<separator/>-->
<filter string="Overdue amount" domain="[('payment_amount_overdue', '>', 0.0)]"/>
<filter string="Overdue amount" domain="[('credit', '>', 0.0)]"/>
<separator/>
<filter string="Follow-ups to do" domain="[('payment_next_action_date', '&lt;=', time.strftime('%%Y-%%m-%%d'))]"/>
<separator/>
@ -100,7 +100,7 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{} </field>
<!--<field name="domain">[('payment_amount_overdue', '>', 0)]</field>--> <!--('customer', '=', True), ('latest_followup_date','!=', False)-->
<!--<field name="domain">[('credit', '>', 0)]</field>--> <!--('customer', '=', True), ('latest_followup_date','!=', False)-->
<field name="context">{'Followupfirst':True, 'search_default_todo': True, 'search_default_credits': True} </field>
<field name="search_view_id" ref="customer_followup_search_view"/>
</record>
@ -118,21 +118,21 @@
<!--<field eval="[(4, ref('account.group_account_user'))]" name="groups_id"/>--><!-- or user? -->
<field name="arch" type="xml" >
<div name="buttons" position="inside">
<button name="do_button_print" type="object" string="Print Overdue Payments" groups="account.group_account_user" help="Print overdue payments report independent of follow-up line" attrs="{'invisible':[('payment_amount_overdue', '&lt;=', 0.0)]}" />
<button name="do_button_mail" type="object" string="Send Overdue Email" groups="account.group_account_user" help="If not specified by the latest follow-up level, it will send from the default follow-up of overdue invoices template" attrs="{'invisible':[('payment_amount_overdue', '&lt;=', 0.0)]}"/>
<button name="do_button_print" type="object" string="Print Overdue Payments" groups="account.group_account_user" help="Print overdue payments report independent of follow-up line" attrs="{'invisible':[('credit', '&lt;=', 0.0)]}" />
<button name="do_button_mail" type="object" string="Send Overdue Email" groups="account.group_account_user" help="If not specified by the latest follow-up level, it will send from the default follow-up of overdue invoices template" attrs="{'invisible':[('credit', '&lt;=', 0.0)]}"/>
</div>
<page string="Accounting" position="before" version="7.0">
<page string="Payments Follow-up" position="inside" groups="account.group_account_user">
<page string="Payments Follow-up" position="inside" groups="account.group_account_invoice">
<div class = "oe_inline">
<p attrs="{'invisible':[('latest_followup_date','=', False)]}" class="oe_inline">The <field name="latest_followup_date" />, the latest level that was executed, was <field name="latest_followup_level_id" class="oe_inline"/>.
</p>
<p class="oe_inline" attrs="{'invisible':[('payment_amount_overdue', '&lt;=', 0.0)]}">The partner owns us <field name="payment_amount_overdue" class="oe_inline"/>
</p>
<!--<p class="oe_inline" attrs="{'invisible':[('credit', '&lt;=', 0.0)]}">The partner owns us <field name="credit" class="oe_inline"/>
</p>-->
<!--<p attrs="{'invisible':[('payment_next_action', '=', False)]}">This is the action required now:</p>-->
</div>
<p class="oe_inline">
<label for="payment_next_action" string="Next Follow-up Action"/>
<field name="payment_next_action_date" nolabel="1"/> <label string="-" attrs="{'invisible': ['|', ('payment_next_action_date', '=', False), ('payment_next_action', '=', False)]}"/>
<field name="payment_next_action_date" nolabel="1" class="oe_inline"/> <label string="-" attrs="{'invisible': ['|', ('payment_next_action_date', '=', False), ('payment_next_action', '=', False)]}"/>
<field name="payment_next_action" class="oe_inline" nolabel="1" string="Next Follow-up action" placeholder="e.g. Give a phonecall, Check if he paid, ..."/>
<span attrs="{'invisible':[('payment_responsible_id', '=', False)]}"> to be done by: </span> <field name="payment_responsible_id" placeholder="The user responsible for taking this action e.g. sales" class="oe_inline"/>
@ -147,12 +147,12 @@
<field name="payment_note" string="The customer promised:"/>
</group>
<p class="oe_grey"> <!--maybe only when accountmovelines empty-->
Here is the history of the transactions of this customer. By clicking on the light bulb, you can put an invoice as litigation. This means you are still in discussion about it and it
won't be taken into account for going to the next follow-up level.
Here is the history of the transactions of this customer. By clicking on the check box, you can put an invoice as litigation. This means you are still in discussion about it and it
will not be taken into account by the wizard.
</p>
<group>
<field name="accountmoveline_ids" nolabel="1" > <!--ontext="{'default_partner_id': active_id}" mode="kanban"-->
<tree string="Account Move line" editable="bottom" create="false" colors="red:date_maturity and date_maturity&lt;current_date or date&lt;current_date">
<tree string="Account Move line" editable="bottom" create="false" delete="false" colors="red:date_maturity and date_maturity&lt;current_date or date&lt;current_date">
<field name="date" readonly="True"/>
<field name="move_id" readonly="True"/>
<field name="blocked" string="Litigation"/>
@ -161,6 +161,7 @@
<field name="result" readonly="True"/>
<field name="followup_line_id" invisible='1'/>
</tree>
<!-- <kanban default_group_by="followup_line_id" create="false">
<field name="followup_line_id"/>
<field name="result"/>
@ -189,8 +190,8 @@
</templates>
</kanban>-->
</field>
</group>
<p align="right"><B>Total amount: <field name="payment_amount_due" class="oe_inline"/> </B></p>
</page>
</page>
</field>

View File

@ -77,7 +77,7 @@ ${mel[aml.id]}
</table>
<center>Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name} </center>
<center>Total overdue amount: ${object.credit} ${object.company_id.currency_id.name} </center>
<br/>
</div>
]]></field>
@ -161,7 +161,7 @@ ${mel[aml.id]}
</table>
<center>Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name} </center>
<center>Total overdue amount: ${object.credit} ${object.company_id.currency_id.name} </center>
<br/>
</div>
]]></field>
@ -240,7 +240,7 @@ ${mel[aml.id]}
</table>
<center>Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name} </center>
<center>Total overdue amount: ${object.credit} ${object.company_id.currency_id.name} </center>
<br/>
<br/>
</div>
@ -321,7 +321,7 @@ ${mel[aml.id]}
% endfor
</table>
<center>Total overdue amount: ${object.payment_amount_overdue} ${object.company_id.currency_id.name} </center>
<center>Total overdue amount: ${object.credit} ${object.company_id.currency_id.name} </center>
<br/>
</div>
]]></field>

View File

@ -23,30 +23,40 @@
<form string="Follow-up Steps" version="7.0">
<h1><field name="name"/></h1>
<group>
<group>
<div class="oe_inline">
After <field name="delay" style="width: 15%%" nolabel="1"/> days, do the following actions:
</div>
</group>
<group>
<field name="manual_action"/>
<field name="send_letter"/>
<field name="send_email"/>
<!--<field name="start" style="width: 25%%"/>-->
</group>
<p class="oe_grey">
</group>
<group>
<p class="oe_grey">
Manual actions can be followed up in the Customers Requiring Action report for
every customer and will only be set when the previous action has been marked as done,
which can be done in the Payments Follow-up tab of the Customer Form.
which can be done in the Payments Follow-up tab of the Customer Form.
</p>
<p class="oe_grey">
<!--<field name="start" style="width: 25%%"/>-->
</group>
</group>
<group>
<group>
<field name="manual_action"/>
<field name="send_letter"/>
<field name="send_email"/>
</group>
<group>
<p class="oe_grey">
The format for the letters and emails can be specified. For the letters (PDF report),
the legend is specified below. For emails, we make use of an email template. Changing the text,
will change the text of the email template.
will change the text of the email template. Don't forget to translate them as the language of the partner
is used.
</p>
</group>
</group>
<group string="Manual Action" attrs="{'invisible': [('manual_action', '=', False)]}">
<field name="manual_action_note" string="Action to perform" attrs="{'invisible': [('manual_action', '=', False)]}" placeholder="e.g. Give a phonecall, Check if he paid, ..."/>
@ -92,13 +102,7 @@
into folow-up levels that are triggered when the due date of the most overdue invoice has passed a
certain amount of days.
</p>
<p class ="oe_grey">
When the wizard for procesing the follow-ups is run, for every partner the most overdue invoice (without litigation) is checked.
If the amount of days overdue is greater or equal than the amount of days specified
and the actions of the previous follow-up level were done, then the actions checked
for the new follow-up level will be executed.
</p>
<field name="followup_line"/>
</form>
</field>

View File

@ -1,7 +1,7 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_followup_followup_line,account_followup.followup.line,model_account_followup_followup_line,account.group_account_user,1,0,0,0
access_account_followup_followup_line_manager,account_followup.followup.line.manager,model_account_followup_followup_line,account.group_account_manager,1,1,1,1
access_account_followup_followup_accountant,account_followup.followup user,model_account_followup_followup,account.group_account_user,1,0,0,0
access_account_followup_followup_manager,account_followup.followup.manager,model_account_followup_followup,account.group_account_manager,1,1,1,1
access_account_followup_stat_invoice,account_followup.stat.invoice,model_account_followup_stat,account.group_account_invoice,1,1,1,1
access_account_followup_stat_by_partner_manager,account_followup.stat.by.partner,model_account_followup_stat_by_partner,account.group_account_manager,1,1,1,1
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_followup_followup_line,account_followup.followup.line,model_account_followup_followup_line,account.group_account_invoice,1,0,0,0
access_account_followup_followup_line_manager,account_followup.followup.line.manager,model_account_followup_followup_line,account.group_account_manager,1,1,1,1
access_account_followup_followup_accountant,account_followup.followup user,model_account_followup_followup,account.group_account_invoice,1,0,0,0
access_account_followup_followup_manager,account_followup.followup.manager,model_account_followup_followup,account.group_account_manager,1,1,1,1
access_account_followup_stat_invoice,account_followup.stat.invoice,model_account_followup_stat,account.group_account_invoice,1,1,1,1
access_account_followup_stat_by_partner_manager,account_followup.stat.by.partner,model_account_followup_stat_by_partner,account.group_account_manager,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_account_followup_followup_line account_followup.followup.line model_account_followup_followup_line account.group_account_user account.group_account_invoice 1 0 0 0
3 access_account_followup_followup_line_manager account_followup.followup.line.manager model_account_followup_followup_line account.group_account_manager 1 1 1 1
4 access_account_followup_followup_accountant account_followup.followup user model_account_followup_followup account.group_account_user account.group_account_invoice 1 0 0 0
5 access_account_followup_followup_manager account_followup.followup.manager model_account_followup_followup account.group_account_manager 1 1 1 1
6 access_account_followup_stat_invoice account_followup.stat.invoice model_account_followup_stat account.group_account_invoice 1 1 1 1
7 access_account_followup_stat_by_partner_manager account_followup.stat.by.partner model_account_followup_stat_by_partner account.group_account_manager 1 1 1 1

View File

@ -79,25 +79,34 @@ class account_followup_sending_results(osv.osv_memory):
def do_report(self, cr, uid, ids, context=None):
res = {}
#print "context:", self.report_data
return context['report_data']
def do_done(self, cr, uid, ids, context=None):
return {}
def _get_description(self, cr, uid, context=None):
res = ""
if context!=None:
res = context['description']
self.report_data = context['report_data']
res = context['description']
return res
def _get_need_printing(self, cr, uid, context=None):
res = False
if context!=None:
if context['needprinting']:
res = context['needprinting']
return res
_name = 'account.followup.sending.results'
_description = 'Results from the sending of the different letters and emails'
_columns = {
'description':fields.text("Description", required=False),
'description':fields.text("Description", required=False, readonly=True),
'needprinting':fields.boolean("Needs printing")
}
_defaults = {
'description':_get_description
'needprinting':_get_need_printing,
'description':_get_description,
}
account_followup_sending_results()
@ -128,25 +137,7 @@ class account_followup_print(osv.osv_memory):
followp_id = self.pool.get('account_followup.followup').search(cr, uid, [('company_id', '=', company_id)], context=context)
return followp_id and followp_id[0] or False
# def do_continue(self, cr, uid, ids, context=None):
# mod_obj = self.pool.get('ir.model.data')
#
# if context is None:
# context = {}
# data = self.browse(cr, uid, ids, context=context)[0]
# model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all')], context=context)
# resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
# context.update({'followup_id': data.followup_id.id, 'date': data.date, 'company_id': data.followup_id.company_id.id})
# return {
# 'name': _('Select Partners'),
# 'view_type': 'form',
# 'context': context,
# 'view_mode': 'tree,form',
# 'res_model': 'account.followup.print.all',
# 'views': [(resource_id,'form')],
# 'type': 'ir.actions.act_window',
# 'target': 'new',
# }
@ -155,42 +146,46 @@ class account_followup_print(osv.osv_memory):
def process_partners(self, cr, uid, partner_ids, data, context=None):
partner_obj = self.pool.get('res.partner')
partner_ids_to_print = []
self.resulttext = "Report"
nbmanuals = 0
manuals = {}
nbmails = 0
nbunknownmails = 0
nbprints = 0
resulttext = " "
for partner in self.pool.get('account_followup.stat.by.partner').browse(cr, uid, partner_ids, context=context):
if partner.max_followup_id.manual_action:
partner_obj.do_partner_manual_action(cr, uid, [partner.partner_id.id], context)
nbmanuals = nbmanuals + 1
key = partner.partner_id.payment_responsible_id.name or "Empty"
manuals[key]= "Y"
if partner.max_followup_id.send_email:
partner_obj.do_partner_mail(cr, uid, [partner.partner_id.id], context)
nbmails = nbmails + 1
if partner.max_followup_id.manual_action:
partner_obj.do_partner_manual_action(cr, uid, [partner.partner_id.id], context)
nbmanuals = nbmanuals + 1
key = partner.partner_id.payment_responsible_id.name or "Empty"
if not key in manuals.keys():
manuals[key]= 1
else:
manuals[key] = manuals[key] + 1
if partner.max_followup_id.send_email:
nbunknownmails += partner_obj.do_partner_mail(cr, uid, [partner.partner_id.id], context)
nbmails += 1
if partner.max_followup_id.send_letter:
partner_ids_to_print.append(partner.id)
nbprints = nbprints+ 1
nbprints += 1
partner_obj.message_post(cr, uid, [partner.partner_id.id], body=_("Follow-up letter will be sent"), context=context)
self.resulttext = self.resulttext + str(nbmanuals) + "Changed \n" + str(nbmails) + " Emailed \n " + str(nbprints) + "Printed \n"
resulttext = resulttext + str(nbmails) + " emails sent (" + str(nbunknownmails) + " with unknown email) \n " + str(nbprints) + " letters in report \n " + str(nbmanuals) + " total manual action(s) assigned: \n \n"
needprinting = False
if nbprints > 0:
needprinting = True
for item in manuals:
self.resulttext = self.resulttext + item + ":" + manuals[item] + "\n"
resulttext = resulttext + item + ":" + str(manuals[item]) + "\n"
result = {}
action = partner_obj.do_partner_print(cr, uid, partner_ids_to_print, data, context)
return action or {}
result['needprinting'] = needprinting
result['resulttext'] = resulttext
result['action'] = action or {}
return result
def do_update_followup_level(self, cr, uid, to_update, partner_list, date, context=None):
#update the followupo level on account.move.line
for id in to_update.keys():
if to_update[id]['partner_id'] in partner_list:
self.pool.get('account.move.line').write(cr, uid, [int(id)], {'followup_line_id': to_update[id]['level'], 'followup_date': date})
# cr.execute(
# "UPDATE account_move_line "\
# "SET followup_line_id=%s, followup_date=%s "\
# "WHERE id=%s",
# (to_update[id]['level'],
# date, int(id),))
def do_process(self, cr, uid, ids, context=None):
tmp = self._get_partners_followp(cr, uid, ids, context=context)
@ -200,16 +195,17 @@ class account_followup_print(osv.osv_memory):
data = self.read(cr, uid, ids, [], context)[0]
data['followup_id'] = data['followup_id'][0]
self.do_update_followup_level(cr, uid, to_update, partner_list, date, context=context)
res = self.process_partners(cr, uid, partner_list, data, context=context)
restot = self.process_partners(cr, uid, partner_list, data, context=context)
res = restot['action']
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}
data = self.browse(cr, uid, ids, context=context)[0]
model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_sending_results')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
context.update({'description': self.resulttext, 'report_data': res})
context.update({'description': restot['resulttext'], 'needprinting': restot['needprinting'], 'report_data': res})
return {
'name': _('Incredibly interesting report'),
'name': _('Send Letters and Emails: Actions Summary'),
'view_type': 'form',
'context': context,
'view_mode': 'tree,form',
@ -222,16 +218,8 @@ class account_followup_print(osv.osv_memory):
def _get_summary(self, cr, uid, context=None):
if context is None:
context = {}
return context.get('summary', '')
#def _get_partners(self, cr, uid, context=None):
# return self._get_partners_followp(cr, uid, [], context=context)['partner_ids']
def _get_msg(self, cr, uid, context=None):
return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.follow_up_msg
return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.follow_up_msg
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
@ -240,7 +228,6 @@ class account_followup_print(osv.osv_memory):
'email_subject': _('Invoices Reminder'),
'partner_lang': True,
#'partner_ids': _get_partners,
'summary': _get_summary,
}
def _get_partners_followp(self, cr, uid, ids, context=None):
@ -312,38 +299,6 @@ class account_followup_print(osv.osv_memory):
return {'partner_ids': partner_list, 'to_update': to_update}
#OLD FUNCTION!
def do_print(self, cr, uid, ids, context=None):
if context is None:
context = {}
data = self.read(cr, uid, ids, [], context=context)[0]
res = self._get_partners_followp(cr, uid, ids, context)['to_update'] #-> only to_update part
to_update = res
data['followup_id'] = 'followup_id' in context and context['followup_id'] or False
date = 'date' in context and context['date'] or data['date']
if not data['test_print']:
for id in to_update.keys():
if to_update[id]['partner_id'] in data['partner_ids']:
self.pool.get('account.move.line').write(cr, uid, [int(id)], {'followup_line_id': to_update[id], 'followup_date': date})
# cr.execute(
# "UPDATE account_move_line "\
# "SET followup_line_id=%s, followup_date=%s "\
# "WHERE id=%s",
# (to_update[id]['level'],
# date, int(id),))
data.update({'date': context['date']})
datas = {
'ids': [],
'model': 'account_followup.followup',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'account_followup.followup.print',
'datas': datas,
}
account_followup_print()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -74,35 +74,22 @@
<field name="name">account.followup.sending.results.form</field>
<field name="model">account.followup.sending.results</field>
<field name="arch" type="xml">
<form string="Results of the sending committee" version="7.0">
<form string="Summary of actions" version="7.0">
<header>
<field name="description"/>
<field name="description" readonly="True" />
</header>
<footer>
<button name="do_report" string="Download report here" type="object" class="oe_highlight"/>
<field name="needprinting" invisible="1"/>
<div attrs="{'invisible':[('needprinting','=', False)]}">
<button name="do_report" string="Download report here" type="object" class="oe_highlight"/>
</div>
<div attrs="{'invisible':[('needprinting','!=', False)]}">
<button name="do_done" string="Close" type="object" class="oe_highlight"/>
</div>
</footer>
</form>
</field>
</record>
<!--<record id="view_account_followup_print_all_msg" model="ir.ui.view">
<field name="name">account.followup.print.all.msg.form</field>
<field name="model">account.followup.print.all</field>
<field name="arch" type="xml">
<form string="Summary" version="7.0">
<separator string="Summary"/>
<field name="summary"/>
</form>
</field>
</record>
<record id="action_account_followup_print_all" model="ir.actions.act_window">
<field name="name">Send Follow-Ups</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.followup.print.all</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>-->
</data>
</openerp>