~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to msf_doc_import/wizard/wiz_common_import.py

  • Committer: Quentin THEURET
  • Date: 2016-03-04 12:15:00 UTC
  • Revision ID: qt@tempo-consulting.fr-20160304121500-u2ay8zrf83ih9fu3
US-826 [IMP] Change the way to check if products is not consistent on add multiple line wizard

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
    }
176
176
 
177
177
    def add_products(self, cr, uid, ids, product_ids, context=None):
 
178
        product_obj = self.pool.get('product.product')
 
179
 
 
180
        if context is None:
 
181
            context = {}
 
182
 
 
183
        if isinstance(ids, (int, long)):
 
184
            ids = [ids]
 
185
 
178
186
        if not product_ids:
179
187
            return {}
180
188
 
181
189
        res = {}
182
 
        for wl in self.browse(cr, uid, ids, context=context):
183
 
            if wl.parent_model in ('tender', 'sale.order', 'purchase.order'):
184
 
                categ = self.pool.get(wl.parent_model).read(cr, uid, wl.parent_id, ['categ'], context=context)['categ']
185
 
                if categ:
186
 
                    not_ok_product_ids = self.pool.get('product.product').search(cr, uid, [
187
 
                        ('id', 'in', product_ids),
188
 
                        ('purchase_type', '=', categ),
189
 
                    ], context=context)
190
 
                    if not_ok_product_ids:
191
 
                        res.update({
192
 
                            'warning': {
193
 
                                'title': _('Warning'),
194
 
                                'message': _('Warning you are about to add a product which does not conform to this PO’s order category, do you wish to proceed ?'),
195
 
                            },
196
 
                        })
 
190
        try:
 
191
            for wl in self.browse(cr, uid, ids, context=context):
 
192
                if wl.parent_model in ('tender', 'sale.order', 'purchase.order'):
 
193
                    categ = self.pool.get(wl.parent_model).read(cr, uid, wl.parent_id, ['categ'], context=context)['categ']
 
194
                    if categ:
 
195
                        for product_id in product_ids[0][2]:
 
196
                            c_msg = product_obj.check_consistency(cr, uid, product_id, categ, context=context)
 
197
                            if c_msg:
 
198
                                res.setdefault('warning', {})
 
199
                                res['warning'].setdefault('title', _('Warning'))
 
200
                                res['warning'].setdefault('message', '')
 
201
                                res['warning']['message'] = '%s \n %s' % (
 
202
                                    res.get('warning', {}).get('message', ''),
 
203
                                    c_msg,
 
204
                                )
 
205
                                return res
 
206
        except IndexError:
 
207
            return {}
197
208
 
198
209
        return res
199
210