diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index 9257c8d3942..22b335d225b 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -158,6 +158,16 @@ class stock_picking(osv.osv): invoice_line_obj.write(cr, uid, inv_lines, {'invoice_id': invoice_id}, context=context) 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): _inherit = 'stock.warehouse' diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 1245b0b38f7..89bd7537d34 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -444,3 +444,15 @@ class stock_picking(osv.osv): 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) 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 diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 16483e76c26..4b28bff1c5b 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -250,7 +250,7 @@ class stock_picking(osv.osv): invoices += self._invoice_create_line(cr, uid, moves, journal_id, type, context=context) 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: context = {} partner, currency_id, company_id, user_id = key @@ -261,7 +261,7 @@ class stock_picking(osv.osv): account_id = partner.property_account_payable.id payment_term = partner.property_supplier_payment_term.id or False return { - 'origin': origin, + 'origin': move.picking_id.name, 'date_invoice': context.get('date_inv', False), 'user_id': user_id, 'partner_id': partner.id, @@ -287,7 +287,7 @@ class stock_picking(osv.osv): if key not in invoices: # 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) invoices[key] = invoice_id @@ -309,4 +309,4 @@ class stock_picking(osv.osv): res.update({'invoice_state': op.picking_id.invoice_state}) if op.linked_move_operation_ids: res.update({'price_unit': op.linked_move_operation_ids[-1].move_id.price_unit}) - return res \ No newline at end of file + return res