define roles in process wherever necessary
[odoo/odoo.git] / addons / purchase / purchase.py
index 211abfe..440bc38 100644 (file)
@@ -86,6 +86,18 @@ class purchase_order(osv.osv):
             res[id] = cur_obj.round(cr, uid, cur, untax.get(id, 0.0) + tax.get(id, 0.0))
         return res
 
+    def _set_minimum_planned_date(self, cr, uid, ids, name, value, arg, context):
+        if not value: return False
+        if type(ids)!=type([]):
+            ids=[ids]
+        for po in self.browse(cr, uid, ids, context):
+            cr.execute("""update purchase_order_line set
+                    date_planned=%s
+                where
+                    order_id=%d and
+                    (date_planned=%s or date_planned<%s)""", (value,po.id,po.minimum_planned_date,value))
+        return True
+
     def _minimum_planned_date(self, cr, uid, ids, field_name, arg, context):
         res={}
         purchase_obj=self.browse(cr, uid, ids, context=context)
@@ -142,14 +154,19 @@ class purchase_order(osv.osv):
 
     _columns = {
         'name': fields.char('Order Reference', size=64, required=True, select=True),
-        'origin': fields.char('Origin', size=64),
+        'origin': fields.char('Origin', size=64, 
+            help="Reference of the document that generated this purchase order request."
+        ),
         'partner_ref': fields.char('Partner Ref.', size=64),
         'date_order':fields.date('Date Ordered', required=True, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)]}),
-        'date_approve':fields.date('Date Approved'),
+        'date_approve':fields.date('Date Approved', readonly=1),
         'partner_id':fields.many2one('res.partner', 'Supplier', required=True, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)]}, change_default=True),
         'partner_address_id':fields.many2one('res.partner.address', 'Address', required=True, states={'posted':[('readonly',True)]}),
 
-        'dest_address_id':fields.many2one('res.partner.address', 'Destination Address', states={'posted':[('readonly',True)]}),
+        'dest_address_id':fields.many2one('res.partner.address', 'Destination Address', states={'posted':[('readonly',True)]},
+            help="Put an address if you want to deliver directly from the supplier to the customer." \
+                "In this case, it will remove the warehouse link and set the customer location."
+        ),
         'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', states={'posted':[('readonly',True)]}),
         'location_id': fields.many2one('stock.location', 'Destination', required=True),
 
@@ -165,8 +182,13 @@ class purchase_order(osv.osv):
         'shipped_rate': fields.function(_shipped_rate, method=True, string='Received', type='float'),
         'invoiced':fields.boolean('Invoiced & Paid', readonly=True, select=True),
         'invoiced_rate': fields.function(_invoiced_rate, method=True, string='Invoiced', type='float'),
-        'invoice_method': fields.selection([('manual','Manual'),('order','From order'),('picking','From picking')], 'Invoicing Control', required=True),
-        'minimum_planned_date':fields.function(_minimum_planned_date, method=True,store=True, string='Planned Date', type='date', help="This is computed as the minimum scheduled date of all purchase order lines' products."),
+        'invoice_method': fields.selection([('manual','Manual'),('order','From Order'),('picking','From Picking')], 'Invoicing Control', required=True,
+            help="From Order: a draft invoice will be pre-generated based on the purchase order. The accountant " \
+                "will just have to validate this invoice for control.\n" \
+                "From Picking: a draft invoice will be pre-genearted based on validated receptions.\n" \
+                "Manual: no invoice will be pre-generated. The accountant will have to encode manually."
+        ),
+        'minimum_planned_date':fields.function(_minimum_planned_date, fnct_inv=_set_minimum_planned_date, method=True,store=True, string='Planned Date', type='datetime', help="This is computed as the minimum scheduled date of all purchase order lines' products."),
         'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
         'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
         'amount_total': fields.function(_amount_total, method=True, string='Total'),
@@ -205,10 +227,11 @@ class purchase_order(osv.osv):
         if not part:
             return {'value':{'partner_address_id': False}}
         addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['default'])
-        pricelist = self.pool.get('res.partner').browse(cr, uid, part).property_product_pricelist_purchase.id
+        pricelist = self.pool.get('res.partner').property_get(cr, uid,
+                    part,property_pref=['property_product_pricelist_purchase']).get('property_product_pricelist_purchase',False)
         return {'value':{'partner_address_id': addr['default'], 'pricelist_id': pricelist}}
 
-    def wkf_approve_order(self, cr, uid, ids):
+    def wkf_approve_order(self, cr, uid, ids, context={}):
         self.write(cr, uid, ids, {'state': 'approved', 'date_approve': time.strftime('%Y-%m-%d')})
         return True
 
@@ -399,13 +422,14 @@ class purchase_order_line(osv.osv):
         if not pricelist:
             raise osv.except_osv(_('No Pricelist !'), _('You have to select a pricelist in the purchase form !\nPlease set one before choosing a product.'))
         if not product:
-            return {'value': {'price_unit': 0.0, 'name':'','notes':''}, 'domain':{'product_uom':[]}}
+            return {'value': {'price_unit': 0.0, 'name':'','notes':'', 'product_uom' : False}, 'domain':{'product_uom':[]}}
+        prod= self.pool.get('product.product').browse(cr, uid,product)
         lang=False
         if partner_id:
-            lang=self.pool.get('res.partner').read(cr, uid, [partner_id])[0]['lang']
+            lang=self.pool.get('res.partner').read(cr, uid, partner_id)['lang']
         context={'lang':lang}
 
-        prod = self.pool.get('product.product').read(cr, uid, [product], ['supplier_taxes_id','name','seller_delay','uom_po_id','description_purchase'])[0]
+        prod = self.pool.get('product.product').read(cr, uid, product, ['supplier_taxes_id','name','seller_delay','uom_po_id','description_purchase'],context=context)
         prod_uom_po = prod['uom_po_id'][0]
         if not uom:
             uom = prod_uom_po
@@ -422,21 +446,21 @@ class purchase_order_line(osv.osv):
         res = {'value': {'price_unit': price, 'name':prod_name, 'taxes_id':prod['supplier_taxes_id'], 'date_planned': dt,'notes':prod['description_purchase'], 'product_uom': uom}}
         domain = {}
 
-        if res['value']['taxes_id']:
-            taxes = self.pool.get('account.tax').browse(cr, uid,
-                    [x.id for x in product.supplier_taxes_id])
-            taxep = None
-            if partner_id:
-                taxep = self.pool.get('res.partner').browse(cr, uid,
-                        partner_id).property_account_supplier_tax
-            if not taxep or not taxep.id:
-                res['value']['taxes_id'] = [x.id for x in product.taxes_id]
-            else:
-                res5 = [taxep.id]
-                for t in taxes:
-                    if not t.tax_group==taxep.tax_group:
-                        res5.append(t.id)
-                res['value']['taxes_id'] = res5
+        
+        taxes = self.pool.get('account.tax').browse(cr, uid,prod['supplier_taxes_id'])
+        taxep = None
+        if partner_id:
+            taxep_id = self.pool.get('res.partner').property_get(cr, uid,partner_id,property_pref=['property_account_supplier_tax']).get('property_account_supplier_tax',False)
+            if taxep_id:
+                taxep=self.pool.get('account.tax').browse(cr, uid,taxep_id)
+        if not taxep or not taxep.id:
+            res['value']['taxes_id'] = [x.id for x in prod['supplier_taxes_id']]
+        else:
+            res5 = [taxep.id]
+            for t in taxes:
+                if not t.tax_group==taxep.tax_group:
+                    res5.append(t.id)
+            res['value']['taxes_id'] = res5
 
         res2 = self.pool.get('product.uom').read(cr, uid, [uom], ['category_id'])
         res3 = self.pool.get('product.uom').read(cr, uid, [prod_uom_po], ['category_id'])