This question has been flagged
1 Reply
3523 Views

Hi,

I want to add a custom state "Printed" in stock.picking between "Ready to Transfer" and "Transfer". 

I also want to add a button to go to this state. However, I managed to add button and I created the matching function in my python but I can't change the state of the object.


This is the code of the button action:

@api.one

def print_report_picking(self):

     self.write({'state':'printed'})


and the code for adding my new item to the selection:


state = fields.Selection(

[('draft', 'Draft'),

('cancel', 'Cancelled'),

('waiting', 'Waiting Another Operation'),

('confirmed', 'Waiting Availability'),

('partially_available', 'Partially Available'),

('assigned', 'Ready to Transfer'),

('printed', 'Printed'),

('done', 'Transferred')])


Could someone tells me why my state is not updated ?

Avatar
Discard
Best Answer

Hi

First you have to inherit the model

Then add the field again but with your new state

class stock_picking(osv.osv):

 _inherit = 'stock.picking'

_columns = {

'state': fields.function(_state_get, type="selection", copy=False,

store={

'stock.picking': (lambda self, cr, uid, ids, ctx: ids, ['move_type'], 20),

'stock.move': (_get_pickings, ['state', 'picking_id', 'partially_available'], 20)},

selection=[

('draft', 'Draft'),

('cancel', 'Cancelled'),

('waiting', 'Waiting Another Operation'),

('confirmed', 'Waiting Availability'),

('partially_available', 'Partially Available'),

('assigned', 'Ready to Transfer'),

('done', 'Transferred'),

('printed', 'Printed'),

], string='Status', readonly=True, select=True, track_visibility='onchange',

help="""

* Draft: not confirmed yet and will not be scheduled until confirmed\n

* Waiting Another Operation: waiting for another move to proceed before it becomes automatically available (e.g. in Make-To-Order flows)\n

* Waiting Availability: still waiting for the availability of products\n

* Partially Available: some products are available and reserved\n

* Ready to Transfer: products reserved, simply waiting for confirmation.\n

* Transferred: has been processed, can't be modified or cancelled anymore\n

* Cancelled: has been cancelled, can't be confirmed anymore"""

),

}

Now xml if you want to see visible in your status bar

<xpath expr="//field[@name='state']" position="attributes"><attribute name="statusbar_visible">"draft,printed,assigned,done" </attribute></xpath>

Greetings, I hope to help you.

Avatar
Discard
Author

Yeah, I've done this, but I did'nt want to write all code in my answer. The problem is when I want to add a button to change state to the new I've created. I can add a button and even write associated function in python. But updating the state through self.write does not work, While updating another field I've created for testing purpose does.