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

« back to all changes in this revision

Viewing changes to sale_override/sale.py

  • Committer: jf
  • Date: 2014-01-14 15:51:27 UTC
  • mfrom: (1789.6.50 unifield-wm)
  • Revision ID: jfb@tempo-consulting.fr-20140114155127-xrgj0ex1kq1wyxzj
UTP-101 [IMP] Product Selection Wizards
lp:~unifield-team/unifield-wm/utp-101

Show diffs side-by-side

added added

removed removed

Lines of Context:
282
282
        'no_line': lambda *a: True,
283
283
    }
284
284
 
 
285
    def _check_empty_line(self, cr, uid, ids, context=None):
 
286
        '''
 
287
        Check if all lines have a quantity larger than 0.00
 
288
        '''
 
289
        issue_ids = []
 
290
        for order in self.read(cr, uid, ids, ['state'], context=context):
 
291
            if order['state'] not in ['draft', 'cancel']:
 
292
                issue_ids.append(order['id'])
 
293
 
 
294
        line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', 'in', issue_ids),
 
295
                                                                     ('product_uom_qty', '=', 0.00)], context=context)
 
296
 
 
297
        if line_ids:
 
298
            return False
 
299
 
 
300
        return True
 
301
 
 
302
    _constraints = [
 
303
        (_check_empty_line, 'All lines must have a quantity larger than 0.00', ['order_line']),
 
304
    ]
 
305
 
285
306
    def _check_own_company(self, cr, uid, company_id, context=None):
286
307
        '''
287
308
        Remove the possibility to make a SO to user's company
1634
1655
        
1635
1656
        return super(sale_order_line, self).copy(cr, uid, id, default, context)
1636
1657
 
 
1658
    def check_empty_line(self, cr, uid, ids, vals, context=None):               
 
1659
        '''                                                                     
 
1660
        Return an error if the line has no qty                                  
 
1661
        '''                                                                     
 
1662
        context = context is None and {} or context                                                                                                                                                                         
 
1663
        if not context.get('noraise') and not context.get('import_in_progress'):
 
1664
            if ids and not 'product_uom_qty' in vals:                              
 
1665
                for line in self.read(cr, uid, ids, ['product_uom_qty'], context=context):
 
1666
                    if line['product_uom_qty'] <= 0.00:                            
 
1667
                        raise osv.except_osv(_('Error'), _('A line must a have a quantity larger than 0.00'))
 
1668
                    elif 'product_uom_qty' in vals and vals.get('product_uom_qty') == 0.00:
 
1669
                        raise osv.except_osv(_('Error'), _('A line must a have a quantity larger than 0.00'))
 
1670
                    
 
1671
        return True                                                                
 
1672
 
1637
1673
    def create(self, cr, uid, vals, context=None):
1638
1674
        """
1639
1675
        Override create method so that the procurement method is on order if no product is selected
1643
1679
            context = {}
1644
1680
        if not vals.get('product_id') and context.get('sale_id', []):
1645
1681
            vals.update({'type': 'make_to_order'})
 
1682
 
 
1683
        self.check_empty_line(cr, uid, False, vals, context=context)
1646
1684
        
1647
1685
        # UF-1739: as we do not have product_uos_qty in PO (only in FO), we recompute here the product_uos_qty for the SYNCHRO
1648
1686
        qty = vals.get('product_uom_qty')
1690
1728
        if order_id and self.pool.get('sale.order').read(cr, uid, order_id,['procurement_request'], context)['procurement_request']:
1691
1729
            vals.update({'cost_price': vals.get('cost_price', False)})
1692
1730
 
 
1731
        self.check_empty_line(cr, uid, ids, vals, context=context)
 
1732
 
1693
1733
        res = super(sale_order_line, self).write(cr, uid, ids, vals, context=context)
1694
1734
 
1695
1735
        return res