From: Martin Trigaux Date: Fri, 4 Oct 2013 14:06:02 +0000 (+0200) Subject: [FIX] purchase: reduce the number of mail messages sent to when procurement in exception X-Git-Tag: InsPy_master01~464^2~337^2~10 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=dbac14474fd41c094a0aacf5e39f1915d9661e9b;hp=c536c5a432186114c507880cff58eb493dcb130f;p=odoo%2Fodoo.git [FIX] purchase: reduce the number of mail messages sent to when procurement in exception lp bug: https://launchpad.net/bugs/1233730 fixed bzr revid: mat@openerp.com-20131004140602-8gic5ojgadso5801 --- diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index f4a28bc..3a15861 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1035,28 +1035,27 @@ class procurement_order(osv.osv): partner_obj = self.pool.get('res.partner') user = self.pool.get('res.users').browse(cr, uid, uid, context=context) for procurement in self.browse(cr, uid, ids, context=context): - if not procurement.product_id.seller_ids: - message = _('No supplier defined for this product !') - self.message_post(cr, uid, [procurement.id], body=message) - cr.execute('update procurement_order set message=%s where id=%s', (message, procurement.id)) - return False + message = '' partner = procurement.product_id.seller_id #Taken Main Supplier of Product of Procurement. - if not partner: + if not procurement.product_id.seller_ids: + message = _('No supplier defined for this product !') + elif not partner: message = _('No default supplier defined for this product') - self.message_post(cr, uid, [procurement.id], body=message) - cr.execute('update procurement_order set message=%s where id=%s', (message, procurement.id)) + elif not partner_obj.address_get(cr, uid, [partner.id], ['delivery'])['delivery']: + message = _('No address defined for the supplier') + + if message: + if procurement.message != message: + # avoid sending too many messages + self.message_post(cr, uid, [procurement.id], body=message) + self.write(cr, uid, [procurement.id], {'message':message}, context=context) return False + if user.company_id and user.company_id.partner_id: if partner.id == user.company_id.partner_id.id: raise osv.except_osv(_('Configuration Error!'), _('The product "%s" has been defined with your company as reseller which seems to be a configuration error!' % procurement.product_id.name)) - address_id = partner_obj.address_get(cr, uid, [partner.id], ['delivery'])['delivery'] - if not address_id: - message = _('No address defined for the supplier') - self.message_post(cr, uid, [procurement.id], body=message) - cr.execute('update procurement_order set message=%s where id=%s', (message, procurement.id)) - return False return True