[IMP] Finalized tests with a test with paying invoice and clearing action afterwards
bzr revid: jco@openerp.com-20121129135346-hqd7bcdv1nfujj5v
This commit is contained in:
@@ -260,8 +260,6 @@ class res_partner(osv.osv):
|
||||
}
|
||||
|
||||
|
||||
def do_button_mail(self, cr, uid, ids, context=None):
|
||||
self.do_partner_mail(cr, uid, ids, context=context)
|
||||
|
||||
|
||||
_inherit = "res.partner"
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
<div class="oe_right oe_button_box" name="followup_button">
|
||||
<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', '<=', 0.0)]}" />
|
||||
<button name="do_button_mail" type="object" string="Send Overdue Email" groups="account.group_account_user"
|
||||
<button name="do_partner_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', '<=', 0.0)]}"/>
|
||||
</div>
|
||||
<p attrs="{'invisible':[('latest_followup_date','=', False)]}">
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
appropriate measures in order to carry out this payment in the next 8 days.
|
||||
Would your payment have been carried out after this mail was sent, please ignore this message. Do not hesitate to
|
||||
contact our accounting department at (+32).10.68.94.39.
|
||||
Best Regards,
|
||||
|
||||
</p>
|
||||
<br/>
|
||||
Best Regards,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
|
||||
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import tools
|
||||
from openerp.tests.common import TransactionCase
|
||||
|
||||
import pdb
|
||||
import netsvc
|
||||
|
||||
class TestAccountFollowup(TransactionCase):
|
||||
@@ -26,12 +24,16 @@ class TestAccountFollowup(TransactionCase):
|
||||
self.partner_id = self.partner.create(cr, uid, {'name':'Test Company',
|
||||
'email':'test@localhost',
|
||||
'is_company': True,
|
||||
'state': 'draft'},
|
||||
},
|
||||
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.account_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "a_recv")[1]
|
||||
self.journal_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "bank_journal")[1]
|
||||
self.pay_account_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "cash")[1]
|
||||
self.period_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "period_10")[1]
|
||||
|
||||
self.first_followup_line_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account_followup", "demo_followup_line1")[1]
|
||||
self.last_followup_line_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account_followup", "demo_followup_line3")[1]
|
||||
self.product_id = self.registry("ir.model.data").get_object_reference(cr, uid, "product", "product_product_6")[1]
|
||||
self.invoice_id = self.invoice.create(cr, uid, {'partner_id': self.partner_id,
|
||||
'account_id': self.account_id,
|
||||
@@ -41,72 +43,117 @@ class TestAccountFollowup(TransactionCase):
|
||||
'product_id': self.product_id,
|
||||
'quantity': 5,
|
||||
'price_unit':200
|
||||
})]}, context=None)
|
||||
|
||||
print self.invoice.browse(cr, uid, self.invoice_id).state
|
||||
})]})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'account.invoice', self.invoice_id, 'invoice_open' , cr)
|
||||
print self.invoice.browse(cr, uid, self.invoice_id).state
|
||||
print self.invoice.browse(cr, uid, self.invoice_id).move_lines
|
||||
# context = {}
|
||||
# self.invoice.action_date_assign(cr, uid, [self.invoice_id])
|
||||
# self.invoice.action_move_create(cr, uid, [self.invoice_id], context=context)
|
||||
# self.invoice.action_number(cr, uid, [self.invoice_id], context=context)
|
||||
# self.invoice.invoice_validate(cr, uid, [self.invoice_id], context=context)
|
||||
print self.invoice.browse(cr, uid, self.invoice_id, context=None).date_due
|
||||
wf_service.trg_validate(uid, 'account.invoice', self.invoice_id, 'invoice_open', cr)
|
||||
|
||||
self.voucher = self.registry("account.voucher")
|
||||
|
||||
|
||||
def test_00_send_followup_after_3_days(self):
|
||||
""" Send follow up after 3 days and check nothing is done (as first follow-up level is only after 15 days)"""
|
||||
cr, uid = self.cr, self.uid
|
||||
self.wizard_id = self.wizard.create(cr, uid, {
|
||||
'date':datetime.datetime.now().strftime("%Y-%m-%d"),
|
||||
current_date = datetime.datetime.now()
|
||||
delta = datetime.timedelta(days=3)
|
||||
result = current_date + delta
|
||||
self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime("%Y-%m-%d"),
|
||||
'followup_id': self.followup_id
|
||||
}, context={"followup_id": self.followup_id})
|
||||
res = self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
|
||||
print res
|
||||
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)
|
||||
|
||||
def test_05_send_followup__later_for_upgrade(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
|
||||
def run_wizard_three_times(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
current_date = datetime.datetime.now()
|
||||
delta = datetime.timedelta(days=40)
|
||||
result = current_date + delta
|
||||
print "Resulting date", result
|
||||
self.wizard_id = self.wizard.create(cr, uid, {'date':result.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.wizard_id = self.wizard.create(cr, uid, {'date':result.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.wizard_id = self.wizard.create(cr, uid, {'date':result.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})
|
||||
|
||||
|
||||
def test_01_send_followup_later_for_upgrade(self):
|
||||
""" Send one follow-up after 15 days to check it upgrades to level 1"""
|
||||
cr, uid = self.cr, self.uid
|
||||
current_date = datetime.datetime.now()
|
||||
delta = datetime.timedelta(days=15)
|
||||
result = current_date + delta
|
||||
self.wizard_id = self.wizard.create(cr, uid, {
|
||||
'date':result.strftime("%Y-%m-%d"),
|
||||
'followup_id': self.followup_id
|
||||
}, context={"followup_id": self.followup_id})
|
||||
res = self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
|
||||
pdb.set_trace()
|
||||
print res
|
||||
print self.partner.browse(cr, uid, self.partner_id).name
|
||||
print self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id
|
||||
print self.partner.browse(cr, uid, self.partner_id).latest_followup_date
|
||||
self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
|
||||
self.assertEqual(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id.id, self.first_followup_line_id,
|
||||
"Not updated to the correct follow-up level")
|
||||
|
||||
|
||||
def test_10_check_manual_action_done(self):
|
||||
def test_02_check_manual_action(self):
|
||||
""" Check that when running the wizard three times that the manual action is set"""
|
||||
cr, uid = self.cr, self.uid
|
||||
self.run_wizard_three_times()
|
||||
self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action,
|
||||
"Call the customer on the phone! ", "Manual action not set")
|
||||
self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action_date,
|
||||
datetime.datetime.now().strftime("%Y-%m-%d"))
|
||||
|
||||
def test_03_filter_on_credit(self):
|
||||
""" Check the partners can be filtered on having credits """
|
||||
cr, uid = self.cr, self.uid
|
||||
ids = self.partner.search(cr, uid, [('credit', '>=', 0.0)])
|
||||
self.assertIn(self.partner_id, ids)
|
||||
|
||||
def test_04_action_done(self):
|
||||
""" Run the wizard 3 times, mark it as done, check the action fields are empty"""
|
||||
cr, uid = self.cr, self.uid
|
||||
partner_rec = self.partner.browse(cr, uid, self.partner_id)
|
||||
self.run_wizard_three_times()
|
||||
self.partner.action_done(cr, uid, self.partner_id)
|
||||
self.assertEqual(partner_rec.payment_next_action,
|
||||
"", "Manual action not emptied")
|
||||
self.assertFalse(partner_rec.payment_responsible_id)
|
||||
self.assertFalse(partner_rec.payment_next_action_date)
|
||||
|
||||
def test_05_litigation(self):
|
||||
""" Set the account move line as litigation, run the wizard 3 times and check nothing happened.
|
||||
Turn litigation off. Run the wizard 3 times and check it is in the right follow-up level.
|
||||
"""
|
||||
cr, uid = self.cr, self.uid
|
||||
aml_id = self.partner.browse(cr, uid, self.partner_id).unreconciled_aml_ids[0].id
|
||||
self.registry('account.move.line').write(cr, uid, aml_id, {'blocked': True})
|
||||
self.run_wizard_three_times()
|
||||
self.assertFalse(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id, "Litigation does not work")
|
||||
self.registry('account.move.line').write(cr, uid, aml_id, {'blocked': False})
|
||||
self.run_wizard_three_times()
|
||||
self.assertEqual(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id.id,
|
||||
self.last_followup_line_id, "Lines are not equal")
|
||||
|
||||
def test_06_pay_the_invoice(self):
|
||||
"""Run wizard until manual action, pay the invoice and check that partner has no follow-up level anymore and after running the wizard the action is empty"""
|
||||
cr, uid = self.cr, self.uid
|
||||
self.test_02_check_manual_action()
|
||||
current_date = datetime.datetime.now()
|
||||
delta = datetime.timedelta(days=40)
|
||||
delta = datetime.timedelta(days=1)
|
||||
result = current_date + delta
|
||||
print "Resulting date", result
|
||||
self.wizard_id = self.wizard.create(cr, uid, {
|
||||
'date':result.strftime("%Y-%m-%d"),
|
||||
self.invoice.pay_and_reconcile(cr, uid, [self.invoice_id], 1000.0, self.pay_account_id,
|
||||
self.period_id, self.journal_id, self.pay_account_id,
|
||||
self.period_id, self.journal_id,
|
||||
name = "Payment for test customer invoice follow-up")
|
||||
self.assertFalse(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id, "Level not empty")
|
||||
self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime("%Y-%m-%d"),
|
||||
'followup_id': self.followup_id
|
||||
}, context={"followup_id": self.followup_id})
|
||||
res = self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
|
||||
self.wizard_id = self.wizard.create(cr, uid, {
|
||||
'date':result.strftime("%Y-%m-%d"),
|
||||
'followup_id': self.followup_id
|
||||
}, context={"followup_id": self.followup_id})
|
||||
print res
|
||||
res = self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
|
||||
self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action, "Call the customer on the phone!", "Manual action not set")
|
||||
print res
|
||||
|
||||
self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id})
|
||||
partner_ref = self.partner.browse(cr, uid, self.partner_id)
|
||||
print partner_ref.credit, partner_ref.payment_next_action_date, partner_ref.payment_responsible_id
|
||||
self.assertEqual(0, self.partner.browse(cr, uid, self.partner_id).credit, "Credit != 0")
|
||||
self.assertFalse(self.partner.browse(cr, uid, self.partner_id).payment_next_action_date, "Next action date not cleared")
|
||||
|
||||
@@ -199,12 +199,20 @@ class account_followup_print(osv.osv_memory):
|
||||
|
||||
def clear_manual_actions(self, cr, uid, partner_list, context=None):
|
||||
# Partnerlist is list to exclude
|
||||
# Will
|
||||
# Will clear the actions of partners that have no due payments anymore
|
||||
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)]
|
||||
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)])
|
||||
print ids
|
||||
self.pool.get('res.partner').action_done(cr, uid, ids, context=context)
|
||||
ids = self.pool.get('res.partner').search(cr, uid, ['&', ('id', 'not in', partner_list_ids), '|',
|
||||
('payment_responsible_id', '!=', False),
|
||||
('payment_next_action_date', '!=', False)], context=context)
|
||||
partners = self.pool.get('res.partner').browse(cr, uid, ids, context=context)
|
||||
newids = []
|
||||
for part in partners:
|
||||
credit = 0
|
||||
for aml in part.unreconciled_aml_ids:
|
||||
credit +=aml.result
|
||||
if credit <= 0:
|
||||
newids.append(part.id)
|
||||
self.pool.get('res.partner').action_done(cr, uid, newids, context=context)
|
||||
return len(ids)
|
||||
|
||||
def do_process(self, cr, uid, ids, context=None):
|
||||
@@ -218,7 +226,9 @@ class account_followup_print(osv.osv_memory):
|
||||
#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)
|
||||
self.clear_manual_actions(cr, uid, partner_list, context=context)
|
||||
nbactionscleared = self.clear_manual_actions(cr, uid, partner_list, context=context)
|
||||
if nbactionscleared > 0:
|
||||
restot['resulttext'] = restot['resulttext'] + "<li>" + str(nbactionscleared) + " " + _("partners have no credits and as such the action is cleared") + "</li>"
|
||||
res = restot['action']
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
if context is None:
|
||||
|
||||
Reference in New Issue
Block a user