Odoo Version 8
I have written a module to add Suppliers as a Many2many field onto the Saleorder Line and the Invoice Order Line. I want to pass the suppliers from the sale to the invoice, but I am struggling to get the correct code.
With the code below I can successfully add multiple suppliers on the Saleorder line, but "(0 records)" is displayed in the Suppliers field on the invoice I created. I can add the Suppliers into the field on the Invoice, but I need them to be passed on invoice creation. I think I somehow need to iterate over the records in supplier_from_so_ids and I have searched Google for inspiration to little avail. Help will be much appreciated.
My sale.py module is this:-
from openerp import models, fields, api
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
supplier_ids = fields.Many2many(
comodel_name='res.partner', string='Supplier',
domain=[('supplier', '=', True)],)
@api.model
def _prepare_order_line_invoice_line(self, line, account_id=False):
res = super(SaleOrderLine, self)._prepare_order_line_invoice_line(
line, account_id=account_id)
if line.supplier_ids:
res.update({
'supplier_from_so_ids': line.supplier_ids.ids,
})
return res |
from openerp import models, fields
class account_invoice(models.Model):
_inherit = 'account.invoice.line'
supplier_from_so_ids = fields.Many2many(
comodel_name='res.partner',
readonly=False, string='Supplier',
domain=[('supplier', '=', True)], |
My sale_view.xml is this:-
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--
Add Suppliers to Sale Order Line Form and Tree -->
<record id="view_order_form" model="ir.ui.view">
<field name="name">hhh.custom.view_order_form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/form//field[@name='address_allotment_id']" position="after">
<field name="supplier_ids"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='tax_id']" position="before">
<field name="supplier_ids"/>
</xpath>
</field>
</record>
</data> </openerp> |
My account_invoice_view.xml is this:-
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--
Add Suppliers to Invoice Line Tree and Form-->
<record id="invoice_form" model="ir.ui.view">
<field name="name">hhh.custom.invoice_form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line']/tree/field[@name='price_unit']" position="after">
<field name="supplier_from_so_ids" readonly="0"/>
</xpath>
</field>
</record>
<record id="invoice_line_form" model="ir.ui.view">
<field name="name">hhh.custom.invoice_line_form</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="invoice_line_tax_id" position="after">
<field name="supplier_from_so_ids" readonly="0"/>
</field>
</field>
</record>
</data>
</openerp> |
Thank you, Gill