[FIX] Creating invoices on picking seems to work
bzr revid: fp@openerp.com-20130804170255-8ll9udktbdfzhu6w
This commit is contained in:
parent
934be97ff6
commit
ef4b7c69b2
|
@ -110,7 +110,8 @@
|
|||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='do_prepare_partial']" position="after">
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Create Invoice/Refund" attrs="{'invisible': ['|',('state','<>','done'),('invoice_state','<>','2binvoiced')]}" type="action" class="oe_highlight" groups="base.group_user"/>
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" attrs="{'invisible': ['|',('state','<>','done'),('invoice_state','<>','2binvoiced')]}" type="action" class="oe_highlight" groups="base.group_user"/>
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Refund Invoice" attrs="{'invisible': ['|',('state','<>','done'),('invoice_state','<>','invoiced')]}" type="action" class="oe_highlight" groups="base.group_user" context="{'inv_type': 'out_refund'}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='move_type']" position="after">
|
||||
<field name="invoice_state" groups="account.group_account_invoice"/>
|
||||
|
|
|
@ -70,17 +70,21 @@ class stock_picking(osv.osv):
|
|||
"""
|
||||
context = context or {}
|
||||
todo = {}
|
||||
print 'Invoice Create', ids, journal_id, group, type, context
|
||||
for picking in self.browse(cr, uid, ids, context=context):
|
||||
key = group and picking.id or True
|
||||
for move in picking.move_lines:
|
||||
if (not move.procurement_id) or (move.procurement_id.invoice_state <> '2binvoiced'):
|
||||
if move.procurement_id and (move.procurement_id.invoice_state=='2binvoiced'):
|
||||
if (move.state <> 'cancel') and not move.scrapped:
|
||||
todo.setdefault(key, [])
|
||||
todo[key].append(move)
|
||||
invoices = []
|
||||
for moves in todo.values():
|
||||
self.__invoice_create_line(cr, uid, moves, journal_id, type, context=context)
|
||||
return True
|
||||
invoices = self.__invoice_create_line(cr, uid, moves, journal_id, type, context=context)
|
||||
return invoices
|
||||
|
||||
def __invoice_create_line(self, cr, uid, moves, journal_id=False, inv_type='out_invoice', context=None):
|
||||
invoice_obj = self.pool.get('account.invoice')
|
||||
invoices = {}
|
||||
for move in moves:
|
||||
sale_line = move.procurement_id.sale_line_id
|
||||
|
@ -99,7 +103,7 @@ class stock_picking(osv.osv):
|
|||
account_id = partner.property_account_payable.id
|
||||
payment_term = partner.property_supplier_payment_term.id or False
|
||||
|
||||
invoice_id = self.pool.get('account.invoice').create(cr, uid, {
|
||||
invoice_id = invoice_obj.create(cr, uid, {
|
||||
'origin': sale.name,
|
||||
'date_invoice': context.get('date_inv', False),
|
||||
'user_id': sale.user_id and sale.user_id.id or False,
|
||||
|
@ -140,7 +144,7 @@ class stock_picking(osv.osv):
|
|||
'origin': move.picking_id and move.picking_id.origin or False,
|
||||
'invoice_id': invoices[key],
|
||||
'account_id': account_id,
|
||||
'product_id': line.product_id.id,
|
||||
'product_id': move.product_id.id,
|
||||
'uos_id': uos_id,
|
||||
'quantity': quantity,
|
||||
'price_unit': sale_line.price_unit,
|
||||
|
@ -161,4 +165,4 @@ class stock_picking(osv.osv):
|
|||
}, context=context)
|
||||
|
||||
invoice_obj.button_compute(cr, uid, invoices.values(), context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
|
||||
return invoices.keys()
|
||||
return invoices.values()
|
||||
|
|
|
@ -46,10 +46,12 @@ class stock_invoice_onshipping(osv.osv_memory):
|
|||
_columns = {
|
||||
'journal_id': fields.selection(_get_journal_id, 'Destination Journal',required=True),
|
||||
'group': fields.boolean("Group by partner"),
|
||||
'invoice_date': fields.date('Invoiced date'),
|
||||
'inv_type': fields.selection([('out_invoice','Create Invoice'),('out_refund','Refund Invoice')], "Invoice Type"),
|
||||
'invoice_date': fields.date('Invoice Date'),
|
||||
}
|
||||
_defaults = {
|
||||
'journal_id' : _get_journal,
|
||||
'inv_type': lambda self,cr,uid,ctx: ctx.get('inv_type', 'out_invoice')
|
||||
}
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
|
@ -62,8 +64,6 @@ class stock_invoice_onshipping(osv.osv_memory):
|
|||
for pick in pick_obj.browse(cr, uid, active_ids, context=context):
|
||||
if pick.invoice_state != '2binvoiced':
|
||||
count += 1
|
||||
if len(active_ids) == 1 and count:
|
||||
raise osv.except_osv(_('Warning!'), _('This picking list does not require invoicing.'))
|
||||
if len(active_ids) == count:
|
||||
raise osv.except_osv(_('Warning!'), _('None of these picking lists require invoicing.'))
|
||||
return res
|
||||
|
@ -71,42 +71,41 @@ class stock_invoice_onshipping(osv.osv_memory):
|
|||
def open_invoice(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
invoice_ids = []
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
res = self.create_invoice(cr, uid, ids, context=context)
|
||||
invoice_ids += res.values()
|
||||
inv_type = context.get('inv_type', False)
|
||||
print 'Create Invoice', context
|
||||
invoice_ids = self.create_invoice(cr, uid, ids, context=context)
|
||||
if not invoice_ids:
|
||||
raise osv.except_osv(_('Error!'), _('No invoice created!'))
|
||||
|
||||
onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date', 'inv_type'])
|
||||
inv_type = onshipdata_obj[0]['inv_type']
|
||||
|
||||
action_model = False
|
||||
action = {}
|
||||
if not invoice_ids:
|
||||
raise osv.except_osv(_('Error!'), _('Please create Invoices.'))
|
||||
if inv_type == "out_invoice":
|
||||
action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree1")
|
||||
elif inv_type == "in_invoice":
|
||||
action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree2")
|
||||
elif inv_type == "out_refund":
|
||||
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
if inv_type == "out_refund":
|
||||
action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree3")
|
||||
elif inv_type == "in_refund":
|
||||
action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree4")
|
||||
elif inv_type == "out_invoice":
|
||||
action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree1")
|
||||
|
||||
if action_model:
|
||||
action_pool = self.pool[action_model]
|
||||
action = action_pool.read(cr, uid, action_id, context=context)
|
||||
action['domain'] = "[('id','in', ["+','.join(map(str,invoice_ids))+"])]"
|
||||
return action
|
||||
return action
|
||||
return True
|
||||
|
||||
def create_invoice(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
context = context or {}
|
||||
|
||||
picking_pool = self.pool.get('stock.picking')
|
||||
onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date'])
|
||||
if context.get('new_picking', False):
|
||||
onshipdata_obj['id'] = onshipdata_obj.new_picking
|
||||
onshipdata_obj[ids] = onshipdata_obj.new_picking
|
||||
onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date', 'inv_type'])
|
||||
|
||||
context['date_inv'] = onshipdata_obj[0]['invoice_date']
|
||||
active_ids = context.get('active_ids', [])
|
||||
active_picking = picking_pool.browse(cr, uid, context.get('active_id',False), context=context)
|
||||
inv_type = picking_pool._get_invoice_type(active_picking)
|
||||
inv_type = onshipdata_obj[0]['inv_type']
|
||||
context['inv_type'] = inv_type
|
||||
|
||||
active_ids = context.get('active_ids', [])
|
||||
if isinstance(onshipdata_obj[0]['journal_id'], tuple):
|
||||
onshipdata_obj[0]['journal_id'] = onshipdata_obj[0]['journal_id'][0]
|
||||
res = picking_pool.action_invoice_create(cr, uid, active_ids,
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
<field name="model">stock.invoice.onshipping</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create invoice" version="7.0">
|
||||
<group string="Create Invoice">
|
||||
<h1>
|
||||
<field name="inv_type" readonly="1"/>
|
||||
</h1>
|
||||
<group>
|
||||
<field name="journal_id"/>
|
||||
<field name="group"/>
|
||||
<field name="invoice_date" />
|
||||
|
|
Loading…
Reference in New Issue