Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5006 Vistas

I have create a class 'sale_order_section' in order to decompose a quotation into multiples sections. Here is a part of my code :

class sale_order_section(osv.osv):
    _name = 'sale.order.section'
    #_rec_name = 'number'
    _columns = {
               'order_id': fields.many2one('sale.order', 'Order Reference', ondelete='cascade', select=True, readonly=True),
               'order_line': fields.one2many('sale.order.line', 'section_id', 'Order Lines', readonly=False),
               'number': fields.integer('n° section')
    }

class sale_order_line(osv.osv):

_name = 'sale.order.line'
_inherit = 'sale.order.line'
_columns = {
    'section_id': fields.many2one('sale.order.section', 'n° section', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
    'is_option': fields.boolean('option')
}
sale_order_line()


class sale_order(osv.osv):
_name = "sale.order"
_inherit = 'sale.order'
_columns = {
            'order_section': fields.one2many('sale.order.section', 'order_id', 'Order Sections', readonly=True, states={'draft': [('readonly', False)]})
    }

The problem is that when i create a new section in a view, the "order_id" relative to this section is not created, so i don't have a link between the sale order and the section which belongs to this sale order. How can i fix that ? Thanks

Avatar
Descartar
Mejor respuesta

Normally, you should create sections from sale order view as order_section is a one2many field in sale.order model. The order_id field is automatically filled.

Avatar
Descartar
Autor

Maybe it doesnt work because i cannot have two one2many fields in the same table (order_line and order_section) ?

Autor

Also now i have a field "section_id" in the table "sale.order" in PostgreSQL : i am not supposed to have this becaus it's a one2many field...

Publicaciones relacionadas Respuestas Vistas Actividad
0
mar 15
7558
1
may 16
5146
2
mar 15
14308
2
mar 15
8602
2
mar 15
5282