1
votes

I've added new fields in stock.picking and would like them to appear in the form view as a new page in the Delivery Orders notebook.

I think I'm having trouble because the model used in the Delivery Orders is stock.picking.out, which inherits stock.picking.

As far as I can see, the form view used is stock.view_picking_out_form, which inherits stock.view_picking_form.

I've tried many things in OpenERP 7 and none of them worked.

In version 6.1 it was working like this...

.py:

class stock_picking(osv.osv):

    _inherit = "stock.picking"
    _columns = {
        'hash':       fields.char('Assinatura', size=200),
        'hash_control': fields.char('Chave', size=40),
        'system_entry_date':   fields.datetime('Data de confirmação'),
        'write_date':   fields.datetime('Data de alteração'),
        'hashcode': fields.char('Assinatura do Documento', size=5),
        'doc_guia': fields.boolean('Este documento é do tipo Guia?',
                help='Se o documento for do tipo Guia (e.g.: Guia de Transporte, Guia de Remessa, etc) assinale este campo.'),
        'journal_id': fields.many2one('account.journal', 'Tipo de Guia', domain=[('type', '=', 'guia')], readonly=True),
        'guia_number': fields.char('Número da Guia', size=40, readonly=True),
        'at_code': fields.char('Nº Autorização AT', size=200, readonly=True),
        'data_hora_inicio': fields.datetime('Data/Hora Inicio'),
        'data_hora_fim': fields.datetime('Data/Hora Fim'),
        'at_reject': fields.char('Motivo de Rejeição', size=200, readonly=True),
        'tipo_biling': fields.selection([('P', 'Documento criado nesta aplicação'),
                                           ('I', 'Documento criado noutra aplicação e integrada nesta aplicação'),
                                           ('M', 'Documento proveniente de um documento manual')],
                                          "Origem do Documento", readonly=True),
        'nota_breve': fields.char('Referência', size=128),

    }


stock_picking()

xml:

<record model="ir.ui.view" id="stock_picking_saft_inherit">
            <field name="name">stock.picking.saft.inherit</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_out_form"/>
            <field name="arch" type="xml">
                <field name="backorder_id" position="after">
                    <group col="6" fill="1" colspan="6">
                        <separator colspan="6" string="Dados da Guia"/>
                        <newline/>
                        <field name="journal_id" colspan="3"/>
                        <field name="guia_number" colspan="3"/>
                        <field name="data_entrega" colspan="3"/>
                        <field name="matricula_id" colspan="3"/>
                        <field name="local_carga" colspan="3"/>
                        <field name="tipo_biling" colspan="3"/>
                        <field name="doc_guia" invisible="True"/>
                        <field name="nota_breve" colspan="6"/>
                        <newline/>
                        <separator colspan="6" string="Comunicação AT"/>
                        <newline/>
                        <field name="at_code" colspan="6"/>
                        <field name="at_reject" colspan="6"/>
                    </group>
                </field>
                <tree string="Stock Moves" position="inside">
                     <field name="name" />
                </tree>

                <form string="Stock Moves" position="inside" > 
                    <newline/>
                    <separator colspan="8" string="Descrição do Produto"/>
                    <field name="name" />
                </form>
            </field>
        </record>

Can anyone help?

Thanks.

5
can you provide your .py and .xml file how you do that ?Bhavesh Odedra
Added the info to the question post. Thanks.MCL

5 Answers

1
votes

Delivery Order is a object inherit of 'stock.picking' and now Delivery Order object name is 'stock.picking.out'

Following example in .py file

class stock_picking_out(osv.Model):
    _inherit = 'stock.picking.out'

    _columns = {
        #here declare your field 
    }

Now in .xml file

<record id="view_stock_picking_out_extended_form" model="ir.ui.view">
    <field name="name">stock.picking.out.extended.form</field>
    <field name="model">stock.picking.out</field>
    <field name="inherit_id" ref="stock.view_picking_form"/>
    <field name="arch" type="xml">
            <field name="backorder_id" position="after">
                #place here your customize field
            </field>
    </field>
</record>

After you do this you will see view of Delivery Order and hope you see your desire output.

Hope this will help you.

1
votes

Try This..It works.. i tried it..and ya Odedra is correct..u should inherit stock.picking.out from openerp.osv import osv

from openerp.osv import fields

class delivery_order(osv.osv):

_inherit = "stock.picking.out"
_columns = {
    'cname': fields.char('CName', size=64),
}

delivery_order()

View file

<openerp>
<data>
    <record id="view_delivery_order_form" model="ir.ui.view">
        <field name="name">stock.picking.out.form</field>
        <field name="model">stock.picking.out</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="stock.view_picking_form"/>
        <field name="arch" type="xml">
            <xpath expr="//notebook/page[@string='Additional Info']" position="after">
                <page string="New Page">
                    <group colspan="4">
                        <field name="cname"/>
                    </group>
                </page>
            </xpath>
        </field>
    </record>
</data>

Hope it helps..

1
votes

i've tried that so often and my ONE and only solution was: inherit stock.picking.out and normal stock.picking with both having the fields. some very simple examples:

stock.picking:

_columns = {
            'yourcolumn':fields. #and so on
           }

stock.picking.out:

_columns = {
            'yourcolumn':fields. #and so on
           }

now you can use the field 'yourcolumn' in views.

:-)

1
votes

You may prefer avoid to define columns in both stock.picking and stock.picking.out like this

from openerp.osv import orm, fields

class StockPicking(orm.Model):
  _inherit = 'stock.picking'

  _columns = {
      'new_field': fields.many2one('other.model', 'New field'),
  }

class StockPickingOut(orm.Model):

  _inherit = 'stock.picking.out'

  def __init__(self, pool, cr):
    super(StockPickingOut, self).__init__(pool, cr)
    self._columns['new_field'] = self.pool['stock.picking']._columns['new_field']

really useful is there is several fields to add

here for complete information in https://bugs.launchpad.net/openobject-addons/+bug/1169998/comments/8

An other solution exist : use an abstract model like here :

from openerp.osv import orm, fields

class AbstractStockPicking(orm.AbstractModel):
  _inherit = 'abstract.logistic.flow'
  _name = 'abstract.stock.picking'

  _columns = {
      'new_field': fields.many2one('other.model', 'New field'),
  }

class StockPicking(orm.Model):
  _inherit = ['stock.picking', 'abstract.stock.picking']
  _name = 'stock.picking'

  def __init__(self, pool, cr):
    super(StockPicking, self).__init__(pool, cr)
    self._columns['new_field'] = \
        self.pool['abstract.stock.picking']._columns[new_field]


class StockPickingOut(orm.Model):
  _inherit = ['stock.picking.out', 'abstract.stock.picking']
  _name = 'stock.picking.out'

  def __init__(self, pool, cr):
    super(StockPickingOut, self).__init__(pool, cr)
    self._columns['new_field'] = \
        self.pool['abstract.stock.picking']._columns[new_field]

real example here:

h t t p://bazaar.launchpad.net/~akretion-team/+junk/logistic-center/view/head:/connector_logistic_center/stock.py#L65

for views here is an example :

<record id="view_picking_form_logis_out" model="ir.ui.view">
  <field name="model">stock.picking.out</field>
  <field name="inherit_id" ref="stock.view_picking_form"/>
  <field name="arch" type="xml">
    <field name="stock_journal_id" position="after">
        <field name="logistic_center"/>
    </field>
  </field>
</record>

details here:

h t t p://bazaar.launchpad.net/~akretion-team/+junk/logistic-center/view/head:/connector_logistic_center/stock_view.xml#L62

0
votes

Nothing I've tried helped, including the solutions provided here. So, I ended up creating a new view for the delivery orders. Thank you for help, anyway.