Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
8436 Visualizzazioni

Hi,

I have created a new model inherit from sale.order.line like this :

class sale_order_line_option(models.Model):
    _name="sale.order.line.option"
    _inherit = "sale.order.line"
   
    accept_option = fields.Boolean(u'Option prise',readonly=True,
                                   states={'draft': [('readonly', False)],'sent': [('readonly', False)]})
    tax_id = fields.Many2many('account.tax', 'sale_order_option_tax', 'order_line_option_id', 'tax_id',readonly=True,
                               states={'draft': [('readonly', False)]})

I create this model because I want two differents table : 1 table for sale.order.line and 1 table for sale.order.line.option


And I inherit sale.order too :

class sale_order(models.Model):
    _inherit = "sale.order"
   
    order_line_option = fields.One2many('sale.order.line.option', 'order_id', 'Options',readonly=True,
                                  states={'draft': [('readonly', False)],'sent': [('readonly', False)]})


My problem it's I can't create  an order if I add a sale.order.line!
I have this error : One of the documents you are trying to access has been deleted, please try again after refreshing.

( I have no error if I just add a sale.order.line.option )


Thanks in advance for yours answers

Avatar
Abbandona
Risposta migliore

Hello,


basically, you do everything correct from Odoo developer point of view. But not from Odoo logics.


Such inheritance is really risky, since order lines have a lot of functions, each of which may cause severe problems, including one you mentioned. E.g., the function _order_lines_from_invoice is using a direct sql (!) request, where the name of a model is sale_order_line. This line may just not exist! Besides, some troubles would be revealed a long after in procurement, accounting, stock, etc. 

My advise: do not use such inheritance. If you described your purposes, perhaps, the society would offer a better solution  

Avatar
Abbandona
Autore

hi! Thank you for your answer !

I think i going to create a new "simplified" model instead of inheritance!

Risposta migliore

Hi,

Here You are trying to use a wrong ID 'order_id'  which is already referred to sale.order in table sale.order.line  !!
So you have to modify your code as follows:

Add a Many2one relation to 'sale.order' in 'sale.order.line.option'

_name="sale.order.line.option"
order_option_id = fields.Many2one('sale.order', string='Order Option Reference', required=True, ondelete='cascade', index=True, copy=False)

Add this parent_id to sale.order as follows:

 _inherit = "sale.order"
   
    order_line_option = fields.One2many('sale.order.line.option', 'order_option_id', 'Options',readonly=True,
                                  states={'draft': [('readonly', False)],'sent': [('readonly', False)]})

Avatar
Abbandona
Autore Risposta migliore

Hi Aslam,

it doesn't work, I have an error with the field "order_id" because I think it is NULL and it's a required field.

--- Error ---

creation/update: a mandatory field is not correctly set

[object with reference: order_id - order.id]


So now In my order:

- I have the error "One of the documents you are trying to access has been deleted" When I want to create a sale.order.line

- I have the error "creation/update: a mandatory field is not correctly set" When I want to create a sale.order.line.option


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 24
3925
2
feb 16
5417
2
gen 24
5494
0
giu 23
2071
1
dic 22
3423