[IMP] Adding Python tests

bzr revid: jco@openerp.com-20121127165317-v5rmrw5wvx6yykyr
This commit is contained in:
Josse Colpaert 2012-11-27 17:53:17 +01:00
parent bf172d2959
commit f41866a703
8 changed files with 128 additions and 71 deletions

View File

@ -1381,7 +1381,7 @@ class account_invoice_line(osv.osv):
'quantity': fields.float('Quantity', digits_compute= dp.get_precision('Product Unit of Measure'), required=True),
'discount': fields.float('Discount (%)', digits_compute= dp.get_precision('Discount')),
'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
'company_id': fields.related('invoice_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True)
}

View File

@ -39,8 +39,6 @@ class followup(osv.osv):
}
_sql_constraints = [('company_uniq', 'unique(company_id)', 'Only one follow-up per company is allowed')]
followup()
class followup_line(osv.osv):
@ -96,7 +94,6 @@ Best Regards,
(_check_description, 'Your description is invalid, use the right legend or %% if you want to use the percent character.', ['description']),
]
followup_line()
class account_move_line(osv.osv):
@ -111,14 +108,10 @@ class account_move_line(osv.osv):
'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level',
ondelete='restrict'), #restrict deletion of the followup line
'followup_date': fields.date('Latest Follow-up', select=True),
'payment_commitment':fields.text('Commitment'),
'payment_date':fields.date('Date'),
'payment_next_action':fields.text('Next Action'),
'result':fields.function(_get_result, type='float', method=True,
string="Balance") #'balance' field is not the same
}
account_move_line()
class email_template(osv.osv):
@ -130,7 +123,6 @@ class email_template(osv.osv):
context['current_date'] = fields.date.context_today(cr, uid, context)
return super(email_template, self).render_template(cr, uid, template, model, res_id, context=context)
email_template()
class res_partner(osv.osv):
@ -149,7 +141,7 @@ class res_partner(osv.osv):
def get_latest_from_company(self, cr, uid, ids, names, arg, context=None, company_id=None):
def _get_latest(self, cr, uid, ids, names, arg, context=None, company_id=None):
res={}
if company_id == None:
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
@ -176,37 +168,6 @@ class res_partner(osv.osv):
'latest_followup_level_id': latest_level,
'latest_followup_level_id_without_lit': latest_level_without_lit}
return res
def _get_latest(self, cr, uid, ids, names, arg, context=None):
return self.get_latest_from_company(cr, uid, ids, names, arg, context=context)
#Not used, but works, field next_followup_level_id
def _get_next_followup_level_id(self, cr, uid, ids, name, arg, context=None):
company = self.pool.get("res.users").browse(cr, uid, uid, context=context).company_id
res = {}
for partner in self.browse(cr, uid, ids, context=context):
#Get latest
latest_id = partner.latest_followup_level_id_without_lit.id
latest = latest_id and self.pool.get('account_followup.followup.line').browse(cr, uid, latest_id, context=context) or False
old_delay = latest and latest.delay or False
print "Old Delay", old_delay
newlevel = latest and latest.id or False
delay = False
#Search next
fl_ar = self.pool.get('account_followup.followup.line').search(cr, uid, [('followup_id.company_id.id','=', company.id)])
for fl_obj in self.pool.get('account_followup.followup.line').browse(cr, uid, fl_ar, context=context):
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
return res
def do_partner_manual_action(self, cr, uid, partner_ids, context=None):
@ -281,7 +242,7 @@ class res_partner(osv.osv):
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=context)
return self.write(cr, uid, ids, {'payment_next_action_date': False, 'payment_next_action':'', 'payment_responsible_id': False}, context=context)
def do_button_print(self, cr, uid, ids, context=None):
assert(len(ids) == 1)
@ -303,16 +264,10 @@ class res_partner(osv.osv):
self.do_partner_mail(cr, uid, ids, context=context)
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=context):
if aml.partner_id.id not in partnerlist:
partnerlist.append(aml.partner_id.id)
return partnerlist
_inherit = "res.partner"
_columns = {
'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Follow-up Responsible', help="Responsible for making sure the action happens."), #TODO find better name for field
'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Follow-up Responsible',
help="Responsible for making sure the action happens."),
'payment_note':fields.text('Customer Payment Promise', help="Payment Note"),
'payment_next_action':fields.text('Next Action',
help="This is the next action to be taken by the user. It will automatically be set when the action fields are empty and the partner gets a follow-up level that requires a manual action. "),
@ -334,12 +289,8 @@ class res_partner(osv.osv):
help="The maximum follow-up level without taking into account the account move lines with litigation",
store=False,
multi="latest"),
'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=False),
'payment_amount_due':fields.related('credit', type='float', string="Total amount due", readonly=True),
}
res_partner()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -16,10 +16,10 @@
-
I create a follow-up.
-
!record {model: account.followup.print, id: account_followup_print_0}:
!record {model: account_followup.print, id: account_followup_print_0}:
{}
-
I will process follow-ups
-
!python {model: account.followup.print}: |
!python {model: account_followup.print}: |
self.do_process(cr, uid, [ref("account_followup_print_0")], {"active_ids": [ref("account_followup.account_followup_print_menu")], "active_id": ref("account_followup.account_followup_print_menu"),})

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_account_followup
checks = [
test_account_followup,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,62 @@
from datetime import datetime
import tools
from openerp.tests.common import TransactionCase
class TestAccountFollowup(TransactionCase):
def setUp(self):
""" setUp ***"""
super(TestAccountFollowup, self).setUp()
cr, uid = self.cr, self.uid
self.user = self.registry('res.users')
self.user_id = self.user.browse(cr, uid, uid)
self.partner = self.registry('res.partner')
self.invoice = self.registry('account.invoice')
self.invoice_line = self.registry('account.invoice.line')
self.wizard = self.registry('account_followup.print')
self.followup_id = self.registry('account_followup.followup')
self.partner_id = self.partner.create(cr, uid, {'name':'Test Company',
'email':'test@localhost',
'is_company': True,},
context=None)
self.followup_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account_followup", "demo_followup1")[1]
self.account_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "a_sale")[1]
self.invoice_id = self.invoice.create(cr, uid, {'partner_id': self.partner_id,
'account_id': self.account_id,
}, context=None)
#self.invoice_line_id = self.invoice_line.create(cr, uid, {'name': 'Product A',
# 'quantity': 5,
# 'price':251.21,
# 'invoice_id':self.invoice_id},
# context=None)
#self.invoice.write(cr, uid, self.invoice_id, {'invoice_line': (4, self.invoice_line_id, {})})
# self.invoice.action_date_assign(cr, uid, self.invoice_id)
# self.invoice.action_move_create(cr, uid, self.invoice_id, context=None)
# self.invoice.action_number(cr, uid, self.invoice_id, context=None)
# self.invoice.invoice_validate(cr, uid, self.invoice_id, context=None)
def test_00_send_followup_after_3_days(self):
cr, uid = self.cr, self.uid
self.wizard_id = self.wizard.create(cr, uid, {
'date':datetime.now().strftime("%Y-%m-%d"),
'followup_id': self.followup_id
}, context={"followup_id": self.followup_id})
self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
self.assertFalse(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id)
self.wizard_id = self.wizard.create(cr, uid, {
'date':(datetime.now() + datetime.timedelta(days=15)).strftime("%Y-%m-%d"),
'followup_id': self.followup_id
}, context={"followup_id": self.followup_id})
self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
self.assertTrue(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id)

View File

@ -77,7 +77,6 @@ account_followup_stat_by_partner()
class account_followup_sending_results(osv.osv_memory):
def do_report(self, cr, uid, ids, context=None):
return context['report_data']
@ -97,7 +96,7 @@ class account_followup_sending_results(osv.osv_memory):
res = context['needprinting']
return res
_name = 'account.followup.sending.results'
_name = 'account_followup.sending.results'
_description = 'Results from the sending of the different letters and emails'
_columns = {
'description':fields.text("Description", required=False, readonly=True),
@ -113,7 +112,7 @@ account_followup_sending_results()
class account_followup_print(osv.osv_memory):
_name = 'account.followup.print'
_name = 'account_followup.print'
_description = 'Print Follow-up & Send Mail to Customers'
_columns = {
'date': fields.date('Follow-up Sending Date', required=True,
@ -156,7 +155,7 @@ class account_followup_print(osv.osv_memory):
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)
partner_obj.do_partner_manual_action(cr, uid, [partner.partner_id.id], context=context)
nbmanuals = nbmanuals + 1
key = partner.partner_id.payment_responsible_id.name or _("Nobody")
if not key in manuals.keys():
@ -164,7 +163,7 @@ class account_followup_print(osv.osv_memory):
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)
nbunknownmails += partner_obj.do_partner_mail(cr, uid, [partner.partner_id.id], context=context)
nbmails += 1
if partner.max_followup_id.send_letter:
partner_ids_to_print.append(partner.id)
@ -184,7 +183,7 @@ class account_followup_print(osv.osv_memory):
resulttext = resulttext + "<li>" + item + ":" + str(manuals[item]) + "\n </li>"
resulttext += "</p>"
result = {}
action = partner_obj.do_partner_print(cr, uid, partner_ids_to_print, data, context)
action = partner_obj.do_partner_print(cr, uid, partner_ids_to_print, data, context=context)
result['needprinting'] = needprinting
result['resulttext'] = resulttext
result['action'] = action or {}
@ -196,16 +195,35 @@ class account_followup_print(osv.osv_memory):
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})
def clear_manual_actions(self, cr, uid, partner_list, context=None):
#Partnerlist is list to exclude
partner_list_ids = [partner.partner_id.id for partner in self.pool.get('account_followup.stat.by.partner').browse(cr, uid, partner_list, context=context)]
print "Clear Manual actions ids"
print partner_list_ids
parts = self.pool.get('res.partner').browse(cr, uid, partner_list_ids, context=context)
for part in parts:
print part.name, part.payment_responsible_id
ids = self.pool.get('res.partner').search(cr, uid, ['&', ('credit', '<=', 0), '&', ('id','not in',partner_list_ids), '|', ('payment_responsible_id', '!=', False),
('payment_next_action_date', '!=', False)])
parts = self.pool.get('res.partner').browse(cr, uid, ids, context=context)
print ids
self.pool.get('res.partner').action_done(cr, uid, ids, context=context)
def do_process(self, cr, uid, ids, context=None):
#Get partners
tmp = self._get_partners_followp(cr, uid, ids, context=context)
partner_list = tmp['partner_ids']
to_update = tmp['to_update']
date = self.browse(cr, uid, ids, context)[0].date
data = self.read(cr, uid, ids, [], context)[0]
date = self.browse(cr, uid, ids, context=context)[0].date
data = self.read(cr, uid, ids, [], context=context)[0]
data['followup_id'] = data['followup_id'][0]
#Update and process partners
self.do_update_followup_level(cr, uid, to_update, partner_list, date, context=context)
restot = self.process_partners(cr, uid, partner_list, data, context=context)
res = restot['action']
self.clear_manual_actions(cr, uid, partner_list, context=context)
res = restot['action']
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}

View File

@ -4,7 +4,7 @@
<record id="view_account_followup_print" model="ir.ui.view">
<field name="name">account.followup.print.form</field>
<field name="model">account.followup.print</field>
<field name="model">account_followup.print</field>
<field name="arch" type="xml">
<form string="Send follow-ups" version="7.0">
<group col="4">
@ -27,7 +27,7 @@
<record id="action_account_followup_print" model="ir.actions.act_window">
<field name="name">Send Follow-Ups</field>
<field name="res_model">account.followup.print</field>
<field name="res_model">account_followup.print</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
@ -70,8 +70,8 @@
</record>
<record id="view_account_followup_sending_results" model="ir.ui.view">
<field name="name">account.followup.sending.results.form</field>
<field name="model">account.followup.sending.results</field>
<field name="name">account_followup.sending.results.form</field>
<field name="model">account_followup.sending.results</field>
<field name="arch" type="xml">
<form string="Summary of actions" version="7.0">
<header>

View File

@ -23,7 +23,6 @@ import tools
from openerp.tests import common
class Test_Lunch(common.TransactionCase):
def setUp(self):
"""*****setUp*****"""
super(Test_Lunch, self).setUp()