Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
8152 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

hi! Thank you for your answer !

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

Jawaban Terbai

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
Buang
Penulis Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Agu 24
3745
2
Feb 16
5225
2
Jan 24
5285
0
Jun 23
1905
1
Des 22
3179