跳至内容
菜单
此问题已终结
3 回复
8284 查看

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

形象
丢弃
最佳答案

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  

形象
丢弃
编写者

hi! Thank you for your answer !

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

最佳答案

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

形象
丢弃
编写者 最佳答案

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


形象
丢弃
相关帖文 回复 查看 活动
1
8月 24
3802
2
2月 16
5325
2
1月 24
5367
0
6月 23
1980
1
12月 22
3303