Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
8255 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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  

Awatar
Odrzuć
Autor

hi! Thank you for your answer !

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

Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 24
3799
2
lut 16
5317
2
sty 24
5362
0
cze 23
1975
1
gru 22
3281