[FIX] sale: fixed the batch invoicing of sales orders that was create invoice twice per order + some refactoring
bzr revid: qdp-launchpad@openerp.com-20130321113059-667qdj873r0h0t55
This commit is contained in:
commit
1743dc6df7
|
@ -532,6 +532,9 @@ class sale_order(osv.osv):
|
||||||
invoice_ref += o.name + '|'
|
invoice_ref += o.name + '|'
|
||||||
self.write(cr, uid, [o.id], {'state': 'progress'})
|
self.write(cr, uid, [o.id], {'state': 'progress'})
|
||||||
cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res))
|
cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res))
|
||||||
|
#remove last '|' in invoice_ref
|
||||||
|
if len(invoice_ref) >= 1:
|
||||||
|
invoice_ref = invoice_ref[:-1]
|
||||||
invoice.write(cr, uid, [res], {'origin': invoice_ref, 'name': invoice_ref})
|
invoice.write(cr, uid, [res], {'origin': invoice_ref, 'name': invoice_ref})
|
||||||
else:
|
else:
|
||||||
for order, il in val:
|
for order, il in val:
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import fields, osv
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from openerp import netsvc
|
|
||||||
|
|
||||||
class sale_make_invoice(osv.osv_memory):
|
class sale_make_invoice(osv.osv_memory):
|
||||||
_name = "sale.make.invoice"
|
_name = "sale.make.invoice"
|
||||||
|
@ -40,7 +39,7 @@ class sale_make_invoice(osv.osv_memory):
|
||||||
record_id = context and context.get('active_id', False)
|
record_id = context and context.get('active_id', False)
|
||||||
order = self.pool.get('sale.order').browse(cr, uid, record_id, context=context)
|
order = self.pool.get('sale.order').browse(cr, uid, record_id, context=context)
|
||||||
if order.state == 'draft':
|
if order.state == 'draft':
|
||||||
raise osv.except_osv(_('Warning!'),'You cannot create invoice when sales order is not confirmed.')
|
raise osv.except_osv(_('Warning!'), _('You cannot create invoice when sales order is not confirmed.'))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def make_invoices(self, cr, uid, ids, context=None):
|
def make_invoices(self, cr, uid, ids, context=None):
|
||||||
|
@ -51,10 +50,11 @@ class sale_make_invoice(osv.osv_memory):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
data = self.read(cr, uid, ids)[0]
|
data = self.read(cr, uid, ids)[0]
|
||||||
order_obj.action_invoice_create(cr, uid, context.get(('active_ids'), []), data['grouped'], date_invoice = data['invoice_date'])
|
for sale_order in order_obj.browse(cr, uid, context.get(('active_ids'), []), context=context):
|
||||||
wf_service = netsvc.LocalService("workflow")
|
if sale_order.state != 'manual':
|
||||||
for id in context.get(('active_ids'), []):
|
raise osv.except_osv(_('Warning!'), _("You shouldn't manually invoice the following sale order %s") % (sale_order.name))
|
||||||
wf_service.trg_validate(uid, 'sale.order', id, 'manual_invoice', cr)
|
|
||||||
|
order_obj.action_invoice_create(cr, uid, context.get(('active_ids'), []), data['grouped'], date_invoice=data['invoice_date'])
|
||||||
|
|
||||||
for o in order_obj.browse(cr, uid, context.get(('active_ids'), []), context=context):
|
for o in order_obj.browse(cr, uid, context.get(('active_ids'), []), context=context):
|
||||||
for i in o.invoice_ids:
|
for i in o.invoice_ids:
|
||||||
|
@ -63,7 +63,7 @@ class sale_make_invoice(osv.osv_memory):
|
||||||
result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree1')
|
result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree1')
|
||||||
id = result and result[1] or False
|
id = result and result[1] or False
|
||||||
result = act_obj.read(cr, uid, [id], context=context)[0]
|
result = act_obj.read(cr, uid, [id], context=context)[0]
|
||||||
result['domain'] = "[('id','in', ["+','.join(map(str,newinv))+"])]"
|
result['domain'] = "[('id','in', [" + ','.join(map(str, newinv)) + "])]"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
<field name="model">sale.make.invoice</field>
|
<field name="model">sale.make.invoice</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Create invoices" version="7.0">
|
<form string="Create invoices" version="7.0">
|
||||||
<header>
|
|
||||||
<button name="make_invoices" string="Create Invoices" type="object" class="oe_highlight" />
|
|
||||||
or
|
|
||||||
<button string="Cancel" class="oe_link" special="cancel" />
|
|
||||||
</header>
|
|
||||||
<separator colspan="4" string="Do you really want to create the invoice(s)?" />
|
<separator colspan="4" string="Do you really want to create the invoice(s)?" />
|
||||||
<group>
|
<group>
|
||||||
<field name="grouped"/>
|
<field name="grouped"/>
|
||||||
<field name="invoice_date"/>
|
<field name="invoice_date"/>
|
||||||
</group>
|
</group>
|
||||||
|
<footer>
|
||||||
|
<button name="make_invoices" string="Create Invoices" type="object" class="oe_highlight"/>
|
||||||
|
or
|
||||||
|
<button string="Cancel" class="oe_link" special="cancel" />
|
||||||
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
Loading…
Reference in New Issue