Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
9 Antworten
59461 Ansichten

I'm very disappointed with myself having to ask this question, but after almost two wasted days....

I am creating my first module I have

from osv import osv, fields
    class sale_pack_type(osv.Model):
    _inherit = 'sale.order'
    _columns = {
    'sale_pack_type': fields.selection((('a', 'A'), ('b', 'B'), ('c', 'C')), 'Sale Packaging Type'),
    }
    _defaults = {
        'sale_pack_type': 'a',
    }

Which works just dandy!

But when I try to retrieve the value using

class ware_pack_type(osv.Model):
    _inherit = 'stock.picking.out'
    _columns = {
        'ware_pack_type': fields.related('sale_id', 'sale_pack_type', type='char', relation='sale.order', readonly=True, store=True, string='Packaging Type'),
    }

I get constant failure :( -

The best I can achieve is displaying 'Packaging Type' in the view and 'ware_pack_type' in the 'stock.picking.out' db, all values = NULL.

I've tried everything ...

type='selection', selection=(('a','A'),.....

with and without relation=...

type='one2many'

gone through hundreds of web pages

and many many more

Nothing works, pleeeeasssse help.

Avatar
Verwerfen

It seems to be wrong related field implementation, I am not sure but please check related field documentation. related filed can be use with self related field. please see documentation or batter example from blogs other than openerp docs.

Autor

Cheers Zahin - did you mean to say "related field CAN be used"? or did you mean "Cannot"?

The only example / commentary relating to field.related is about a bug but thats four years old, and suppose to be resolved https://bugs.launchpad.net/openobject-server/+bug/385117 - I'm off for a beer!

@Cameron: What I mean is exact given in answer 1, sale_id should require.

Beste Antwort

For correct work in related field you must define list of selection values one more. Working example will be:

from osv import osv, fields

PACKAGE_TYPE_SELECTION = [
    ('a', 'A'),
    ('b', 'B'),
    ('c', 'C')
]

class sale_pack_type(osv.Model):
    _inherit = 'sale.order'
    _columns = {
        'sale_pack_type': fields.selection(PACKAGE_TYPE_SELECTION, 'Sale Packaging Type'),
    }
    _defaults = {
        'sale_pack_type': 'a',
    }

class ware_pack_type(osv.Model):
    _inherit = 'stock.picking.out'
    _columns = {
        'sale_id': fields.many2one('sale.order', 'sale order'),
        'ware_pack_type': fields.related('sale_id', 'sale_pack_type', type='selection', selection=PACKAGE_TYPE_SELECTION, readonly=True, store=True, string='Packaging Type'),
    }
Avatar
Verwerfen
Beste Antwort

Create first py file:

class Book_return(models.Model):

_name = 'college.return'

statusbar_custom = fields.Selection([('new', 'New'), ('draft', 'Draft'), ('cancel', 'Cancel'), ('confirm', 'Confirm'), ('done', 'Done')])

Create second py file.I implement the another table selection field in my current table.In this example is helpful for u

class Book_form(models.Model):

_name = 'college.book'

stage_id=fields.Many2one('college.return',string='Stage ID')

     stage_state = fields.Selection(related='stage_id.statusbar_custom',string='Stage State')

Avatar
Verwerfen
Beste Antwort

hi , have a problem with my related field , i have two classes : nomenclature and projet_ligne i want to get the value of ' sous' on 'eta' so there s my code


class nomenclature(models.Model):

 _name = 'nomenclature'

name = fields.Char('Nom de la nomenclature',required=True)

quantite = fields.Integer('Quantité',required=True)

produit=fields.Many2one('product.product')

sous= fields.Boolean('sous')


class projet_ligne(models.Model):

_name = 'projet.ligne'

#name = fields.Char('nom du sous essaie',required=True)

nomenclature=fields.Many2one('nomenclature',required=True)

responsable=fields.Many2one('res.users',)

projet = fields.Many2one('projet',required=True)

date= fields.Date() etat=fields.Boolean('Achevé?')

reference= fields.Char('Réference')

nature= fields.Char('Nature')

dateprelevement= fields.Date()

lieuprelevement= fields.Char('lieu')

etatvalider= fields.Boolean('Validé')

eta= fields.Boolean(related='nomenclature.sous')


It doesn t work :/

Avatar
Verwerfen
Beste Antwort

Good afternoon here will be useful information

https://www.odoo.com/files/memento/OpenERP_Technical_Memento_v0.7.4.pdf

Avatar
Verwerfen
Beste Antwort

it should be like this

class ware_pack_type(osv.Model):
_inherit = 'stock.picking.out'
_columns = {
    'sale_id': fields.many2one('sale.order', 'sale order'),
    'ware_pack_type': fields.related('sale_id', 'sale_pack_type', type='selection', relation='sale.order', readonly=True, store=True, string='Packaging Type'),
}
ware_pack_type()

Above same for the stock.picking object

Hope It works !

Mark true on the answer if is correct

Thanks,

dsouzajoseph199@gmail.com

Avatar
Verwerfen
Autor

Many thanks but I'm afraid it doesn't work, same as before NULL in the db

Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Apr. 15
3365
4
Dez. 23
22182
5
Juli 24
15503
1
Juni 22
27026
9
Mai 22
53275