=== modified file 'sale/sale.py' --- old/sale/sale.py 2009-07-02 14:56:52 +0000 +++ new/sale/sale.py 2009-08-01 17:38:28 +0000 @@ -378,6 +378,8 @@ 'payment_term': pay_term, 'fiscal_position': order.partner_id.property_account_position.id } + if context.get('date_inv', False): + inv['date_invoice'] = context['date_inv'] inv_obj = self.pool.get('account.invoice') inv.update(self._inv_get(cr, uid, order)) inv_id = inv_obj.create(cr, uid, inv) @@ -389,10 +391,16 @@ return inv_id - def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed','done','exception']): + def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed','done','exception'], date_inv=False): res = False invoices = {} invoice_ids = [] + context = {} + + # If date was specified, use it as date invoiced, usefull when invoices are generated this month and put the + # last day of the last month as invoice date + if date_inv: + context['date_inv'] = date_inv for o in self.browse(cr,uid,ids): lines = [] @@ -411,7 +419,7 @@ picking_obj=self.pool.get('stock.picking') for val in invoices.values(): if grouped: - res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x,y: x + y, [l for o,l in val], [])) + res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x,y: x + y, [l for o,l in val], []), context=context) for o,l in val: self.write(cr, uid, [o.id], {'state' : 'progress'}) if o.order_policy=='picking': @@ -419,7 +427,7 @@ cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res)) else: for order, il in val: - res = self._make_invoice(cr, uid, order, il) + res = self._make_invoice(cr, uid, order, il, context=context) invoice_ids.append(res) self.write(cr, uid, [order.id], {'state' : 'progress'}) if order.order_policy=='picking': === modified file 'sale/wizard/make_invoice.py' --- old/sale/wizard/make_invoice.py 2009-01-22 11:23:33 +0000 +++ new/sale/wizard/make_invoice.py 2009-08-01 14:42:14 +0000 @@ -28,11 +28,14 @@
+ + """ invoice_fields = { - 'grouped' : {'string':'Group the invoices', 'type':'boolean', 'default': lambda x,y,z: False} + 'grouped' : {'string':'Group the invoices', 'type':'boolean', 'default': lambda x,y,z: False}, + 'invoice_date': {'string': 'Invoiced date', 'type':'date', 'help': 'Usefull if the invoice was created the next month'}, } ack_form = """ @@ -46,7 +49,7 @@ order_obj = pooler.get_pool(cr.dbname).get('sale.order') newinv = [] - order_obj.action_invoice_create(cr, uid, data['ids'], data['form']['grouped']) + order_obj.action_invoice_create(cr, uid, data['ids'], data['form']['grouped'], date_inv=data['form']['invoice_date']) for id in data['ids']: wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'sale.order', id, 'manual_invoice', cr)