Merged trunk addons
[odoo/odoo.git] / addons / purchase / purchase.py
index 0c3527b..2e05c1f 100644 (file)
@@ -227,11 +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').property_get(cr, uid,
-                                       part,property_pref=['property_product_pricelist_purchase']).get('property_product_pricelist_purchase',False)
+        part = self.pool.get('res.partner').browse(cr, uid, part)
+        pricelist = part.property_product_pricelist_purchase.id
         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
 
@@ -264,15 +264,15 @@ class purchase_order(osv.osv):
                        })
     def inv_line_create(self,a,ol):
         return (0, False, {
-                    'name': ol.name,
-                    'account_id': a,
-                    'price_unit': ol.price_unit or 0.0,
-                    'quantity': ol.product_qty,
-                    'product_id': ol.product_id.id or False,
-                    'uos_id': ol.product_uom.id or False,
-                    'invoice_line_tax_id': [(6, 0, [x.id for x in ol.taxes_id])],
-                    'account_analytic_id': ol.account_analytic_id.id,
-                })
+            'name': ol.name,
+            'account_id': a,
+            'price_unit': ol.price_unit or 0.0,
+            'quantity': ol.product_qty,
+            'product_id': ol.product_id.id or False,
+            'uos_id': ol.product_uom.id or False,
+            'invoice_line_tax_id': [(6, 0, [x.id for x in ol.taxes_id])],
+            'account_analytic_id': ol.account_analytic_id.id,
+        })
 
     def action_invoice_create(self, cr, uid, ids, *args):
         res = False
@@ -288,17 +288,8 @@ class purchase_order(osv.osv):
                         raise osv.except_osv(_('Error !'), _('There is no expense account defined for this product: "%s" (id:%d)') % (ol.product_id.name, ol.product_id.id,))
                 else:
                     a = self.pool.get('ir.property').get(cr, uid, 'property_account_expense_categ', 'product.category')
+                a = self.pool.get('account.fiscal.position').map_account(cr, uid, o.partner_id, a)
                 il.append(self.inv_line_create(a,ol))
-#               il.append((0, False, {
-#                   'name': ol.name,
-#                   'account_id': a,
-#                   'price_unit': ol.price_unit or 0.0,
-#                   'quantity': ol.product_qty,
-#                   'product_id': ol.product_id.id or False,
-#                   'uos_id': ol.product_uom.id or False,
-#                   'invoice_line_tax_id': [(6, 0, [x.id for x in ol.taxes_id])],
-#                   'account_analytic_id': ol.account_analytic_id.id,
-#               }))
 
             a = o.partner_id.property_account_payable.id
             inv = {
@@ -423,6 +414,7 @@ class purchase_order_line(osv.osv):
             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':'', '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)['lang']
@@ -449,11 +441,10 @@ class purchase_order_line(osv.osv):
         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)                
+            partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
+            taxep = partner.property_account_position and partner.property_account_position.account_supplier_tax
         if not taxep or not taxep.id:
-            res['value']['taxes_id'] = [x.id for x in product.taxes_id]
+            res['value']['taxes_id'] = prod['supplier_taxes_id']
         else:
             res5 = [taxep.id]
             for t in taxes: