[MERGE] trunk
[odoo/odoo.git] / addons / account_anglo_saxon / stock.py
index ad09136..9ddfab8 100644 (file)
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
-from osv import fields,osv
+from osv import osv
 
 #----------------------------------------------------------
 # Stock Picking
 #----------------------------------------------------------
 class stock_picking(osv.osv):
     _inherit = "stock.picking"
-    _description = "Packing List"
+    _description = "Picking List"
 
     def action_invoice_create(self, cr, uid, ids, journal_id=False,
             group=False, type='out_invoice', context=None):
         '''Return ids of created invoices for the pickings'''
-        res = super(stock_picking,self).action_invoice_create(cr, uid, ids, journal_id, group, type, context)
+        res = super(stock_picking,self).action_invoice_create(cr, uid, ids, journal_id, group, type, context=context)
         if type == 'in_refund':
             for inv in self.pool.get('account.invoice').browse(cr, uid, res.values(), context=context):
                 for ol in inv.invoice_line:
@@ -43,6 +43,18 @@ class stock_picking(osv.osv):
                             fpos = ol.invoice_id.fiscal_position or False
                             a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)
                             self.pool.get('account.invoice.line').write(cr, uid, [ol.id], {'account_id': a})
+                            
+        elif type == 'in_invoice':
+            for inv in self.pool.get('account.invoice').browse(cr, uid, res.values(), context=context):
+                for ol in inv.invoice_line:
+                    if ol.product_id:
+                        oa = ol.product_id.product_tmpl_id.property_stock_account_input and ol.product_id.product_tmpl_id.property_stock_account_input.id
+                        if not oa:
+                            oa = ol.product_id.categ_id.property_stock_account_input_categ and ol.product_id.categ_id.property_stock_account_input_categ.id        
+                        if oa:
+                            fpos = ol.invoice_id.fiscal_position or False
+                            a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)
+                            self.pool.get('account.invoice.line').write(cr, uid, [ol.id], {'account_id': a})
         return res
 
 stock_picking()