diff --git a/addons/purchase_manual/__terp__.py b/addons/purchase_manual/__terp__.py
index 7634af9ca7a..a0c140cbcc2 100644
--- a/addons/purchase_manual/__terp__.py
+++ b/addons/purchase_manual/__terp__.py
@@ -31,7 +31,8 @@
'init_xml': [],
'update_xml': [
'purchase_manual_view.xml',
- 'purchase_manual_wizard.xml',
+ 'wizard/purchase_line_invoice_view.xml',
+
],
'demo_xml': [],
'installable': True,
diff --git a/addons/purchase_manual/purchase_manual_view.xml b/addons/purchase_manual/purchase_manual_view.xml
index 4e698dcac53..7d97cca7512 100644
--- a/addons/purchase_manual/purchase_manual_view.xml
+++ b/addons/purchase_manual/purchase_manual_view.xml
@@ -77,7 +77,7 @@
-
+
Uninvoiced Purchase Order Lines
@@ -99,7 +99,7 @@
-
+
diff --git a/addons/purchase_manual/wizard/__init__.py b/addons/purchase_manual/wizard/__init__.py
index e93c28bfe14..9f53e1a75ad 100644
--- a/addons/purchase_manual/wizard/__init__.py
+++ b/addons/purchase_manual/wizard/__init__.py
@@ -19,4 +19,5 @@
#
##############################################################################
-import wizard_purchase_line_invoice
+
+import purchase_line_invoice
diff --git a/addons/purchase_manual/wizard/purchase_line_invoice.py b/addons/purchase_manual/wizard/purchase_line_invoice.py
new file mode 100644
index 00000000000..12024df71ad
--- /dev/null
+++ b/addons/purchase_manual/wizard/purchase_line_invoice.py
@@ -0,0 +1,132 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# 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 .
+#
+##############################################################################
+
+import netsvc
+import ir
+from osv import osv
+from tools.translate import _
+
+class purchase_line_invoice(osv.osv_memory):
+
+ """ To create invoice for purchase order line"""
+
+ _name = 'purchase.order.line_invoice'
+ _description = 'Purchase Order Line Make Invoice'
+
+ def makeInvoices(self, cr, uid, ids, context):
+ """
+ To get Purchase Order line and create Invoice
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param context: A standard dictionary
+ @return : retrun view of Invoice
+ """
+ record_ids = context.get('active_ids',[])
+ if record_ids:
+ res = False
+ invoices = {}
+ invoice_obj=self.pool.get('account.invoice')
+ purchase_line_obj=self.pool.get('purchase.order.line')
+ property_obj=self.pool.get('ir.property')
+ account_fiscal_obj=self.pool.get('account.fiscal.position')
+ invoice_line_obj=self.pool.get('account.invoice.line')
+
+ def make_invoice(order, lines):
+ a = order.partner_id.property_account_payable.id
+ if order.partner_id and order.partner_id.property_payment_term.id:
+ pay_term = order.partner_id.property_payment_term.id
+ else:
+ pay_term = False
+ inv = {
+ 'name': order.name,
+ 'origin': order.name,
+ 'type': 'in_invoice',
+ 'reference': "P%dPO%d" % (order.partner_id.id, order.id),
+ 'account_id': a,
+ 'partner_id': order.partner_id.id,
+ 'address_invoice_id': order.partner_address_id.id,
+ 'address_contact_id': order.partner_address_id.id,
+ 'invoice_line': [(6,0,lines)],
+ 'currency_id' : order.pricelist_id.currency_id.id,
+ 'comment': order.notes,
+ 'payment_term': pay_term,
+ 'fiscal_position': order.partner_id.property_account_position.id
+ }
+ inv_id = invoice_obj.create(cr, uid, inv)
+ return inv_id
+
+ for line in purchase_line_obj.browse(cr,uid,record_ids):
+ if (not line.invoiced) and (line.state not in ('draft','cancel')):
+ if not line.order_id.id in invoices:
+ invoices[line.order_id.id] = []
+ if line.product_id:
+ a = line.product_id.product_tmpl_id.property_account_expense.id
+ if not a:
+ a = line.product_id.categ_id.property_account_expense_categ.id
+ if not a:
+ raise osv.except_osv(_('Error !'),
+ _('There is no expense account defined ' \
+ 'for this product: "%s" (id:%d)') % \
+ (line.product_id.name, line.product_id.id,))
+ else:
+ a = property_obj.get(cr, uid,
+ 'property_account_expense_categ', 'product.category',
+ context=context)
+ fpos = line.order_id.fiscal_position or False
+ a = account_fiscal_obj.map_account(cr, uid, fpos, a)
+ inv_id = invoice_line_obj.create(cr, uid, {
+ 'name': line.name,
+ 'origin': line.order_id.name,
+ 'account_id': a,
+ 'price_unit': line.price_unit,
+ 'quantity': line.product_qty,
+ 'uos_id': line.product_uom.id,
+ 'product_id': line.product_id.id or False,
+ 'invoice_line_tax_id': [(6, 0, [x.id for x in line.taxes_id])],
+ 'note': line.notes,
+ 'account_analytic_id': line.account_analytic_id and line.account_analytic_id.id or False,
+ })
+ cr.execute('insert into purchase_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
+ purchase_line_obj.write(cr, uid, [line.id], {'invoiced': True})
+ invoices[line.order_id.id].append((line,inv_id))
+
+ res = []
+ for result in invoices.values():
+ order = result[0][0].order_id
+ il = map(lambda x: x[1], result)
+ res.append(make_invoice(order, il))
+
+ return {
+ 'domain': "[('id','in', ["+','.join(map(str,res))+"])]",
+ 'name': _('Supplier Invoices'),
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.invoice',
+ 'view_id': False,
+ 'context': "{'type':'in_invoice'}",
+ 'type': 'ir.actions.act_window'
+ }
+purchase_line_invoice()
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/purchase_manual/wizard/purchase_line_invoice_view.xml b/addons/purchase_manual/wizard/purchase_line_invoice_view.xml
new file mode 100644
index 00000000000..c5855e5d448
--- /dev/null
+++ b/addons/purchase_manual/wizard/purchase_line_invoice_view.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+ Control invoices
+ purchase.order.line_invoice
+ form
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/addons/purchase_manual/wizard/wizard_purchase_line_invoice.py b/addons/purchase_manual/wizard/wizard_purchase_line_invoice.py
deleted file mode 100644
index 0e30368d41b..00000000000
--- a/addons/purchase_manual/wizard/wizard_purchase_line_invoice.py
+++ /dev/null
@@ -1,162 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# 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 .
-#
-##############################################################################
-
-import wizard
-import netsvc
-import ir
-import pooler
-from osv import osv
-from tools.translate import _
-
-invoice_form = """
-
-"""
-
-invoice_fields = {
-}
-
-def _makeInvoices(self, cr, uid, data, context):
- pool = pooler.get_pool(cr.dbname)
- res = False
- invoices = {}
-
- def make_invoice(order, lines):
- a = order.partner_id.property_account_payable.id
- if order.partner_id and order.partner_id.property_payment_term.id:
- pay_term = order.partner_id.property_payment_term.id
- else:
- pay_term = False
- inv = {
- 'name': order.name,
- 'origin': order.name,
- 'type': 'in_invoice',
- 'reference': "P%dPO%d" % (order.partner_id.id, order.id),
- 'account_id': a,
- 'partner_id': order.partner_id.id,
- 'address_invoice_id': order.partner_address_id.id,
- 'address_contact_id': order.partner_address_id.id,
- 'invoice_line': [(6,0,lines)],
- 'currency_id' : order.pricelist_id.currency_id.id,
- 'comment': order.notes,
- '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
-
- for line in pool.get('purchase.order.line').browse(cr,uid,data['ids']):
- if (not line.invoiced) and (line.state not in ('draft','cancel')):
- if not line.order_id.id in invoices:
- invoices[line.order_id.id] = []
- if line.product_id:
- a = line.product_id.product_tmpl_id.property_account_expense.id
- if not a:
- a = line.product_id.categ_id.property_account_expense_categ.id
- if not a:
- raise osv.except_osv(_('Error !'),
- _('There is no expense account defined ' \
- 'for this product: "%s" (id:%d)') % \
- (line.product_id.name, line.product_id.id,))
- else:
- a = pool.get('ir.property').get(cr, uid,
- 'property_account_expense_categ', 'product.category',
- context=context)
- fpos = line.order_id.fiscal_position or False
- a = pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
- inv_id = pool.get('account.invoice.line').create(cr, uid, {
- 'name': line.name,
- 'origin': line.order_id.name,
- 'account_id': a,
- 'price_unit': line.price_unit,
- 'quantity': line.product_qty,
- 'uos_id': line.product_uom.id,
- 'product_id': line.product_id.id or False,
- 'invoice_line_tax_id': [(6, 0, [x.id for x in line.taxes_id])],
- 'note': line.notes,
- 'account_analytic_id': line.account_analytic_id and line.account_analytic_id.id or False,
- })
- cr.execute('insert into purchase_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
- pool.get('purchase.order.line').write(cr, uid, [line.id], {'invoiced': True})
- invoices[line.order_id.id].append((line,inv_id))
-
- res = []
- for result in invoices.values():
- order = result[0][0].order_id
- il = map(lambda x: x[1], result)
- res.append(make_invoice(order, il))
- return {'invoice_ids': res}
-
- return {
- 'domain': "[('id','in', ["+','.join(map(str,res))+"])]",
- 'name': _('Supplier Invoices'),
- 'view_type': 'form',
- 'view_mode': 'tree,form',
- 'res_model': 'account.invoice',
- 'view_id': False,
- 'context': "{'type':'in_invoice'}",
- 'type': 'ir.actions.act_window'
- }
-
-class line_make_invoice(wizard.interface):
- def _open_invoice(self, cr, uid, data, context):
- pool_obj = pooler.get_pool(cr.dbname)
- model_data_ids = pool_obj.get('ir.model.data').search(cr,uid,[('model','=','ir.ui.view'),('name','=','invoice_supplier_form')])
- resource_id = pool_obj.get('ir.model.data').read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
- return {
- 'domain': "[('id','in', ["+','.join(map(str,data['form']['invoice_ids']))+"])]",
- 'name': 'Invoices',
- 'view_type': 'form',
- 'view_mode': 'tree,form',
- 'res_model': 'account.invoice',
- 'views': [(False,'tree'),(resource_id,'form')],
- 'context': "{'type':'in_invoice'}",
- 'type': 'ir.actions.act_window'
- }
-
- states = {
- 'init' : {
- 'actions': [],
- 'result': {
- 'type': 'form',
- 'arch': invoice_form,
- 'fields': invoice_fields,
- 'state': [
- ('end', 'Cancel'),
- ('invoice', 'Create invoices')
- ]
- }
- },
- 'invoice' : {
- 'actions' : [_makeInvoices],
- 'result' : {'type': 'state', 'state': 'open'}
- },
- 'open': {
- 'actions': [],
- 'result': {'type':'action', 'action':_open_invoice, 'state':'end'}
- }
- }
-
-line_make_invoice("purchase.order.line.make_invoice")
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-