[FIX] stock: fixed invoicing wizard to work properly on multiple pickings - invoice type is automatically determined
bzr revid: odo@openerp.com-20101015115817-g1jy04x90cyinv7j
This commit is contained in:
parent
3e4abfff4e
commit
68a015bc42
|
@ -29,90 +29,67 @@ class stock_invoice_onshipping(osv.osv_memory):
|
||||||
_columns = {
|
_columns = {
|
||||||
'journal_id': fields.many2one('account.journal', 'Destination Journal', required=True),
|
'journal_id': fields.many2one('account.journal', 'Destination Journal', required=True),
|
||||||
'group': fields.boolean("Group by partner"),
|
'group': fields.boolean("Group by partner"),
|
||||||
'type': fields.selection([('out_invoice', 'Customer Invoice'),
|
|
||||||
('in_invoice', 'Supplier Invoice'),
|
|
||||||
('out_refund', 'Customer Refund'),
|
|
||||||
('in_refund', 'Supplier Refund')] , 'Type', required=True),
|
|
||||||
'invoice_date': fields.date('Invoiced date'),
|
'invoice_date': fields.date('Invoiced date'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def view_init(self, cr, uid, fields_list, context=None):
|
def view_init(self, cr, uid, fields_list, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
res= super(stock_invoice_onshipping, self).view_init(cr, uid, fields_list, context=context)
|
res = super(stock_invoice_onshipping, self).view_init(cr, uid, fields_list, context=context)
|
||||||
pick_obj=self.pool.get('stock.picking')
|
pick_obj = self.pool.get('stock.picking')
|
||||||
count=0
|
count = 0
|
||||||
for pick in pick_obj.browse(cr, uid,context.get('active_ids', False)):
|
active_ids = context.get('active_ids',[])
|
||||||
|
for pick in pick_obj.browse(cr, uid, active_ids):
|
||||||
if pick.invoice_state != '2binvoiced':
|
if pick.invoice_state != '2binvoiced':
|
||||||
count=count+1
|
count += 1
|
||||||
if len(context.get('active_ids'))==1 and count==1:
|
if len(active_ids) == 1 and count:
|
||||||
raise osv.except_osv(_('Warning !'),'This picking list does not require invoicing.')
|
raise osv.except_osv(_('Warning !'), _('This picking list does not require invoicing.'))
|
||||||
if len(context.get('active_ids'))==count:
|
if len(active_ids) == count:
|
||||||
raise osv.except_osv(_('Warning !'),'None of these picking lists require invoicing.')
|
raise osv.except_osv(_('Warning !'), _('None of these picking lists require invoicing.'))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_type(self, cr, uid, context=None):
|
def _get_type(self, pick):
|
||||||
""" To get invoice type.
|
src_usage = dest_usage = None
|
||||||
@param self: The object pointer.
|
pick_type = None
|
||||||
@param cr: A database cursor
|
if pick.invoice_state=='2binvoiced':
|
||||||
@param uid: ID of the user currently logged in
|
if pick.move_lines:
|
||||||
@param ids: The ID or list of IDs if we want more than one
|
src_usage = pick.move_lines[0].location_id.usage
|
||||||
@param context: A standard dictionary
|
dest_usage = pick.move_lines[0].location_dest_id.usage
|
||||||
@return: Invoice type
|
if pick.type == 'out' and dest_usage == 'supplier':
|
||||||
"""
|
pick_type = 'in_refund'
|
||||||
|
elif pick.type == 'out' and dest_usage == 'customer':
|
||||||
|
pick_type = 'out_invoice'
|
||||||
|
elif pick.type == 'in' and src_usage == 'supplier':
|
||||||
|
pick_type = 'in_invoice'
|
||||||
|
elif pick.type == 'in' and src_usage == 'customer':
|
||||||
|
pick_type = 'out_refund'
|
||||||
|
else:
|
||||||
|
pick_type = 'out_invoice'
|
||||||
|
return pick_type
|
||||||
|
|
||||||
|
def create_invoice(self, cr, uid, ids, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
picking_obj = self.pool.get('stock.picking')
|
|
||||||
src_usage = dest_usage = None
|
|
||||||
for pick in picking_obj.browse(cr, uid, context['active_ids'], context=context):
|
|
||||||
if pick.invoice_state=='2binvoiced':
|
|
||||||
if pick.move_lines:
|
|
||||||
src_usage = pick.move_lines[0].location_id.usage
|
|
||||||
dest_usage = pick.move_lines[0].location_dest_id.usage
|
|
||||||
if pick.type == 'out' and dest_usage == 'supplier':
|
|
||||||
type = 'in_refund'
|
|
||||||
elif pick.type == 'out' and dest_usage == 'customer':
|
|
||||||
type = 'out_invoice'
|
|
||||||
elif pick.type == 'in' and src_usage == 'supplier':
|
|
||||||
type = 'in_invoice'
|
|
||||||
elif pick.type == 'in' and src_usage == 'customer':
|
|
||||||
type = 'out_refund'
|
|
||||||
else:
|
|
||||||
type = 'out_invoice'
|
|
||||||
return type
|
|
||||||
|
|
||||||
_defaults = {
|
|
||||||
'type': _get_type,
|
|
||||||
}
|
|
||||||
|
|
||||||
def create_invoice(self, cr, uid, ids, context):
|
|
||||||
""" To create invoice
|
|
||||||
@param self: The object pointer.
|
|
||||||
@param cr: A database cursor
|
|
||||||
@param uid: ID of the user currently logged in
|
|
||||||
@param ids: the ID or list of IDs if we want more than one
|
|
||||||
@param context: A standard dictionary
|
|
||||||
@return: Invoice ids
|
|
||||||
"""
|
|
||||||
result = []
|
result = []
|
||||||
picking_obj = self.pool.get('stock.picking')
|
picking_obj = self.pool.get('stock.picking')
|
||||||
mod_obj = self.pool.get('ir.model.data')
|
onshipdata_obj = self.read(cr, uid, ids[0], ['journal_id', 'group', 'invoice_date'])
|
||||||
act_obj = self.pool.get('ir.actions.act_window')
|
if context.get('new_picking', False):
|
||||||
for onshipdata_obj in self.read(cr, uid, ids, ['journal_id', 'group', 'type', 'invoice_date']):
|
onshipdata_obj['id'] = onshipdata_obj.new_picking
|
||||||
if context.get('new_picking', False):
|
onshipdata_obj[ids] = onshipdata_obj.new_picking
|
||||||
onshipdata_obj[id] = onshipdata_obj.new_picking
|
|
||||||
onshipdata_obj[ids] = onshipdata_obj.new_picking
|
|
||||||
|
|
||||||
type = onshipdata_obj['type']
|
context['date_inv'] = onshipdata_obj['invoice_date']
|
||||||
context['date_inv'] = onshipdata_obj['invoice_date']
|
invoice_ids = []
|
||||||
res = picking_obj.action_invoice_create(cr, uid,context['active_ids'],
|
for picking in picking_obj.browse(cr, uid, context.get('active_ids', []), context=context):
|
||||||
journal_id = onshipdata_obj['journal_id'],
|
if picking.invoice_state == '2binvoiced':
|
||||||
group=onshipdata_obj['group'],
|
res = picking_obj.action_invoice_create(cr, uid, [picking.id],
|
||||||
type=type,
|
journal_id = onshipdata_obj['journal_id'],
|
||||||
context=context)
|
group=onshipdata_obj['group'],
|
||||||
invoice_ids = res.values()
|
type=self._get_type(picking),
|
||||||
if not invoice_ids:
|
context=context)
|
||||||
raise osv.except_osv(_('Error'), _('Invoice is not created'))
|
invoice_ids.extend(res.values())
|
||||||
|
|
||||||
|
if not invoice_ids:
|
||||||
|
raise osv.except_osv(_('Error'), _('No invoice were created'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'domain': "[('id','in', ["+','.join(map(str,invoice_ids))+"])]",
|
'domain': "[('id','in', ["+','.join(map(str,invoice_ids))+"])]",
|
||||||
|
@ -120,7 +97,6 @@ class stock_invoice_onshipping(osv.osv_memory):
|
||||||
'view_type': 'form',
|
'view_type': 'form',
|
||||||
'view_mode': 'tree,form',
|
'view_mode': 'tree,form',
|
||||||
'res_model': 'account.invoice',
|
'res_model': 'account.invoice',
|
||||||
'views': False,
|
|
||||||
'context': context,
|
'context': context,
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,16 @@
|
||||||
<field name="model">stock.invoice.onshipping</field>
|
<field name="model">stock.invoice.onshipping</field>
|
||||||
<field name="type">form</field>
|
<field name="type">form</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Create invoices">
|
<form string="Create invoice">
|
||||||
<separator colspan="4" string="Create invoices" />
|
<separator colspan="4" string="Create invoice" />
|
||||||
<field name="journal_id"/>
|
<field name="journal_id"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="group"/>
|
<field name="group"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="type"/>
|
|
||||||
<newline/>
|
|
||||||
<field name="invoice_date" />
|
<field name="invoice_date" />
|
||||||
<separator string="" colspan="4" />
|
<separator string="" colspan="4" />
|
||||||
<button special="cancel" string="_Cancel" icon='gtk-cancel'/>
|
<button special="cancel" string="_Cancel" icon='gtk-cancel'/>
|
||||||
<button name="create_invoice" string="Create Invoices" type="object" icon="terp-gtk-go-back-rtl"/>
|
<button name="create_invoice" string="Create" type="object" icon="terp-gtk-go-back-rtl"/>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
Loading…
Reference in New Issue