[FIX] sale_stock : Traceback when paying invoice by percentage in SO, after installing sale_stock.
bzr revid: mdi@tinyerp.com-20121011070128-z81rzss16d2no59i
This commit is contained in:
parent
fc94df2af5
commit
20d9f75193
|
@ -635,34 +635,64 @@ class sale_order_line(osv.osv):
|
||||||
class sale_advance_payment_inv(osv.osv_memory):
|
class sale_advance_payment_inv(osv.osv_memory):
|
||||||
_inherit = "sale.advance.payment.inv"
|
_inherit = "sale.advance.payment.inv"
|
||||||
|
|
||||||
def _create_invoices(self, cr, uid, inv_values, sale_id, context=None):
|
def create_invoices(self, cr, uid, ids, context=None):
|
||||||
result = super(sale_advance_payment_inv, self)._create_invoices(cr, uid, inv_values, sale_id, context=context)
|
""" create invoices for the active sale orders """
|
||||||
sale_obj = self.pool.get('sale.order')
|
sale_obj = self.pool.get('sale.order')
|
||||||
sale_line_obj = self.pool.get('sale.order.line')
|
act_window = self.pool.get('ir.actions.act_window')
|
||||||
wizard = self.browse(cr, uid, ids[0], context)
|
wizard = self.browse(cr, uid, ids[0], context)
|
||||||
sale = sale_obj.browse(cr, uid, sale_id, context=context)
|
sale_ids = context.get('active_ids', [])
|
||||||
if sale.order_policy == 'postpaid':
|
if wizard.advance_payment_method == 'all':
|
||||||
raise osv.except_osv(
|
# create the final invoices of the active sale orders
|
||||||
_('Error!'),
|
res = sale_obj.manual_invoice(cr, uid, sale_ids, context)
|
||||||
_("You cannot make an advance on a sales order \
|
if context.get('open_invoices', False):
|
||||||
that is defined as 'Automatic Invoice after delivery'."))
|
return res
|
||||||
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
|
||||||
# If invoice on picking: add the cost on the SO
|
if wizard.advance_payment_method == 'lines':
|
||||||
# If not, the advance will be deduced when generating the final invoice
|
# open the list view of sale order lines to invoice
|
||||||
line_name = inv_values.get('invoice_line') and inv_values.get('invoice_line')[2].get('name') or ''
|
res = act_window.for_xml_id(cr, uid, 'sale', 'action_order_line_tree2', context)
|
||||||
line_tax = inv_values.get('invoice_line') and inv_values.get('invoice_line')[2].get('invoice_line_tax_id') or False
|
res['context'] = {
|
||||||
if sale.order_policy == 'picking':
|
'search_default_uninvoiced': 1,
|
||||||
vals = {
|
'search_default_order_id': sale_ids and sale_ids[0] or False,
|
||||||
'order_id': sale.id,
|
|
||||||
'name': line_name,
|
|
||||||
'price_unit': -inv_amount,
|
|
||||||
'product_uom_qty': wizard.qtty or 1.0,
|
|
||||||
'product_uos_qty': wizard.qtty or 1.0,
|
|
||||||
'product_uos': res.get('uos_id', False),
|
|
||||||
'product_uom': res.get('uom_id', False),
|
|
||||||
'product_id': wizard.product_id.id or False,
|
|
||||||
'discount': False,
|
|
||||||
'tax_id': line_tax,
|
|
||||||
}
|
}
|
||||||
sale_line_obj.create(cr, uid, vals, context=context)
|
return res
|
||||||
return result
|
assert wizard.advance_payment_method in ('fixed', 'percentage')
|
||||||
|
|
||||||
|
inv_ids = []
|
||||||
|
for sale_id, inv_values in self._prepare_advance_invoice_vals(cr, uid, ids, context=context):
|
||||||
|
|
||||||
|
sale_obj = self.pool.get('sale.order')
|
||||||
|
sale_line_obj = self.pool.get('sale.order.line')
|
||||||
|
sale = sale_obj.browse(cr, uid, sale_id, context=context)
|
||||||
|
if sale.order_policy == 'postpaid':
|
||||||
|
raise osv.except_osv(
|
||||||
|
_('Error!'),
|
||||||
|
_("You cannot make an advance on a sales order \
|
||||||
|
that is defined as 'Automatic Invoice after delivery'."))
|
||||||
|
|
||||||
|
# If invoice on picking: add the cost on the SO
|
||||||
|
# If not, the advance will be deduced when generating the final invoice
|
||||||
|
line_name = inv_values.get('invoice_line') and inv_values.get('invoice_line')[0][2].get('name') or ''
|
||||||
|
line_tax = inv_values.get('invoice_line') and inv_values.get('invoice_line')[0][2].get('invoice_line_tax_id') or False
|
||||||
|
if sale.order_policy == 'picking':
|
||||||
|
vals = {
|
||||||
|
'order_id': sale.id,
|
||||||
|
'name': line_name,
|
||||||
|
'price_unit': -inv_amount,
|
||||||
|
'product_uom_qty': wizard.qtty or 1.0,
|
||||||
|
'product_uos_qty': wizard.qtty or 1.0,
|
||||||
|
'product_uos': res.get('uos_id', False),
|
||||||
|
'product_uom': res.get('uom_id', False),
|
||||||
|
'product_id': wizard.product_id.id or False,
|
||||||
|
'discount': False,
|
||||||
|
'tax_id': line_tax,
|
||||||
|
}
|
||||||
|
sale_line_obj.create(cr, uid, vals, context=context)
|
||||||
|
|
||||||
|
inv_ids.append(self._create_invoices(cr, uid, inv_values, sale_id, context=context))
|
||||||
|
|
||||||
|
if context.get('open_invoices', False):
|
||||||
|
return self.open_invoices( cr, uid, ids, inv_ids, context=context)
|
||||||
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
res = super(sale_advance_payment_inv, self).create_invoices(self, cr, uid, ids, context=context)
|
||||||
|
return res
|
Loading…
Reference in New Issue