[IMP] Add field for not sending emails
authorJosse Colpaert <jco@openerp.com>
Thu, 17 Jan 2013 16:31:59 +0000 (17:31 +0100)
committerJosse Colpaert <jco@openerp.com>
Thu, 17 Jan 2013 16:31:59 +0000 (17:31 +0100)
bzr revid: jco@openerp.com-20130117163159-ceqq1ewf55go05ua

addons/account_followup/account_followup.py
addons/account_followup/account_followup_customers.xml
addons/account_followup/wizard/account_followup_print.py

index 285a352..6ea90f5 100644 (file)
@@ -208,12 +208,13 @@ class res_partner(osv.osv):
         for partner in self.browse(cr, uid, partner_ids, context=ctx):
             if partner.email and partner.email.strip():
                 level = partner.latest_followup_level_id_without_lit
-                if level and level.send_email and level.email_template_id and level.email_template_id.id:
-                    mtp.send_mail(cr, uid, level.email_template_id.id, partner.id, context=ctx)
-                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=ctx)
+                if not partner.payment_no_email:
+                    if level and level.send_email and level.email_template_id and level.email_template_id.id:
+                        mtp.send_mail(cr, uid, level.email_template_id.id, partner.id, context=ctx)
+                    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=ctx)
             else:
                 unknown_mails = unknown_mails + 1
                 action_text = _("Email not sent because of email address of partner not filled in")
@@ -275,8 +276,17 @@ class res_partner(osv.osv):
                                 <center>Amount due: %s </center>''' % (total)
         return followup_table
 
+    def write(self, cr, uid, ids, vals, context=None):
+        if vals.get("payment_responsible_id", False):
+            for part in self.browse(cr, uid, ids, context=context):
+                if part.payment_responsible_id <> vals["payment_responsible_id"]:
+                    pass
+                    #message_post()
+        res = super(res_partner, self).write(cr, uid, ids, vals, context=context)
+        return res
+
     def action_done(self, cr, uid, ids, context=None):
-        return 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, 'payment_no_email': False}, context=context) 
 
     def do_button_print(self, cr, uid, ids, context=None):
         assert(len(ids) == 1)
@@ -408,13 +418,18 @@ class res_partner(osv.osv):
     _inherit = "res.partner"
     _columns = {
         'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Follow-up Responsible', 
-                                                 help="Optionally you can assign a user to this field, which will make him responsible for the action."), 
-        'payment_note':fields.text('Customer Payment Promise', help="Payment Note"),
+                                                 help="Optionally you can assign a user to this field, which will make him responsible for the action.", 
+                                                 track_visibility="onchange"), 
+        'payment_note':fields.text('Customer Payment Promise', help="Payment Note", track_visibility="onchange"),
         'payment_next_action':fields.text('Next Action', 
-                                    help="This is the next action to be taken.  It will automatically be set when the partner gets a follow-up level that requires a manual action. "), 
+                                    help="This is the next action to be taken.  It will automatically be set when the partner gets a follow-up level that requires a manual action. ", 
+                                    track_visibility="onchange"), 
         'payment_next_action_date':fields.date('Next Action Date',
                                     help="This is when the manual follow-up is needed. " \
-                                    "The date will be set to the current date when the partner gets a follow-up level that requires a manual action. Can be practical to set manually e.g. to see if he keeps his promises."), 
+                                    "The date will be set to the current date when the partner gets a follow-up level that requires a manual action. "\
+                                    "Can be practical to set manually e.g. to see if he keeps his promises."),
+        'payment_no_email':fields.boolean('Don\'t send follow-up emails meanwhile', help='When checked, the follow-up wizard will go to the next level,'\
+                                          ' print letters and set manual actions, but mails will not be sent. Follow-up will happen by doing manual actions. '), 
         'unreconciled_aml_ids':fields.one2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '=', False), '&', 
                             ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]), 
         'latest_followup_date':fields.function(_get_latest, method=True, type='date', string="Latest Follow-up Date", 
index 8a27730..ca1c509 100644 (file)
                         <filter string="Follow-ups To Do" domain="[('payment_next_action_date', '&lt;=', time.strftime('%%Y-%%m-%%d')), ('payment_amount_overdue', '>', 0.0)]" name="todo"/>
                         <separator/>
                         <filter string="No Responsible" domain="[('payment_responsible_id', '=', False)]"/>
-                        <filter string="My Follow-ups" domain="[('payment_responsible_id','=', uid)]"/>
+                        <filter string="My Follow-ups" domain="[('payment_responsible_id','=', uid)]" name="my"/>
                     </group>
                     <group expand="1" string="Group By...">
-                        <filter string="Responsible" context="{'group_by':'payment_responsible_id'}"/>
+                        <filter string="Follow-up Responsible" context="{'group_by':'payment_responsible_id'}"/>
                     </group>
                 </search>
             </field>
                             <label for="payment_next_action"/>
                             <div>
                                 <field name="payment_next_action_date" class="oe_inline"/>
-                                <button name="action_done" type="object" string="⇾ Mark as Done"
+                                <button name="action_done" type="object" string="⇾ Mark as Done ⇾"
                                      help="Click to mark the action as done." class="oe_link"
                                      attrs="{'invisible':[('payment_next_action_date','=', False)]}"
                                      groups="base.group_partner_manager"/>
+                                <field name="payment_no_email" attrs="{'invisible': [('payment_next_action_date','=', False)]}" groups="base.group_partner_manager"/>
+                                <i><label for="payment_no_email" attrs="{'invisible': [('payment_next_action_date','=', False)]}" groups="base.group_partner_manager"/></i>
                                 <field name="payment_next_action" placeholder="Action to be taken e.g. Give a phonecall, Check if it's paid, ..."/>
                             </div>
                         </group>
         <!-- 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"/>
-
+        <record id="action_customer_my_followup" model="ir.actions.act_window">
+            <field name="name">My Follow-Ups</field>
+            <field name="view_id" ref="customer_followup_tree"/>
+            <field name="res_model">res.partner</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,form</field>
+            <field name="domain">[('payment_amount_due', '>', 0.0)]</field>
+            <field name="context">{'Followupfirst':True, 'search_default_todo': True, 'search_default_my': True} </field>
+            <field name="search_view_id" ref="customer_followup_search_view"/>
+        </record>
+        <menuitem id="base.menu_sales_followup" parent="base.menu_base_partner" name="Payment Follow-up" groups="account.group_account_invoice" sequence="2"/>
+        <menuitem id="menu_sale_followup" parent="base.menu_sales_followup" sequence="10" 
+                  action="action_customer_my_followup"  groups="account.group_account_invoice"/>
     </data>
 </openerp>
index e93b4dd..456ccb5 100644 (file)
@@ -204,7 +204,7 @@ class account_followup_print(osv.osv_memory):
             if not part.unreconciled_aml_ids: 
                 partners_to_clear.append(part.id)
         self.pool.get('res.partner').action_done(cr, uid, partners_to_clear, context=context)
-        return len(ids)
+        return len(partners_to_clear)
 
     def do_process(self, cr, uid, ids, context=None):
         if context is None: