0
votes

I really need to add an additional 'state' value on my Sale Order object. Since version 7.0, the 'sale_stock' module does exactly that already. When you try to do the same thing from your own module, your key,value just gets ignored. Is there any other alternative to achieve this?
As I found out, this seems to be an old time issue from two years ago as explained in this thread. A suggested workaround there was to do something like this:

_inherit = 'sale.order'
def __init__(self, pool, cr):
    super(sale_order, self)._columns['state'].selection.append(('keyx', 'valuex'))

I found this approach logical, but it resulted in the following error:

`File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 2958, in _auto_init
    self._field_create(cr, context=context)
File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 764, in _field_create
    ir_model_fields_obj = self.pool.get('ir.model.fields')
AttributeError: 'sale.order' object has no attribute 'pool'`

Should this bug be reported at launchpad or is it an unintended use? What other possible solutions can you suggest? Thanks in advance.

3

3 Answers

0
votes

try this

from openerp.osv import osv, fields
class sale_order(osv.osv):
    _inherit = 'sale.order'
    selection_list = [];#add your selection list here.
    _columns = {
        'state': fields.selection(selection_list,'State');#add necessary arguments
    }
sale_order()
0
votes

simply inherit the sale.order model and add your state field as it is which define in existing model , add the external state which you are required to add additionaly

for eg:

class sale_order(osv.osv)

    _inherit ='sale.order'

    _columns = {
       'state': fields.selection([
        ('draft', 'Quotation'),
        ('waiting_date', 'Waiting Schedule'),
        ('manual', 'To Invoice'),
        ('progress', 'In Progress'),
        ('shipping_except', 'Shipping Exception'),
        ('invoice_except', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Cancelled'),
        **('key','value')**,  

This above would be your newly added selection value sequence dosen't matter.

        ], 'Order State', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),

    }

sale_order()

than abouve key value will be your additional selection field and you can set it any where in the squence as per your requirements.

0
votes

having the same problem, I had a look at the thread, you noticed. I guess that the problem comes from the fact that our modules and sale_stock are "in conflict" because they modify the same field ('state') in the sale.order object and are not depending of each other. One solution is to modify your own module and adding 'sale_stock" in the 'depends' list of openerp.py :

depends : ['sale_stock',...]

You can see an example in this module which had another (key,value) in state field : http://bazaar.launchpad.net/~agaplan/agaplan-addons/7.0/files/head:/sale_double_validation/

Hope it helps