From b8d2a0afbaacd16475cba5881525db1885271dcc Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 7 Oct 2015 19:56:15 +0200 Subject: [PATCH] [IMP] purchase: add PO line to invoice Some usability improvements. A field "Purchase Order" is added on the invoice line, so it is much easier to make the link between the invoice line and the PO. On the other hand, the "Purchase Order" field which was used for encoding help is kept empty since it is not meaningful. --- addons/purchase/invoice.py | 9 ++++++++- addons/purchase/invoice_view.xml | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/purchase/invoice.py b/addons/purchase/invoice.py index b9d0b0ec05d..ddfa1484395 100644 --- a/addons/purchase/invoice.py +++ b/addons/purchase/invoice.py @@ -8,7 +8,8 @@ from openerp.tools.float_utils import float_compare class AccountInvoice(models.Model): _inherit = 'account.invoice' - purchase_id = fields.Many2one('purchase.order', string='Purchase Order', domain=[('invoice_status', '=', 'to invoice')]) + purchase_id = fields.Many2one('purchase.order', string='Add Purchase Order', domain=[('invoice_status', '=', 'to invoice')], + help='Encoding help. When selected, the associated purchase order lines are added to the vendor bill. Several PO can be selected.') # Load all unsold PO lines @api.onchange('purchase_id') @@ -61,7 +62,10 @@ class AccountInvoice(models.Model): if account: data['account_id'] = account.id result.append(data) + + self.invoice_line_ids = False # To avoid duplicates self.invoice_line_ids = result + self.purchase_id = False return {} @api.model @@ -138,4 +142,7 @@ class AccountInvoice(models.Model): class AccountInvoiceLine(models.Model): """ Override AccountInvoice_line to add the link to the purchase order line it is related to""" _inherit = 'account.invoice.line' + purchase_line_id = fields.Many2one('purchase.order.line', 'Purchase Order Line', ondelete='set null', select=True, readonly=True) + purchase_id = fields.Many2one('purchase.order', related='purchase_line_id.order_id', string='Purchase Order', store=False, readonly=True, + help='Associated Purchase Order. Filled in automatically when a PO is chosen on the vendor bill.') diff --git a/addons/purchase/invoice_view.xml b/addons/purchase/invoice_view.xml index 2717fe066e9..f09c08fce19 100644 --- a/addons/purchase/invoice_view.xml +++ b/addons/purchase/invoice_view.xml @@ -61,8 +61,20 @@ - + + + + + account.invoice.line.form.inherit.purchase + account.invoice.line + + + + + + +