[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.
This commit is contained in:
@@ -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.')
|
||||
|
||||
@@ -61,8 +61,20 @@
|
||||
<field name="purchase_id" domain="[('invoice_status', '=', 'to invoice'), ('partner_id', 'child_of', partner_id)]" attrs="{'invisible': [('state', '<>', 'draft')]}" class="oe_edit_only"/>
|
||||
</field>
|
||||
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='company_id']" position="after">
|
||||
<field name="purchase_line_id" invisible="1"/>
|
||||
<field name="purchase_line_id" invisible="1"/>
|
||||
<field name="purchase_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_invoice_line_form_inherit_purchase" model="ir.ui.view">
|
||||
<field name="name">account.invoice.line.form.inherit.purchase</field>
|
||||
<field name="model">account.invoice.line</field>
|
||||
<field name="inherit_id" ref="account.view_invoice_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="account_id" position="before">
|
||||
<field name="purchase_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user