[CLEAN] Small code cleaning before merging (context management, coding style).

bzr revid: tde@openerp.com-20130305104801-d254qf2it3k22xl5
This commit is contained in:
Thibault Delavallée 2013-03-05 11:48:01 +01:00
parent 1a147be814
commit 2e039c3d5c
4 changed files with 41 additions and 33 deletions

View File

@ -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'): 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) 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').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) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -731,6 +731,9 @@ class purchase_order(osv.osv):
list_key.sort() list_key.sort()
return tuple(list_key) return tuple(list_key)
if context is None:
context = {}
# Compute what the new orders should contain # Compute what the new orders should contain
new_orders = {} 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()] order_data['order_line'] = [(0, 0, value) for value in order_data['order_line'].itervalues()]
# create the new order # create the new order
if not context: context.update({'mail_create_nolog': True})
context = {}
context.update({ 'mail_create_nolog' : True })
neworder_id = self.create(cr, uid, order_data) neworder_id = self.create(cr, uid, order_data)
self.message_post(cr, uid, [neworder_id], body=_("RFQ created"), context=context) self.message_post(cr, uid, [neworder_id], body=_("RFQ created"), context=context)
orders_info.update({neworder_id: old_ids}) 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']]) 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) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
class account_invoice(osv.Model): 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' _inherit = 'account.invoice'
def invoice_validate(self, cr, uid, ids, context=None): 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=context)
res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=None) purchase_order_obj = self.pool.get('purchase.order')
self.pool.get('purchase.order').message_post(cr, uid, po_ids, body=_("Invoice received"), context=context) po_ids = purchase_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context)
return res 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): 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=context)
res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=None) purchase_order_obj = self.pool.get('purchase.order')
self.pool.get('purchase.order').message_post(cr, uid, po_ids, body=_("Invoice paid"), context=context) 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 return res

View File

@ -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]): 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) 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 location_id = requisition.warehouse_id.lot_input_id.id
if not context: context.update({'mail_create_nolog': True})
context = {}
context.update({ 'mail_create_nolog' : True })
purchase_id = purchase_order.create(cr, uid, { purchase_id = purchase_order.create(cr, uid, {
'origin': requisition.name, 'origin': requisition.name,
'partner_id': supplier.id, 'partner_id': supplier.id,

View File

@ -346,12 +346,14 @@ class sale_order(osv.osv):
return {'value': val} return {'value': val}
def create(self, cr, uid, vals, context=None): 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 '/' vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/'
context = dict(context, mail_create_nolog=True) context.update({'mail_create_nolog': True})
res = super(sale_order, self).create(cr, uid, vals, context=context) new_id = super(sale_order, self).create(cr, uid, vals, context=context)
self.message_post(cr, uid, [res], body=_("Quotation created"), context=context) self.message_post(cr, uid, [new_id], body=_("Quotation created"), context=context)
return res return new_id
def button_dummy(self, cr, uid, ids, context=None): def button_dummy(self, cr, uid, ids, context=None):
return True 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."), 'sale_note': fields.text('Default Terms and Conditions', translate=True, help="Default terms and conditions for quotations."),
} }
class mail_compose_message(osv.Model): class mail_compose_message(osv.Model):
_inherit = 'mail.compose.message' _inherit = 'mail.compose.message'
def send_mail(self, cr, uid, ids, context=None): def send_mail(self, cr, uid, ids, context=None):
context = context or {} 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'): 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) context = dict(context, mail_post_autofollow=True)
self.pool.get('sale.order').signal_quotation_sent(cr, uid, [context['default_res_id']]) 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) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
class account_invoice(osv.Model): class account_invoice(osv.Model):
_inherit = 'account.invoice' _inherit = 'account.invoice'
def confirm_paid(self, cr, uid, ids, context=None): def confirm_paid(self, cr, uid, ids, context=None):
so_ids = self.pool.get('sale.order').search(cr,uid,[('invoice_ids','in',ids)],context) sale_order_obj = self.pool.get('sale.order')
res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=None) res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context)
self.pool.get('sale.order').message_post(cr, uid, so_ids, body=_("Invoice paid"), 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 return res
class stock_picking(osv.osv): class stock_picking(osv.osv):
_inherit = 'stock.picking' _inherit = 'stock.picking'
def action_done(self, cr, uid, ids, context=None): def action_done(self, cr, uid, ids, context=None):
"""Changes picking state to done. """ Changes picking state to done. This method is called at the end of
the workflow by the activity "done".
This method is called at the end of the workflow by the activity "done".
@return: True
""" """
for record in self.browse(cr, uid, ids, context): for record in self.browse(cr, uid, ids, context):
if record.type == "out" and record.sale_id: 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) 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) return super(stock_picking, self).action_done(cr, uid, ids, context=context)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: