Fixes #3851 Create invoice from picking copies some parameters from the order to the invoice
This commit is contained in:
parent
8eae018b27
commit
31a01ea772
|
@ -158,6 +158,16 @@ class stock_picking(osv.osv):
|
||||||
invoice_line_obj.write(cr, uid, inv_lines, {'invoice_id': invoice_id}, context=context)
|
invoice_line_obj.write(cr, uid, inv_lines, {'invoice_id': invoice_id}, context=context)
|
||||||
return invoice_id
|
return invoice_id
|
||||||
|
|
||||||
|
def _get_invoice_vals(self, cr, uid, key, inv_type, journal_id, move, context=None):
|
||||||
|
inv_vals = super(stock_picking, self)._get_invoice_vals(cr, uid, key, inv_type, journal_id, move, context=context)
|
||||||
|
if move.purchase_line_id and move.purchase_line_id.order_id:
|
||||||
|
purchase = move.purchase_line_id.order_id
|
||||||
|
inv_vals.update({
|
||||||
|
'fiscal_position': purchase.fiscal_position.id,
|
||||||
|
'payment_term': purchase.payment_term_id.id,
|
||||||
|
})
|
||||||
|
return inv_vals
|
||||||
|
|
||||||
|
|
||||||
class stock_warehouse(osv.osv):
|
class stock_warehouse(osv.osv):
|
||||||
_inherit = 'stock.warehouse'
|
_inherit = 'stock.warehouse'
|
||||||
|
|
|
@ -444,3 +444,15 @@ class stock_picking(osv.osv):
|
||||||
created_lines = sale_line_obj.invoice_line_create(cr, uid, sale_line_ids, context=context)
|
created_lines = sale_line_obj.invoice_line_create(cr, uid, sale_line_ids, context=context)
|
||||||
invoice_line_obj.write(cr, uid, created_lines, {'invoice_id': invoice_id}, context=context)
|
invoice_line_obj.write(cr, uid, created_lines, {'invoice_id': invoice_id}, context=context)
|
||||||
return invoice_id
|
return invoice_id
|
||||||
|
|
||||||
|
def _get_invoice_vals(self, cr, uid, key, inv_type, journal_id, move, context=None):
|
||||||
|
inv_vals = super(stock_picking, self)._get_invoice_vals(cr, uid, key, inv_type, journal_id, move, context=context)
|
||||||
|
sale = move.picking_id.sale_id
|
||||||
|
if sale:
|
||||||
|
inv_vals.update({
|
||||||
|
'fiscal_position': sale.fiscal_position.id,
|
||||||
|
'payment_term': sale.payment_term.id,
|
||||||
|
'user_id': sale.user_id.id,
|
||||||
|
'name': sale.client_order_ref or '',
|
||||||
|
})
|
||||||
|
return inv_vals
|
||||||
|
|
|
@ -250,7 +250,7 @@ class stock_picking(osv.osv):
|
||||||
invoices += self._invoice_create_line(cr, uid, moves, journal_id, type, context=context)
|
invoices += self._invoice_create_line(cr, uid, moves, journal_id, type, context=context)
|
||||||
return invoices
|
return invoices
|
||||||
|
|
||||||
def _get_invoice_vals(self, cr, uid, key, inv_type, journal_id, origin, context=None):
|
def _get_invoice_vals(self, cr, uid, key, inv_type, journal_id, move, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
partner, currency_id, company_id, user_id = key
|
partner, currency_id, company_id, user_id = key
|
||||||
|
@ -261,7 +261,7 @@ class stock_picking(osv.osv):
|
||||||
account_id = partner.property_account_payable.id
|
account_id = partner.property_account_payable.id
|
||||||
payment_term = partner.property_supplier_payment_term.id or False
|
payment_term = partner.property_supplier_payment_term.id or False
|
||||||
return {
|
return {
|
||||||
'origin': origin,
|
'origin': move.picking_id.name,
|
||||||
'date_invoice': context.get('date_inv', False),
|
'date_invoice': context.get('date_inv', False),
|
||||||
'user_id': user_id,
|
'user_id': user_id,
|
||||||
'partner_id': partner.id,
|
'partner_id': partner.id,
|
||||||
|
@ -287,7 +287,7 @@ class stock_picking(osv.osv):
|
||||||
|
|
||||||
if key not in invoices:
|
if key not in invoices:
|
||||||
# Get account and payment terms
|
# Get account and payment terms
|
||||||
invoice_vals = self._get_invoice_vals(cr, uid, key, inv_type, journal_id, origin, context=context)
|
invoice_vals = self._get_invoice_vals(cr, uid, key, inv_type, journal_id, move, context=context)
|
||||||
invoice_id = self._create_invoice_from_picking(cr, uid, move.picking_id, invoice_vals, context=context)
|
invoice_id = self._create_invoice_from_picking(cr, uid, move.picking_id, invoice_vals, context=context)
|
||||||
invoices[key] = invoice_id
|
invoices[key] = invoice_id
|
||||||
|
|
||||||
|
@ -309,4 +309,4 @@ class stock_picking(osv.osv):
|
||||||
res.update({'invoice_state': op.picking_id.invoice_state})
|
res.update({'invoice_state': op.picking_id.invoice_state})
|
||||||
if op.linked_move_operation_ids:
|
if op.linked_move_operation_ids:
|
||||||
res.update({'price_unit': op.linked_move_operation_ids[-1].move_id.price_unit})
|
res.update({'price_unit': op.linked_move_operation_ids[-1].move_id.price_unit})
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Reference in New Issue