[REF] sale: removed some chatter messages, replaced by a track on state and amount...
authorThibault Delavallée <tde@openerp.com>
Tue, 18 Dec 2012 18:17:18 +0000 (19:17 +0100)
committerThibault Delavallée <tde@openerp.com>
Tue, 18 Dec 2012 18:17:18 +0000 (19:17 +0100)
bzr revid: tde@openerp.com-20121218181718-zw3d4lmau83bhk7v

addons/sale/sale.py
addons/sale/sale_data.xml
addons/sale_crm/__openerp__.py
addons/sale_crm/sale_crm.py
addons/sale_crm/sale_crm_data.xml [new file with mode: 0644]

index f564096..27e52cb 100644 (file)
@@ -50,6 +50,12 @@ class sale_order(osv.osv):
     _inherit = ['mail.thread', 'ir.needaction_mixin']
     _description = "Sales Order"
 
+    _track = {
+        'state': {
+            'sale.mt_order_confirmed': lambda self, cr, uid, obj, ctx=None: obj.state in ['manual', 'progress']
+        },
+    }
+
     def onchange_shop_id(self, cr, uid, ids, shop_id, context=None):
         v = {}
         if shop_id:
@@ -187,7 +193,8 @@ class sale_order(osv.osv):
             ('manual', 'Sale to Invoice'),
             ('invoice_except', 'Invoice Exception'),
             ('done', 'Done'),
-            ], 'Status', readonly=True, tracked=True, help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sale order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
+            ], 'Status', readonly=True, track_visibility=1,
+            help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sale order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
         'date_order': fields.date('Date', required=True, readonly=True, select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
         'create_date': fields.datetime('Creation Date', readonly=True, select=True, help="Date on which sales order is created."),
         'date_confirm': fields.date('Confirmation Date', readonly=True, select=True, help="Date on which sales order is confirmed."),
@@ -213,24 +220,24 @@ class sale_order(osv.osv):
             fnct_search=_invoiced_search, type='boolean', help="It indicates that sale order has at least one invoice."),
         'note': fields.text('Terms and conditions'),
 
-        'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
-            store = {
+        'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Untaxed Amount',
+            store={
                 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                 'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
             },
             multi='sums', help="The amount without tax."),
-        'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
-            store = {
+        'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes',
+            store={
                 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                 'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
             },
             multi='sums', help="The tax amount."),
-        'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
-            store = {
+        'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total',
+            store={
                 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                 'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
             },
-            multi='sums', help="The total amount."),
+            multi='sums', track_visibility=2, help="The total amount."),
 
         'invoice_quantity': fields.selection([('order', 'Ordered Quantities')], 'Invoice on', help="The sale order will automatically create the invoice proposition (draft invoice).", required=True, readonly=True, states={'draft': [('readonly', False)]}),
         'payment_term': fields.many2one('account.payment.term', 'Payment Term'),
@@ -323,10 +330,7 @@ class sale_order(osv.osv):
     def create(self, cr, uid, vals, context=None):
         if vals.get('name','/')=='/':
             vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/'
-        order =  super(sale_order, self).create(cr, uid, vals, context=context)
-        if order:
-            self.create_send_note(cr, uid, [order], context=context)
-        return order
+        return super(sale_order, self).create(cr, uid, vals, context=context)
 
     def button_dummy(self, cr, uid, ids, context=None):
         return True
@@ -561,7 +565,6 @@ class sale_order(osv.osv):
                     wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr)
             sale_order_line_obj.write(cr, uid, [l.id for l in  sale.order_line],
                     {'state': 'cancel'})
-            self.cancel_send_note(cr, uid, [sale.id], context=None)
         self.write(cr, uid, ids, {'state': 'cancel'})
         return True
 
@@ -596,7 +599,6 @@ class sale_order(osv.osv):
             else:
                 self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)})
             self.pool.get('sale.order.line').button_confirm(cr, uid, [x.id for x in o.order_line])
-            self.confirm_send_note(cr, uid, ids, context)
         return True
 
     def action_quotation_send(self, cr, uid, ids, context=None):
@@ -634,7 +636,6 @@ class sale_order(osv.osv):
         }
 
     def action_done(self, cr, uid, ids, context=None):
-        self.done_send_note(cr, uid, ids, context=context)
         return self.write(cr, uid, ids, {'state': 'done'}, context=context)
 
     # ------------------------------------------------
@@ -642,23 +643,7 @@ class sale_order(osv.osv):
     # ------------------------------------------------
 
     def needaction_domain_get(self, cr, uid, ids, context=None):
-        return [('state', '=', 'draft'), ('user_id','=',uid)]
-
-    def create_send_note(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_post(cr, uid, [obj.id], body=_("Quotation for <em>%s</em> <b>created</b>.") % (obj.partner_id.name), context=context)
-
-    def confirm_send_note(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_post(cr, uid, [obj.id], body=_("Quotation for <em>%s</em> <b>converted</b> to Sale Order of %s %s.") % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), subtype="sale.mt_order_confirmed", context=context)
-
-    def cancel_send_note(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_post(cr, uid, [obj.id], body=_("Sale Order for <em>%s</em> <b>cancelled</b>.") % (obj.partner_id.name), context=context)
-
-    def done_send_note(self, cr, uid, ids, context=None):
-        for obj in self.browse(cr, uid, ids, context=context):
-            self.message_post(cr, uid, [obj.id], body=_("Sale Order for <em>%s</em> set to <b>Done</b>") % (obj.partner_id.name), context=context)
+        return [('state', '=', 'draft'), ('user_id', '=', uid)]
 
     def invoice_paid_send_note(self, cr, uid, ids, context=None):
         self.message_post(cr, uid, ids, body=_("Invoice <b>paid</b>."), context=context)
index 3346540..4a08063 100644 (file)
         <record id="mt_quotation_sent" model="mail.message.subtype">
             <field name="name">Quotation sent</field>
             <field name="res_model">sale.order</field>
+            <field name="description">Quotation &lt;b&gt;send&lt;/b&gt;</field>
         </record>
         <record id="mt_order_confirmed" model="mail.message.subtype">
             <field name="name">Sale Order Confirmed</field>
             <field name="res_model">sale.order</field>
-        </record>
-
-        <!-- Salesteam-related subtypes for messaging / Chatter -->
-        <record id="mt_salesteam_sent" model="mail.message.subtype">
-            <field name="name">Quotation sent</field>
-            <field name="res_model">crm.case.section</field>
-            <field name="default" eval="False"/>
-        </record>
-        <record id="mt_salesteam_confirmed" model="mail.message.subtype">
-            <field name="name">Sale Order Confirmed</field>
-            <field name="res_model">crm.case.section</field>
-            <field name="default" eval="False"/>
+            <field name="description">Quotation &lt;b&gt;confirmed&lt;/b&gt;</field>
         </record>
 
     </data>
index 4ef6b60..6591589 100644 (file)
@@ -41,6 +41,7 @@ modules.
     'data': [
         'wizard/crm_make_sale_view.xml',
         'sale_crm_view.xml',
+        'sale_crm_data.xml',
         'process/sale_crm_process.xml',
         'security/sale_crm_security.xml',
         'security/ir.model.access.csv',
index 927b89b..75799da 100644 (file)
@@ -29,15 +29,8 @@ class sale_order(osv.osv):
             domain="['|',('section_id','=',section_id),('section_id','=',False), ('object_id.model', '=', 'crm.lead')]")
     }
 
-    def create(self, cr, uid, vals, context=None):
-        order =  super(sale_order, self).create(cr, uid, vals, context=context)
-        section_id = self.browse(cr, uid, order, context=context).section_id
-        if section_id:
-            # subscribe salesteam followers & subtypes to the sale order
-            self._subscribe_followers_subtype(cr, uid, [order], section_id, 'crm.case.section', context=context)
-        return order
-
     def write(self, cr, uid, ids, vals, context=None):
+        # TDE todo: will be replaced by automatic in mail.thread
         if vals.get('section_id'):
             section_id = self.pool.get('crm.case.section').browse(cr, uid, vals.get('section_id'), context=context)
             vals['message_follower_ids'] = [(6, 0, [follower.id]) for follower in section_id.message_follower_ids]
diff --git a/addons/sale_crm/sale_crm_data.xml b/addons/sale_crm/sale_crm_data.xml
new file mode 100644 (file)
index 0000000..4a57a9d
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data noupdate="1">
+
+        <!-- Salesteam-related subtypes for messaging / Chatter -->
+        <record id="mt_salesteam_sent" model="mail.message.subtype">
+            <field name="name">Quotation sent</field>
+            <field name="res_model">crm.case.section</field>
+            <field name="parent_id" eval="ref('sale.mt_quotation_sent')"/>
+            <field name="parent_field">section_id</field>
+        </record>
+        <record id="mt_salesteam_confirmed" model="mail.message.subtype">
+            <field name="name">Sale Order Confirmed</field>
+            <field name="res_model">crm.case.section</field>
+            <field name="parent_id" eval="ref('sale.mt_order_confirmed')"/>
+            <field name="parent_field">section_id</field>
+        </record>
+
+    </data>
+</openerp>