[IMP] First changes wizard and functional fields
bzr revid: jco@openerp.com-20121023122324-xn3jr015b3ib7j47
This commit is contained in:
parent
21a9b3e2c1
commit
4e14df3180
|
@ -78,7 +78,7 @@ class account_move_line(osv.osv):
|
|||
'followup_date': fields.date('Latest Follow-up', select=True),
|
||||
'payment_commitment':fields.text('Commitment'),
|
||||
'payment_date':fields.date('Date'),
|
||||
'payment_note':fields.text('Payment note'),
|
||||
#'payment_note':fields.text('Payment note'),
|
||||
'payment_new_action':fields.text('New action'),
|
||||
}
|
||||
|
||||
|
@ -115,48 +115,60 @@ res_company()
|
|||
class res_partner(osv.osv):
|
||||
|
||||
|
||||
def _get_latest_followup_date(self, cr, uid, ids):
|
||||
def _get_latest_followup_date(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for partner in self.browse(cr, uid, ids):
|
||||
accountmovelines = self.pool.get('account.account_move_line').search(cr, uid, [('partner_id', '=', partner.id)])
|
||||
latest_date = 0
|
||||
for accountmoveline in accountmovelines:
|
||||
if (latest_date < accountmoveline.followup_date):
|
||||
latest_date = accountmoveline.followup_date
|
||||
res[partner.id] = latest_date
|
||||
return res
|
||||
|
||||
def _test_latestfollowup(self, cr, uid, ids, name, arg, context = None):
|
||||
res = {}
|
||||
for partner in self.browse(cr, uid, ids, context = context):
|
||||
res[partner.id] = 5
|
||||
|
||||
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:
|
||||
amls2 = filter(lambda a: (a.state != 'draft') and (a.account_id.type is 'receivable')
|
||||
and (a.debit > 0), accountmovelines)
|
||||
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
|
||||
return res
|
||||
|
||||
|
||||
|
||||
|
||||
def _get_latest_followup_level_id(self, cr, uid, ids, context = None):
|
||||
def _get_latest_followup_level_id(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for partner in self.browse(cr, uid, ids, context = context):
|
||||
accountmovelines = self.pool.get('account.account_move_line').search(cr, uid, [('partner_id', '=', partner.id)])
|
||||
for partner in self.browse(cr, uid, ids):
|
||||
amls = partner.accountmoveline_ids
|
||||
level_id = 0
|
||||
level_days = -1000
|
||||
for accountmoveline in accountmovelines:
|
||||
if (level_days < accountmoveline.followup_id.delay):
|
||||
level_days = accountmoveline.followup_id.delay
|
||||
latest_date = accountmoveline.followup_id.followup_date
|
||||
res[partner.id] = latest_date
|
||||
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:
|
||||
if (accountmoveline.followup_line_id != False) and (level_days < accountmoveline.followup_line_id.delay) and (accountmoveline.state != "draft"): # and (accountmoveline.debit > 0):
|
||||
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
|
||||
|
||||
_inherit = "res.partner"
|
||||
_columns = {
|
||||
#'payment_responsible_id':fields.many2one('res.partner', ondelete='set null'),
|
||||
'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'),
|
||||
'payment_responsible_id':fields.many2one('res.users', ondelete='set null'),
|
||||
#'payment_followup_level_id':fields.many2one('account_followup.followup.line', 'Followup line'),
|
||||
'payment_note':fields.text('Payment note', help="Payment note"),
|
||||
'payment_new_action':fields.text('New action'), #one2many?
|
||||
'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id'),
|
||||
'latest_followup_date':fields.function(_test_latestfollowup, method=True, type='integer', string="latest followup date"),
|
||||
#'latest_followup_level_id':fields.function(_get_followup_level_id, type='one2many'),
|
||||
'payment_new_action':fields.text('New action'), #one2many/selection?
|
||||
'accountmoveline_ids':fields.one2many('account.move.line', 'partner_id'),
|
||||
'latest_followup_date':fields.function(_get_latest_followup_date, method=True, type='date', string="latest followup date"),
|
||||
'latest_followup_level_id':fields.function(_get_latest_followup_level_id, method=True,
|
||||
type='many2one', relation='account_followup.followup.line', string="latest followup level"),
|
||||
}
|
||||
|
||||
|
||||
res_partner()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -13,16 +13,32 @@
|
|||
<form string="Customer FollowUp form">
|
||||
<group col="4" colspan="4">
|
||||
<field name="name"/>
|
||||
<field name="phone"/>
|
||||
<field name="phone" />
|
||||
</group>
|
||||
<separator name="Detail of accounts"/>
|
||||
<!--<field name="accountmoveline_ids"/>-->
|
||||
<separator name="Payment Followup Remarks"/>
|
||||
<separator string="Detail of accounts" />
|
||||
<field name="accountmoveline_ids" nolabel="1" domain="[('debit', '>', 0)]">
|
||||
<tree string="Account Move line" editable="bottom">
|
||||
<field name="date" readonly="True"/>
|
||||
<field name="move_id" readonly="True"/>
|
||||
<field name="ref" readonly="True"/>
|
||||
|
||||
<field name="debit" readonly="True"/>
|
||||
<field name="credit" readonly="True"/>
|
||||
<field name="followup_date" readonly="True"/>
|
||||
<field name="followup_line_id" readonly="True"/>
|
||||
<field name="blocked" string="Litigation"/>
|
||||
<field name="payment_commitment"/>
|
||||
<field name="payment_date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<newline/>
|
||||
<separator string="Payment Followup Remarks"/>
|
||||
<!--<field name="payment_responsible_id"/>-->
|
||||
<group col="4" colspan="4">
|
||||
<field name="payment_note"/>
|
||||
<field name="payment_followup_level_id"/>
|
||||
<!--<field name="payment_followup_level_id"/>-->
|
||||
<field name="payment_new_action"/>
|
||||
<field name="latest_followup_level_id"/>
|
||||
<field name="latest_followup_date"/>
|
||||
</group>
|
||||
</form>
|
||||
|
@ -36,12 +52,14 @@
|
|||
<field name="priority" eval="20"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Customer Followup">
|
||||
<field name="name"/>
|
||||
<field name="payment_note"/>
|
||||
<field name="payment_new_action"/>
|
||||
<field name="email"/>
|
||||
<field name="phone"/>
|
||||
<!--<field name="latest_followup_date"/>-->
|
||||
<field name="name"/>
|
||||
<field name="latest_followup_level_id"/>
|
||||
<field name="latest_followup_date"/>
|
||||
<field name="payment_new_action"/>
|
||||
<field name="payment_note"/>
|
||||
<field name="phone"/>
|
||||
<field name="email"/>
|
||||
<!-- <field name="latest_followup_date"/>-->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -59,6 +77,7 @@
|
|||
|
||||
|
||||
|
||||
|
||||
<record id="action_view_customer_followup_form" model="ir.actions.act_window.view">
|
||||
<field name="sequence" eval="2"/>
|
||||
<field name="view_mode">form</field>
|
||||
|
|
|
@ -31,7 +31,7 @@ class account_followup_print(osv.osv_memory):
|
|||
_description = 'Print Follow-up & Send Mail to Customers'
|
||||
_columns = {
|
||||
'date': fields.date('Follow-up Sending Date', required=True, help="This field allow you to select a forecast date to plan your follow-ups"),
|
||||
'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True),
|
||||
'followup_id': fields.many2one('account_followup.followup', 'Follow-Up', required=True, readonly = True),
|
||||
}
|
||||
|
||||
def _get_followup(self, cr, uid, context=None):
|
||||
|
@ -155,6 +155,7 @@ class account_followup_print_all(osv.osv_memory):
|
|||
data = self.browse(cr, uid, ids, context=context)[0]
|
||||
company_id = 'company_id' in context and context['company_id'] or data.company_id.id
|
||||
|
||||
|
||||
cr.execute(
|
||||
"SELECT l.partner_id, l.followup_line_id,l.date_maturity, l.date, l.id "\
|
||||
"FROM account_move_line AS l "\
|
||||
|
@ -193,8 +194,19 @@ class account_followup_print_all(osv.osv_memory):
|
|||
partner_list = []
|
||||
to_update = {}
|
||||
for partner_id, followup_line_id, date_maturity,date, id in move_lines:
|
||||
|
||||
if not partner_id:
|
||||
continue
|
||||
#part = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
|
||||
#print "Respartner: " + part.send_letter
|
||||
|
||||
#if not partns[0].send_letter:
|
||||
# continue
|
||||
|
||||
#if not partner_id.send_letter:
|
||||
# continue
|
||||
|
||||
|
||||
if followup_line_id not in fups:
|
||||
continue
|
||||
stat_line_id = partner_id * 10000 + company_id
|
||||
|
@ -207,6 +219,7 @@ class account_followup_print_all(osv.osv_memory):
|
|||
if stat_line_id not in partner_list:
|
||||
partner_list.append(stat_line_id)
|
||||
to_update[str(id)]= {'level': fups[followup_line_id][1], 'partner_id': stat_line_id}
|
||||
|
||||
return {'partner_ids': partner_list, 'to_update': to_update}
|
||||
|
||||
def do_mail(self, cr, uid, ids, context=None):
|
||||
|
@ -221,70 +234,71 @@ class account_followup_print_all(osv.osv_memory):
|
|||
partners = [stat_by_partner_line / 10000 for stat_by_partner_line in stat_by_partner_line_ids]
|
||||
model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_followup_print_all_msg')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
if data.email_conf:
|
||||
if True: #should not depend on this
|
||||
msg_sent = ''
|
||||
msg_unsent = ''
|
||||
data_user = user_obj.browse(cr, uid, uid, context=context)
|
||||
for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context):
|
||||
ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))])
|
||||
data_lines = move_obj.browse(cr, uid, ids_lines, context=context)
|
||||
total_amt = 0.0
|
||||
for line in data_lines:
|
||||
total_amt += line.debit - line.credit
|
||||
dest = False
|
||||
if partner:
|
||||
dest = [partner.email]
|
||||
if not data.partner_lang:
|
||||
body = data.email_body
|
||||
else:
|
||||
cxt = context.copy()
|
||||
cxt['lang'] = partner.lang
|
||||
body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg
|
||||
move_line = ''
|
||||
subtotal_due = 0.0
|
||||
subtotal_paid = 0.0
|
||||
subtotal_maturity = 0.0
|
||||
balance = 0.0
|
||||
l = '--------------------------------------------------------------------------------------------------------------------------'
|
||||
head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l
|
||||
for i in data_lines:
|
||||
maturity = 0.00
|
||||
if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit):
|
||||
maturity = i.debit - i.credit
|
||||
subtotal_due = subtotal_due + i.debit
|
||||
subtotal_paid = subtotal_paid + i.credit
|
||||
subtotal_maturity = subtotal_maturity + int(maturity)
|
||||
balance = balance + (i.debit - i.credit)
|
||||
move_line = move_line + (i.date).rjust(10) + '\t'+ (i.name).rjust(10) + '\t'+ (i.ref or '').rjust(10) + '\t' + (i.date_maturity or '').rjust(10) + '\t' + str(i.debit).rjust(10) + '\t' + str(i.credit).rjust(10) + '\t' + str(maturity).rjust(10) + '\t' + str(i.blocked).rjust(10) + '\n'
|
||||
move_line = move_line + l + '\n'+ '\t\t\t' + 'Sub total'.rjust(35) + '\t' + (str(subtotal_due) or '').rjust(10) + '\t' + (str(subtotal_paid) or '').rjust(10) + '\t' + (str(subtotal_maturity) or '').rjust(10)+ '\n'
|
||||
move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l
|
||||
val = {
|
||||
'partner_name':partner.name,
|
||||
'followup_amount':total_amt,
|
||||
'user_signature':data_user.name,
|
||||
'company_name':data_user.company_id.name,
|
||||
'company_currency':data_user.company_id.currency_id.name,
|
||||
'line':move_line,
|
||||
'heading': head,
|
||||
'date':time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
body = body%val
|
||||
sub = tools.ustr(data.email_subject)
|
||||
msg = ''
|
||||
if dest:
|
||||
try:
|
||||
vals = {'state': 'outgoing',
|
||||
'subject': sub,
|
||||
'body_html': '<pre>%s</pre>' % body,
|
||||
'email_to': dest,
|
||||
'email_from': data_user.email or tools.config.options['email_from']}
|
||||
self.pool.get('mail.mail').create(cr, uid, vals, context=context)
|
||||
msg_sent += partner.name + '\n'
|
||||
except Exception, e:
|
||||
raise osv.except_osv('Error !', e )
|
||||
else:
|
||||
msg += partner.name + '\n'
|
||||
msg_unsent += msg
|
||||
if True: #partner.latest_followup_level_id.send_email:
|
||||
ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))])
|
||||
data_lines = move_obj.browse(cr, uid, ids_lines, context=context)
|
||||
total_amt = 0.0
|
||||
for line in data_lines:
|
||||
total_amt += line.debit - line.credit
|
||||
dest = False
|
||||
if partner:
|
||||
dest = [partner.email]
|
||||
if not data.partner_lang:
|
||||
body = data.email_body
|
||||
else:
|
||||
cxt = context.copy()
|
||||
cxt['lang'] = partner.lang
|
||||
body = user_obj.browse(cr, uid, uid, context=cxt).company_id.follow_up_msg
|
||||
move_line = ''
|
||||
subtotal_due = 0.0
|
||||
subtotal_paid = 0.0
|
||||
subtotal_maturity = 0.0
|
||||
balance = 0.0
|
||||
l = '--------------------------------------------------------------------------------------------------------------------------'
|
||||
head = l+ '\n' + 'Date'.rjust(10) + '\t' + 'Description'.rjust(10) + '\t' + 'Ref'.rjust(10) + '\t' + 'Due date'.rjust(10) + '\t' + 'Due'.rjust(10) + '\t' + 'Paid'.rjust(10) + '\t' + 'Maturity'.rjust(10) + '\t' + 'Litigation'.rjust(10) + '\n' + l
|
||||
for i in data_lines:
|
||||
maturity = 0.00
|
||||
if i.date_maturity < time.strftime('%Y-%m-%d') and (i.debit - i.credit):
|
||||
maturity = i.debit - i.credit
|
||||
subtotal_due = subtotal_due + i.debit
|
||||
subtotal_paid = subtotal_paid + i.credit
|
||||
subtotal_maturity = subtotal_maturity + int(maturity)
|
||||
balance = balance + (i.debit - i.credit)
|
||||
move_line = move_line + (i.date).rjust(10) + '\t'+ (i.name).rjust(10) + '\t'+ (i.ref or '').rjust(10) + '\t' + (i.date_maturity or '').rjust(10) + '\t' + str(i.debit).rjust(10) + '\t' + str(i.credit).rjust(10) + '\t' + str(maturity).rjust(10) + '\t' + str(i.blocked).rjust(10) + '\n'
|
||||
move_line = move_line + l + '\n'+ '\t\t\t' + 'Sub total'.rjust(35) + '\t' + (str(subtotal_due) or '').rjust(10) + '\t' + (str(subtotal_paid) or '').rjust(10) + '\t' + (str(subtotal_maturity) or '').rjust(10)+ '\n'
|
||||
move_line = move_line + '\t\t\t' + 'Balance'.rjust(33) + '\t' + str(balance).rjust(10) + '\n' + l
|
||||
val = {
|
||||
'partner_name':partner.name,
|
||||
'followup_amount':total_amt,
|
||||
'user_signature':data_user.name,
|
||||
'company_name':data_user.company_id.name,
|
||||
'company_currency':data_user.company_id.currency_id.name,
|
||||
'line':move_line,
|
||||
'heading': head,
|
||||
'date':time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
body = body%val
|
||||
sub = tools.ustr(data.email_subject)
|
||||
msg = ''
|
||||
if dest:
|
||||
try:
|
||||
vals = {'state': 'outgoing',
|
||||
'subject': sub,
|
||||
'body_html': '<pre>%s</pre>' % body,
|
||||
'email_to': dest,
|
||||
'email_from': data_user.email or tools.config.options['email_from']}
|
||||
self.pool.get('mail.mail').create(cr, uid, vals, context=context)
|
||||
msg_sent += partner.name + '\n'
|
||||
except Exception, e:
|
||||
raise osv.except_osv('Error !', e )
|
||||
else:
|
||||
msg += partner.name + '\n'
|
||||
msg_unsent += msg
|
||||
if not msg_unsent:
|
||||
summary = _("All Emails have been successfully sent to Partners:.\n\n%s") % msg_sent
|
||||
else:
|
||||
|
@ -312,8 +326,9 @@ class account_followup_print_all(osv.osv_memory):
|
|||
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']
|
||||
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']:
|
||||
|
@ -326,6 +341,7 @@ class account_followup_print_all(osv.osv_memory):
|
|||
(to_update[id]['level'],
|
||||
date, int(id),))
|
||||
data.update({'date': context['date']})
|
||||
print data
|
||||
datas = {
|
||||
'ids': [],
|
||||
'model': 'account_followup.followup',
|
||||
|
@ -337,6 +353,7 @@ class account_followup_print_all(osv.osv_memory):
|
|||
'datas': datas,
|
||||
}
|
||||
|
||||
|
||||
account_followup_print_all()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -71,33 +71,12 @@
|
|||
<header>
|
||||
<button name="do_mail" string="Send Mails" type="object" class="oe_highlight"/>
|
||||
<button name="do_print" string="Print Follow Ups" type="object" class="oe_highlight"/>
|
||||
|
||||
<button name="do_process" string="Process" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel"/>
|
||||
</header>
|
||||
<notebook>
|
||||
<page string="Partner Selection">
|
||||
<field name="partner_ids" context="{'search_default_balance_positive': 1}" domain="[('company_id','=',context.get('company_id',False))]"/>
|
||||
</page>
|
||||
<page string="Email Settings">
|
||||
<group col="4">
|
||||
<field name="email_conf" colspan="4"/>
|
||||
<field name="partner_lang" colspan="4"/>
|
||||
<field name="test_print" colspan="4"/>
|
||||
<field name="email_subject" colspan="4"/>
|
||||
<field name="email_body" colspan="4" nolabel="1"/>
|
||||
</group>
|
||||
<group string="Legend">
|
||||
<label string="%%(partner_name)s: Partner name"/>
|
||||
<label string="%%(user_signature)s: User name"/>
|
||||
<label string="%%(followup_amount)s: Total Amount Due"/>
|
||||
<label string="%%(date)s: Current Date"/>
|
||||
<label string="%%(company_name)s: User's Company name"/>
|
||||
<label string="%%(company_currency)s: User's Company Currency"/>
|
||||
<label string="%%(heading)s: Move line header"/>
|
||||
<label string="%%(line)s: Ledger Posting lines"/>
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
<field name="partner_ids" context="{'search_default_balance_positive': 1}" domain="[('company_id','=',context.get('company_id',False))]"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue