0

I created a custom module to add fields project and contract_no in the sale.order and contract_num and rel_sale_order in the purchase module. Now When choosing the “rel_sales_order” in PO, automatically pass the “contract_no” from SO to PO. How to do that? my code:

.py

from openerp import models, fields

class SaleLink(models.Model):

_inherit = 'sale.order'

project = fields.Char(string='Project', help='Project details')
contract_no = fields.Char(string='Contract No')


class PurchaseLink(models.Model):

_inherit = 'purchase.order'

contract_num = fields.Char('sale.order', string='Contract number')
rel_sale_order = fields.Many2one('sale.order', string='Related Sales Order', required=True)

.xml

  <?xml version="1.0" encoding="UTF-8"?>
<openerp>

<data>
    <record model="ir.ui.view" id="sale_linker_custom">
        <field name="name">sale.order.custom.form.inherited</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='partner_id']" position="after">
                   <field name="project"/>
                   <field name="contract_no"/>
                </xpath>
                <xpath expr="//page[@string='Other Information']" position="after">
                    <page string="Related Purchase Orders">

                    </page>
                </xpath>
        </field>
    </record>`


    <record model="ir.ui.view" id="purchase_linker_custom">
        <field name="name">purchase.order.custom.form.inherited</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_ref']" position="after">
                <field name="contract_num"/>
            </xpath>
                <xpath expr="//field[@name='dest_address_id']" position="after">
                    <field name="rel_sale_order"/>
                </xpath>
        </field>
    </record>

</data>
</openerp>
frontendzzzguy
  • 3,242
  • 21
  • 31
DGL
  • 53
  • 9
  • contract_num = fields.Char( string='Contract number', related='rel_sale_order.contract_no') found the answer^^^ – DGL Jan 04 '18 at 08:07

1 Answers1

1

you have to add another field in PO rel_contract_no.

rel_contract_no = fields.Char(related='rel_sale_order.contract_no)

on view pass this field.

Urmila Bhuva
  • 161
  • 6