Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
8240 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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  

Imagine profil
Abandonează
Autor

hi! Thank you for your answer !

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

Cel mai bun răspuns

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)]})

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
aug. 24
3796
2
feb. 16
5313
2
ian. 24
5357
0
iun. 23
1966
1
dec. 22
3266