[ADD]: Add button on specific condition.

bzr revid: atp@tinyerp.com-20121107164842-lymoy84p30byl0en
This commit is contained in:
Atul Patel (OpenERP) 2012-11-07 22:18:42 +05:30
parent 04cdfb2cd5
commit a81e1b2881
3 changed files with 59 additions and 61 deletions

View File

@ -118,7 +118,6 @@ class stock_picking(osv.osv):
class stock_partial_picking(osv.osv_memory):
_inherit = 'stock.partial.picking'
# Overridden to inject the purchase price as true 'cost price' when processing
# incoming pickings.
def _product_cost_for_average_update(self, cr, uid, move):
@ -127,54 +126,6 @@ class stock_partial_picking(osv.osv_memory):
'currency': move.picking_id.purchase_id.pricelist_id.currency_id.id}
return super(stock_partial_picking, self)._product_cost_for_average_update(cr, uid, move)
def create_invoice(self, cr, uid, ids, context=None):
if context is None:
context = {}
picking_pool = self.pool.get('stock.picking')
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)
context['inv_type'] = inv_type
res = picking_pool.action_invoice_create(cr, uid, active_ids,
type = inv_type,
context=context)
return res
def open_invoice(self, cr, uid, ids, context=None):
"""Launch Create invoice wizard.
"""
if context is None: context = {}
data_pool = self.pool.get('ir.model.data')
result = self.do_partial(cr, uid, ids, context=context)
partial = self.browse(cr, uid, ids[0], context=context)
context.update(active_model='stock.picking',
active_ids=[partial.picking_id.id])
if partial.picking_id.invoice_state == '2binvoiced':
invoice_ids = []
res = self.create_invoice(cr, uid, ids, context=context)
invoice_ids += res.values()
inv_type = context.get('inv_type', False)
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":
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")
if action_model:
action_pool = self.pool.get(action_model)
action = action_pool.read(cr, uid, action_id, context=context)
action['domain'] = "[('id','in', ["+','.join(map(str,invoice_ids))+"])]"
return action
return {'type': 'ir.actions.act_window_close'}
# Redefinition of the new field in order to update the model stock.picking.in in the orm
# FIXME: this is a temporary workaround because of a framework bug (ref: lp996816). It should be removed as soon as
# the bug is fixed

View File

@ -37,18 +37,6 @@
</field>
</record>
<!-- inherit view of stock.partial.picking wizard -->
<record id="stock_partial_picking_form_inherit" model="ir.ui.view">
<field name="name">stock.partial.picking.form.inherit</field>
<field name="model">stock.partial.picking</field>
<field name="inherit_id" ref="stock.stock_partial_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='do_partial']" position="after">
<button name="open_invoice" string="Receive &amp; Control Invoice" type="object" class="oe_highlight" />
</xpath>
</field>
</record>
<!-- is it need ? we have another method "Receive Products"-->
<record id="purchase_order_2_stock_picking" model="ir.ui.view">
<field name="name">Purchase Picking Inherited</field>

View File

@ -81,12 +81,64 @@ class stock_partial_picking(osv.osv_memory):
'hide_tracking': fields.function(_hide_tracking, string='Tracking', type='boolean', help='This field is for internal purpose. It is used to decide if the column production lot has to be shown on the moves or not.'),
}
def create_invoice(self, cr, uid, ids, context=None):
if context is None:
context = {}
picking_pool = self.pool.get('stock.picking')
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)
context['inv_type'] = inv_type
res = picking_pool.action_invoice_create(cr, uid, active_ids,
type = inv_type,
context=context)
return res
def open_invoice(self, cr, uid, ids, context=None):
"""Launch Create invoice wizard.
"""
if context is None: context = {}
data_pool = self.pool.get('ir.model.data')
result = self.do_partial(cr, uid, ids, context=context)
partial = self.browse(cr, uid, ids[0], context=context)
context.update(active_model='stock.picking',
active_ids=[partial.picking_id.id])
if partial.picking_id.invoice_state == '2binvoiced':
invoice_ids = []
res = self.create_invoice(cr, uid, ids, context=context)
invoice_ids += res.values()
inv_type = context.get('inv_type', False)
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":
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")
if action_model:
action_pool = self.pool.get(action_model)
action = action_pool.read(cr, uid, action_id, context=context)
action['domain'] = "[('id','in', ["+','.join(map(str,invoice_ids))+"])]"
return action
return {'type': 'ir.actions.act_window_close'}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
#override of fields_view_get in order to change the label of the process button and the separator accordingly to the shipping type
if context is None:
context={}
res = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
type = context.get('default_type', False)
active_model = context.get('active_model', 'stock.picking')
active_pool = self.pool.get(active_model)
picking = active_pool.browse(cr, uid, context.get('active_id', False))
if type:
doc = etree.XML(res['arch'])
for node in doc.xpath("//button[@name='do_partial']"):
@ -94,6 +146,13 @@ class stock_partial_picking(osv.osv_memory):
node.set('string', _('_Receive'))
elif type == 'out':
node.set('string', _('_Deliver'))
if picking and picking.invoice_state == '2binvoiced':
buttonnode = node.makeelement('button')
buttonnode.set('name', "open_invoice")
buttonnode.set('String', "Receive & Control Invoice")
buttonnode.set('class', "oe_highlight")
buttonnode.set('type', "object")
node.addnext(buttonnode)
for node in doc.xpath("//separator[@name='product_separator']"):
if type == 'in':
node.set('string', _('Receive Products'))