From 2e039c3d5c9a58c1c7c003e28f265e796bb300cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 5 Mar 2013 11:48:01 +0100 Subject: [PATCH] [CLEAN] Small code cleaning before merging (context management, coding style). bzr revid: tde@openerp.com-20130305104801-d254qf2it3k22xl5 --- addons/account/account_invoice.py | 1 + addons/purchase/purchase.py | 28 ++++++++----- .../purchase_requisition.py | 4 +- addons/sale/sale.py | 41 ++++++++++--------- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 52bcd29622c..dbe17d1c60a 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1767,6 +1767,7 @@ class mail_compose_message(osv.Model): if context.get('default_model') == 'account.invoice' and context.get('default_res_id') and context.get('mark_invoice_as_sent'): context = dict(context, mail_post_autofollow=True) self.pool.get('account.invoice').write(cr, uid, [context['default_res_id']], {'sent': True}, context=context) + self.pool.get('account.invoice').message_post(cr, uid, [context['default_res_id']], body=_("Invoice sent"), context=context) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 1ae88748c54..1b017f021ad 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -731,6 +731,9 @@ class purchase_order(osv.osv): list_key.sort() return tuple(list_key) + if context is None: + context = {} + # Compute what the new orders should contain new_orders = {} @@ -794,9 +797,7 @@ class purchase_order(osv.osv): order_data['order_line'] = [(0, 0, value) for value in order_data['order_line'].itervalues()] # create the new order - if not context: - context = {} - context.update({ 'mail_create_nolog' : True }) + context.update({'mail_create_nolog': True}) neworder_id = self.create(cr, uid, order_data) self.message_post(cr, uid, [neworder_id], body=_("RFQ created"), context=context) orders_info.update({neworder_id: old_ids}) @@ -1197,19 +1198,24 @@ class mail_compose_message(osv.Model): self.pool.get('purchase.order').signal_send_rfq(cr, uid, [context['default_res_id']]) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context) + class account_invoice(osv.Model): + """ Override account_invoice to add Chatter messages on the related purchase + orders, logging the invoice reception or payment. """ _inherit = 'account.invoice' def invoice_validate(self, cr, uid, ids, context=None): - po_ids = self.pool.get('purchase.order').search(cr,uid,[('invoice_ids','in',ids)],context) - res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=None) - self.pool.get('purchase.order').message_post(cr, uid, po_ids, body=_("Invoice received"), context=context) - return res - + res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=context) + purchase_order_obj = self.pool.get('purchase.order') + po_ids = purchase_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context) + purchase_order_obj.message_post(cr, uid, po_ids, body=_("Invoice received"), context=context) + return res + def confirm_paid(self, cr, uid, ids, context=None): - po_ids = self.pool.get('purchase.order').search(cr,uid,[('invoice_ids','in',ids)],context) - res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=None) - self.pool.get('purchase.order').message_post(cr, uid, po_ids, body=_("Invoice paid"), context=context) + res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context) + purchase_order_obj = self.pool.get('purchase.order') + po_ids = purchase_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context) + purchase_order_obj.message_post(cr, uid, po_ids, body=_("Invoice paid"), context=context) return res diff --git a/addons/purchase_requisition/purchase_requisition.py b/addons/purchase_requisition/purchase_requisition.py index 11c47ff4524..b213f958736 100644 --- a/addons/purchase_requisition/purchase_requisition.py +++ b/addons/purchase_requisition/purchase_requisition.py @@ -132,9 +132,7 @@ class purchase_requisition(osv.osv): if supplier.id in filter(lambda x: x, [rfq.state <> 'cancel' and rfq.partner_id.id or None for rfq in requisition.purchase_ids]): raise osv.except_osv(_('Warning!'), _('You have already one %s purchase order for this partner, you must cancel this purchase order to create a new quotation.') % rfq.state) location_id = requisition.warehouse_id.lot_input_id.id - if not context: - context = {} - context.update({ 'mail_create_nolog' : True }) + context.update({'mail_create_nolog': True}) purchase_id = purchase_order.create(cr, uid, { 'origin': requisition.name, 'partner_id': supplier.id, diff --git a/addons/sale/sale.py b/addons/sale/sale.py index b2657d6c2b0..8f442c8f14e 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -346,12 +346,14 @@ class sale_order(osv.osv): return {'value': val} def create(self, cr, uid, vals, context=None): - if vals.get('name','/')=='/': + if context is None: + context = {} + if vals.get('name', '/') == '/': vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/' - context = dict(context, mail_create_nolog=True) - res = super(sale_order, self).create(cr, uid, vals, context=context) - self.message_post(cr, uid, [res], body=_("Quotation created"), context=context) - return res + context.update({'mail_create_nolog': True}) + new_id = super(sale_order, self).create(cr, uid, vals, context=context) + self.message_post(cr, uid, [new_id], body=_("Quotation created"), context=context) + return new_id def button_dummy(self, cr, uid, ids, context=None): return True @@ -997,38 +999,39 @@ class res_company(osv.Model): 'sale_note': fields.text('Default Terms and Conditions', translate=True, help="Default terms and conditions for quotations."), } + class mail_compose_message(osv.Model): _inherit = 'mail.compose.message' def send_mail(self, cr, uid, ids, context=None): context = context or {} - if context.get('mark_invoice_as_sent'): - self.pool.get('account.invoice').message_post(cr, uid,[context['default_res_id']], body=_("Invoice sent"), context=context) if context.get('default_model') == 'sale.order' and context.get('default_res_id') and context.get('mark_so_as_sent'): context = dict(context, mail_post_autofollow=True) self.pool.get('sale.order').signal_quotation_sent(cr, uid, [context['default_res_id']]) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context) + class account_invoice(osv.Model): _inherit = 'account.invoice' - + def confirm_paid(self, cr, uid, ids, context=None): - so_ids = self.pool.get('sale.order').search(cr,uid,[('invoice_ids','in',ids)],context) - res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=None) - self.pool.get('sale.order').message_post(cr, uid, so_ids, body=_("Invoice paid"), context=context) + sale_order_obj = self.pool.get('sale.order') + res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context) + so_ids = sale_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context) + sale_order_obj.message_post(cr, uid, so_ids, body=_("Invoice paid"), context=context) return res + + class stock_picking(osv.osv): _inherit = 'stock.picking' - + def action_done(self, cr, uid, ids, context=None): - """Changes picking state to done. - - This method is called at the end of the workflow by the activity "done". - @return: True + """ Changes picking state to done. This method is called at the end of + the workflow by the activity "done". """ for record in self.browse(cr, uid, ids, context): if record.type == "out" and record.sale_id: - self.pool.get('sale.order').message_post(cr, uid, [record.sale_id.id],body=_("Products delivered"), context=context) - return super(stock_picking, self).action_done(cr, uid, ids, context=None) - + self.pool.get('sale.order').message_post(cr, uid, [record.sale_id.id], body=_("Products delivered"), context=context) + return super(stock_picking, self).action_done(cr, uid, ids, context=context) + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: