From 759cead4822c4b51cf4cf9e42b4a65a79f9ab167 Mon Sep 17 00:00:00 2001
From: "mra (Open ERP)" <mra@tinyerp.com>
Date: Wed, 11 Feb 2009 19:02:54 +0530
Subject: [PATCH] fix bug number : 327990 for fiscal position added at the time
 of creating invoice from sale,purchase,and other modules

bzr revid: mra@tinyerp.com-20090211133254-xnp20b9tsbo28v35
---
 addons/event/wizard/make_invoice.py                    |  1 +
 addons/hr_expense/hr_expense.py                        |  3 ++-
 .../wizard/hr_timesheet_final_invoice_create.py        |  1 +
 .../wizard/hr_timesheet_invoice_create.py              |  5 +++--
 addons/membership/membership.py                        | 10 +++++-----
 addons/membership/wizard/invoice_membership.py         |  3 ++-
 addons/mrp_repair/mrp_repair.py                        |  1 +
 addons/purchase/purchase.py                            |  3 ++-
 addons/sale/sale.py                                    |  1 +
 addons/sale/wizard/make_invoice_advance.py             |  1 +
 addons/sale/wizard/wizard_sale_line_invoice.py         |  3 ++-
 addons/stock/stock.py                                  |  9 +++++----
 12 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/addons/event/wizard/make_invoice.py b/addons/event/wizard/make_invoice.py
index 26118edd15b0..c41a0748b555 100644
--- a/addons/event/wizard/make_invoice.py
+++ b/addons/event/wizard/make_invoice.py
@@ -113,6 +113,7 @@ def _makeInvoices(self, cr, uid, data, context):
             'currency_id' :reg.partner_invoice_id.property_product_pricelist.currency_id.id,
             'comment': "",
             'payment_term':reg.partner_invoice_id.property_payment_term.id,
+            'fiscal_position': reg.partner_invoice_id.property_account_position.id
         }
 
         inv_obj = pool_obj.get('account.invoice')
diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py
index dd427fe59845..e7129cf00d5d 100644
--- a/addons/hr_expense/hr_expense.py
+++ b/addons/hr_expense/hr_expense.py
@@ -1,7 +1,7 @@
 # -*- encoding: utf-8 -*-
 ##############################################################################
 #
-#    OpenERP, Open Source Management Solution	
+#    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 #    $Id$
 #
@@ -152,6 +152,7 @@ class hr_expense_expense(osv.osv):
                 'price_type': 'tax_included',
                 'currency_id': exp.currency_id.id,
                 'payment_term': payment_term_id,
+                'fiscal_position': exp.employee_id.address_id.partner_id.property_account_position.id
             }
             if payment_term_id:
                 to_update = invoice_obj.onchange_payment_term_date_invoice(cr, uid, [],
diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py
index fb97b1a0b3cb..742895d78e4d 100644
--- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py
+++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py
@@ -71,6 +71,7 @@ class final_invoice_create(wizard.interface):
                 'account_id': partner.property_account_receivable.id,
                 'currency_id': account.pricelist_id.currency_id.id,
                 'date_due': date_due,
+                'fiscal_position': account.partner_id.property_account_position.id
             }
             last_invoice = pool.get('account.invoice').create(cr, uid, curr_invoice)
             invoices.append(last_invoice)
diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py
index 0d2c7120503f..a568f7118744 100644
--- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py
+++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py
@@ -79,6 +79,7 @@ class invoice_create(wizard.interface):
                 'account_id': partner.property_account_receivable.id,
                 'currency_id': account.pricelist_id.currency_id.id,
                 'date_due': date_due,
+                'fiscal_position': account.partner_id.property_account_position.id
             }
             last_invoice = pool.get('account.invoice').create(cr, uid, curr_invoice)
             invoices.append(last_invoice)
@@ -129,11 +130,11 @@ class invoice_create(wizard.interface):
                 # Compute for lines
                 #
                 cr.execute("SELECT * "  # TODO optimize this
-                           "  FROM account_analytic_line" 
+                           "  FROM account_analytic_line"
                            " WHERE account_id=%%s"
                            "   AND id IN (%s)"
                            "   AND product_id=%%s"
-                           "   AND to_invoice=%%s" % ','.join(['%s']*len(data['ids'])), 
+                           "   AND to_invoice=%%s" % ','.join(['%s']*len(data['ids'])),
                            (account.id, data['ids'], product_id, factor_id))
                 line_ids = cr.dictfetchall()
                 note = []
diff --git a/addons/membership/membership.py b/addons/membership/membership.py
index c34ed55126e2..5c288ed5c985 100644
--- a/addons/membership/membership.py
+++ b/addons/membership/membership.py
@@ -364,10 +364,10 @@ class Partner(osv.osv):
         'member_lines': fields.one2many('membership.membership_line', 'partner', 'Membership'),
         'free_member': fields.boolean('Free member'),
         'membership_amount': fields.float(
-                    'Membership amount', digites=(16, 2), 
+                    'Membership amount', digites=(16, 2),
                     help='The price negociated by the partner'),
         'membership_state': fields.function(
-                    _membership_state, method = True, 
+                    _membership_state, method = True,
                     string = 'Current membership state', type = 'selection',
                     selection = STATE ,store = {
                         'account.invoice':(_get_invoice_partner,['state'], 10),
@@ -385,8 +385,8 @@ class Partner(osv.osv):
                         }
                     ),
         'membership_stop': fields.function(
-                    _membership_stop, method = True, 
-                    string = 'Stop membership date', type = 'date', 
+                    _membership_stop, method = True,
+                    string = 'Stop membership date', type = 'date',
                     store = {
                         'account.invoice':(_get_invoice_partner,['state'], 10),
                         'membership.membership_line':(_get_partner_id,['state'], 10),
@@ -760,7 +760,7 @@ class account_invoice_line(osv.osv):
             if line.invoice_id.date_invoice > date_from and line.invoice_id.date_invoice < date_to:
                 date_from = line.invoice_id.date_invoice
             line_id = member_line_obj.create(cr, uid, {
-                'partner': line.invoice_id.partner_id.id,
+                'partner': line.invoice_id.partner_id and line.invoice_id.partner_id.id or False,
                 'date_from': date_from,
                 'date_to': date_to,
                 'account_invoice_line': line.id,
diff --git a/addons/membership/wizard/invoice_membership.py b/addons/membership/wizard/invoice_membership.py
index 02da0deeee44..1321bb384915 100644
--- a/addons/membership/wizard/invoice_membership.py
+++ b/addons/membership/wizard/invoice_membership.py
@@ -78,7 +78,8 @@ def _invoice_membership(self, cr, uid, data, context):
             'partner_id' : partner_id,
             'address_invoice_id': partner_address_ids[partner_id]['id'],
             'account_id': account_id,
-            'invoice_line':[(6,0,[invoice_line_id])]
+            'invoice_line':[(6,0,[invoice_line_id])],
+            'fiscal_position': fpos_id or False
             }
         )
         invoice_list.append(invoice_id)
diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py
index eb9fe390bd9b..985af84118f4 100644
--- a/addons/mrp_repair/mrp_repair.py
+++ b/addons/mrp_repair/mrp_repair.py
@@ -281,6 +281,7 @@ class mrp_repair(osv.osv):
                         'address_invoice_id': repair.address_id.id,
                         'currency_id': repair.pricelist_id.currency_id.id,
                         'comment': repair.quotation_notes,
+                        'fiscal_position': repair.partner_id.property_account_position.id
                     }
                     inv_obj = self.pool.get('account.invoice')
                     inv_id = inv_obj.create(cr, uid, inv)
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index 63051813ec01..8ba37697c8fe 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -306,7 +306,7 @@ class purchase_order(osv.osv):
                 a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
                 il.append(self.inv_line_create(a,ol))
 
-            a = o.partner_id.property_account_payable.id            
+            a = o.partner_id.property_account_payable.id
             journal_ids = journal_obj.search(cr, uid, [('type', '=','purchase')], limit=1)
             inv = {
                 'name': o.partner_ref or o.name,
@@ -320,6 +320,7 @@ class purchase_order(osv.osv):
                 'journal_id': len(journal_ids) and journal_ids[0] or False,
                 'origin': o.name,
                 'invoice_line': il,
+                'fiscal_position': o.partner_id.property_account_position.id
             }
             inv_id = self.pool.get('account.invoice').create(cr, uid, inv, {'type':'in_invoice'})
             self.pool.get('account.invoice').button_compute(cr, uid, [inv_id], {'type':'in_invoice'}, set_total=True)
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 735c6bb93250..6e635b96be2c 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -372,6 +372,7 @@ class sale_order(osv.osv):
             'currency_id' : order.pricelist_id.currency_id.id,
             'comment': order.note,
             'payment_term': pay_term,
+            'fiscal_position': order.partner_id.property_account_position.id
         }
         inv_obj = self.pool.get('account.invoice')
         inv.update(self._inv_get(cr, uid, order))
diff --git a/addons/sale/wizard/make_invoice_advance.py b/addons/sale/wizard/make_invoice_advance.py
index b2328ed33428..95b4fde05f3d 100644
--- a/addons/sale/wizard/make_invoice_advance.py
+++ b/addons/sale/wizard/make_invoice_advance.py
@@ -87,6 +87,7 @@ def _createInvoices(self, cr, uid, data, context={}):
             'currency_id' :sale.pricelist_id.currency_id.id,
             'comment': '',
             'payment_term':sale.payment_term.id,
+            'fiscal_position': sale.partner_id.property_account_position.id
             }
         inv_obj = pool_obj.get('account.invoice')
         inv_id = inv_obj.create(cr, uid, inv)
diff --git a/addons/sale/wizard/wizard_sale_line_invoice.py b/addons/sale/wizard/wizard_sale_line_invoice.py
index b3c1f718b793..b75dff690a4f 100644
--- a/addons/sale/wizard/wizard_sale_line_invoice.py
+++ b/addons/sale/wizard/wizard_sale_line_invoice.py
@@ -1,7 +1,7 @@
 # -*- encoding: utf-8 -*-
 ##############################################################################
 #
-#    OpenERP, Open Source Management Solution	
+#    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 #    $Id$
 #
@@ -61,6 +61,7 @@ def _makeInvoices(self, cr, uid, data, context):
             'currency_id' : order.pricelist_id.currency_id.id,
             'comment': order.note,
             'payment_term': pay_term,
+            'fiscal_position': order.partner_id.property_account_position.id
         }
         inv_id = pool.get('account.invoice').create(cr, uid, inv)
         return inv_id
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 92fa50dbd0b2..197b3eb15e5d 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -84,8 +84,8 @@ class stock_location(osv.osv):
             if 'stock_virtual' in field_names:
                 res[loc]['stock_virtual'] = prod.virtual_available
         return res
-    
-    
+
+
     def product_detail(self, cr, uid, id, field):
         res = {}
         res[id] = {}
@@ -100,7 +100,7 @@ class stock_location(osv.osv):
                 product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read,'standard_price','name'])
                 final_value += (product[field_to_read] * product['standard_price'])
         return final_value
-    
+
     def _product_value(self, cr, uid, ids, field_names, arg, context={}):
         result = {}
         for id in ids:
@@ -110,7 +110,7 @@ class stock_location(osv.osv):
                 ret_dict = self.product_detail(cr,uid,loc,field=field_name)
                 result[loc][field_name] = ret_dict
         return result
-    
+
     _columns = {
         'name': fields.char('Location Name', size=64, required=True, translate=True),
         'active': fields.boolean('Active'),
@@ -681,6 +681,7 @@ class stock_picking(osv.osv):
                     'address_contact_id': address_contact_id,
                     'comment': comment,
                     'payment_term': payment_term_id,
+                    'fiscal_position': partner.property_account_position.id
                     }
                 cur_id = self.get_currency_id(cursor, user, picking)
                 if cur_id:
-- 
GitLab