[IMP] Clean-up before multi-compny

bzr revid: jco@openerp.com-20121122153049-uuv02l05cqqed7br
This commit is contained in:
Josse Colpaert 2012-11-22 16:30:49 +01:00
parent 1a38725f86
commit 205706f18d
7 changed files with 72 additions and 58 deletions

View File

@ -522,7 +522,8 @@ class account_move_line(osv.osv):
type='many2one', relation='account.invoice', fnct_search=_invoice_search),
'account_tax_id':fields.many2one('account.tax', 'Tax'),
'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'),
'company_id': fields.related('account_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True)
'company_id': fields.related('account_id', 'company_id', type='many2one', relation='res.company',
string='Company', store=True, readonly=True)
}
def _get_date(self, cr, uid, context=None):

View File

@ -32,8 +32,6 @@ class followup(osv.osv):
_description = 'Account Follow-up'
_rec_name = 'name'
_columns = {
#'name': fields.char('Name', size=64, required=True),
#'description': fields.text('Description'),
'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-up'),
'company_id': fields.many2one('res.company', 'Company', required=True),
'name': fields.related('company_id', 'name', string = "Name"),
@ -58,7 +56,7 @@ class followup_line(osv.osv):
_columns = {
'name': fields.char('Follow-Up Action', size=64, required=True),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of follow-up lines."),
'delay': fields.integer('Due Days', help="The number of days after the due date of the invoice to wait before sending the reminder. Could be negative if you want to send a polite alert beforehand."),
'delay': fields.integer('Due Days', help="The number of days after the due date of the invoice to wait before sending the reminder. Could be negative if you want to send a polite alert beforehand.", 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 an Email', help="When processing, it will send an email"),
@ -69,7 +67,7 @@ class followup_line(osv.osv):
'email_template_id':fields.many2one('email.template', 'Email Template', ondelete='set null'),
}
_order = 'delay'
_sql_constraints = [('days_uniq', 'unique(followup_id, delay)', 'Days of the follow-up levels must be different')] #TODO: ADD FOR multi-company!
_sql_constraints = [('days_uniq', 'unique(followup_id, delay)', 'Days of the follow-up levels must be different')]
_defaults = {
'send_email': True,
'send_letter': False,
@ -87,8 +85,6 @@ Best Regards,
}
def _check_description(self, cr, uid, ids, context=None):
for line in self.browse(cr, uid, ids, context=context):
if line.description:
@ -106,7 +102,6 @@ followup_line()
class account_move_line(osv.osv):
def set_kanban_state_litigation(self, cr, uid, ids, context=None):
for l in self.browse(cr, uid, ids, context):
self.write(cr, uid, [l.id], {'blocked': not l.blocked})
@ -120,24 +115,26 @@ class account_move_line(osv.osv):
_inherit = 'account.move.line'
_columns = {
'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level', ondelete='restrict'), #restrict deletion of the followup line
'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_note':fields.text('Payment note'),
'payment_next_action':fields.text('Next Action'),
'result':fields.function(_get_result, type='float', method=True, string="Balance") #TODO: what difference with the balance field on account.move.line?
'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):
_inherit = 'email.template'
#Adds current_date to the context. That way it can be used in the email templates
#TODO: need information
# Adds current_date to the context. That way it can be used to put
# the account move lines in bold that are overdue in the email
def render_template(self, cr, uid, template, model, res_id, context=None):
context['current_date'] = fields.date.context_today(cr, uid, context) #change by inheritance
context['current_date'] = fields.date.context_today(cr, uid, context)
return super(email_template, self).render_template(cr, uid, template, model, res_id, context)
email_template()
@ -168,11 +165,11 @@ class res_partner(osv.osv):
# return res
#
#
#TODO: refactor these functions: remove this one, rework _get_latest and _get_newt_followup_level_id must call _get_latest
#TODO: refactor these functions: remove this one, rework _get_latest and _get_next_followup_level_id must call _get_latest
def _get_latest_followup_level_id(self, cr, uid, ids, name, arg, context=None):
res = {}
for partner in self.browse(cr, uid, ids, context):
for partner in self.browse(cr, uid, ids, context=context):
level_days = False
res[partner.id] = False
for accountmoveline in partner.accountmoveline_ids:
@ -183,33 +180,29 @@ class res_partner(osv.osv):
return res
def _get_latest(self, cr, uid, ids, names, arg, context=None):
#TODO: refactor + take into account company id
def get_latest_from_company(self, cr, uid, ids, names, arg, context=None, company_id=None):
res={}
for partner in self.browse(cr, uid, ids, context):
# if company_id == None:
# company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
# else:
# company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
for partner in self.browse(cr, uid, ids, context=context):
amls = partner.accountmoveline_ids
latest_date = False
latest_level = False
latest_level_without_lit = False
latest_days = False
latest_level_without_lit = False
latest_days_without_lit = False
for aml in amls:
#Give initial value
if latest_date == False:
latest_date = aml.followup_date
if aml.followup_line_id:
latest_level = aml.followup_line_id.id
latest_days = aml.followup_line_id.delay
if not aml.blocked and latest_level_without_lit == False and aml.followup_line_id:
latest_level_without_lit = aml.followup_line_id.id
latest_days_without_lit = aml.followup_line_id.delay
#If initial value < ...
if latest_date and latest_level:
if aml.followup_date > latest_date:
latest_date = aml.followup_date
if aml.followup_line_id and aml.followup_line_id.delay > latest_days:
if (aml.followup_line_id != False) and (not latest_days or latest_days < aml.followup_line_id.delay):
latest_days = aml.followup_line_id.delay
latest_level = aml.followup_line_id.id
if not aml.blocked and latest_level_without_lit and aml.followup_line_id and aml.followup_line_id.delay > latest_days_without_lit:
if (not latest_date or latest_date < aml.followup_date):
latest_date = aml.followup_date
if (aml.blocked == False) and (aml.followup_line_id != False and
(not latest_days_without_lit or latest_days_without_lit < aml.followup_line_id.delay)):
latest_days_without_lit = aml.followup_line_id.delay
latest_level_without_lit = aml.followup_line_id.id
res[partner.id] = {'latest_followup_date': latest_date,
@ -217,6 +210,9 @@ class res_partner(osv.osv):
'latest_followup_level_id_without_lit': latest_level_without_lit}
return res
def _get_latest(self, cr, uid, ids, names, arg, context=None):
company = self.pool.get('res.users').browse(cr, uid, uid, context=context)
return self.get_latest_from_company(cr, uid, ids, names, arg, context=context, company_id=company)
#Problems company id? / Method necessary?
#TODO: must use the company_id of the uid + refactor
def _get_next_followup_level_id(self, cr, uid, ids, name, arg, context=None):

View File

@ -111,7 +111,7 @@
</div>
</group>
<label for="payment_note" class="oe_edit_only"/>
<field name="payment_note" placeholder="e.g. 50%% before 15th of may, balance before 1st of july."/>
<field name="payment_note" placeholder="e.g. 50%% before 15th of May, balance before 1st of July."/>
<p class="oe_grey"> <!--maybe only when accountmovelines empty-->
Below is the history of the transactions of this
customer. You can set an invoice in litigation in
@ -152,7 +152,8 @@
</record>
<!-- Menus about followup of customers -->
<menuitem id="account_followup_s" action="action_customer_followup" parent="menu_finance_followup" name="Do Manual Follow-Ups" sequence="3"/>
<menuitem id="account_followup_s" action="action_customer_followup"
parent="menu_finance_followup" name="Do Manual Follow-Ups" sequence="3"/>
</data>
</openerp>

View File

@ -1,6 +1,5 @@
<openerp>
<data>
<record id="view_account_followup_followup_line_tree" model="ir.ui.view">
<field name="name">account_followup.followup.line.tree</field>
<field name="model">account_followup.followup.line</field>
@ -107,7 +106,7 @@
</record>
<record id="action_account_followup_definition_form" model="ir.actions.act_window">
<field name="name">Follow-ups</field>
<field name="name">Payment Follow-ups</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account_followup.followup</field>
<field name="search_view_id" ref="view_account_followup_filter"/>
@ -122,19 +121,31 @@
</p>
</field>
</record>
<record id="action_account_manual_reconcile_receivable" model="ir.actions.act_window">
<field name="name">Reconcile Invoices &amp; Payments</field>
<field name="search_view_id" ref="view_account_followup_filter"/>
<field name="context">{'search_default_unreconciled': 1,'view_mode':True}</field>
<field name="domain">[('account_id.type', '=', 'receivable')]</field>
<field name="res_model">account.move.line</field>
<field name="view_id" ref="account.view_move_line_tree_reconcile"/>
<field name="view_mode">tree_account_reconciliation</field>
<field name="help" type="html">
<p>
No journal items found.
</p>
</field>
</record>
<menuitem
name="Reconcile Invoices &amp; Payments"
action="account.action_account_manual_reconcile"
action="action_account_manual_reconcile_receivable"
parent="menu_finance_followup"
sequence="0"
id="menu_manual_reconcile_followup"/>
<menuitem action="action_account_followup_definition_form" id="account_followup_menu" parent="account.menu_finance_configuration" name="Follow-up Levels"/>
<report auto="False" id="account_followup_followup_report" menu="False" model="account_followup.followup" name="account_followup.followup.print" rml="account_followup/report/account_followup_print.rml" string="Follow-up Report"/>
<record id="account_move_line_partner_tree" model="ir.ui.view">
<field name="name">account.move.line.partner.tree</field>
<field name="model">account.move.line</field>

View File

@ -65,7 +65,7 @@
<field name="search_view_id" ref="view_account_followup_stat_search"/>
</record>
<menuitem id="menu_finance_followup" parent="account.menu_finance" name="Payment Follow-up" groups="account.group_account_invoice"/>
<menuitem action="action_followup_stat" id="menu_action_followup_stat_follow" parent="menu_finance_followup" groups="account.group_account_invoice" name="Follow-Ups Analysis" sequence="10"/>
<menuitem action="action_followup_stat" id="menu_action_followup_stat_follow" parent="account.menu_finance_reporting" groups="account.group_account_invoice" name="Follow-Ups Analysis" sequence="10"/>
</data>
</openerp>

View File

@ -167,15 +167,20 @@ class account_followup_print(osv.osv_memory):
if partner.max_followup_id.send_letter:
partner_ids_to_print.append(partner.id)
nbprints += 1
partner_obj.message_post(cr, uid, [partner.partner_id.id], body=_("Follow-up letter will be sent from follow_up <I>") + partner.partner_id.latest_followup_level_id.name, context=context) + "</I>"
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"
message = _("Follow-up letter of ") + "\"" + partner.partner_id.latest_followup_level_id_without_lit.name + "\"" + "</I>" + _(" will be sent")
partner_obj.message_post(cr, uid, [partner.partner_id.id], body=message, context=context)
if nbunknownmails == 0:
resulttext += str(nbmails) + _(" emails sent")
else:
resulttext += str(nbmails) + _(" emails should have been sent, but ") + str(nbunknownmails) + _(" had unknown email addresses") + "\n <BR/> "
resulttext += "<BR/>" + str(nbprints) + _(" letters in report") + " \n <BR/>" + str(nbmanuals) + _(" total manual action(s) assigned:")
needprinting = False
if nbprints > 0:
needprinting = True
resulttext += "<ul>"
resulttext += "<p><ul>"
for item in manuals:
resulttext = resulttext + "<li>" + item + ":" + str(manuals[item]) + "\n </li>"
resulttext += "</ul>"
resulttext += "</ul></p>"
result = {}
action = partner_obj.do_partner_print(cr, uid, partner_ids_to_print, data, context)
result['needprinting'] = needprinting