我创建了一个新模块并继承了stock.picking模块。在仓库中准备转移和转移状态之间添加了接受状态。和标题中的接受按钮。 点击“接受”按钮时,功能正在执行,但状态未变为接受状态。现有模块的其他功能正常工作。
我在现有模块中添加了新的接受选择字段。即stock.picking .py文件
from openerp.osv import fields, osv
from openerp.exceptions import except_orm, Warning, ValidationError
import logging
class inventory_button_action(osv.osv):
_inherit = 'stock.picking'
def execute_accept_button(self, cr, uid, ids, context=None):
log = logging.getLogger(__name__)
log.info('######### Executed 11111 ########')
self.change_state_accept(cr, uid, ids, context=context)
def change_state_accept(self, cr, uid, ids, context=None):
log = logging.getLogger(__name__)
obj = self.pool.get('stock.picking')
obj.write(cr, uid, ids, {'state': 'accept'},context=context)
log.info('######### Executed 2222 ########')
xml file
<?xml version="1.0"?>
<openerp>
<data>
<record id="inventory_form_view" model="ir.ui.view">
<field name="name">inventory_status_form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//form/header/button[@name='do_enter_transfer_details']" position="before">
<button string="Accept" name="execute_accept_button" type="object" attrs="{'invisible':['|', ('state', 'in', ('draft','cancel','waiting','confirmed','partially_available','accept','done'))]}"/>
</xpath>
</field>
</record>
</data>
</openerp>
in stock.picking module
_columns = {
'name': fields.char('Reference', select=True, states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, copy=False),
'origin': fields.char('Source Document', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="Reference of the document", select=True),
'backorder_id': fields.many2one('stock.picking', 'Back Order of', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="If this shipment was split, then this field links to the shipment which contains the already processed part.", select=True, copy=False),
'note': fields.text('Notes'),
'move_type': fields.selection([('direct', 'Partial'), ('one', 'All at once')], 'Delivery Method', required=True, states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="It specifies goods to be deliver partially or all at once"),
'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'),('accept','Accepted'),
('done', 'Transferred'),
], string='Status', readonly=True, select=True, track_visibility='onchange')}
答案 0 :(得分:1)
您不需要浏览记录stock.picking
来保存值
当您编写stok_obj.state = 'accept'
时,您只需更改实例值,不会将任何内容保存在数据库中(从odoo-8开始可用)。
要将state
更改为accept
,您可以使用write
功能:
openerp :
def execute_accept_button(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'accept'})
return True
Odoo :
@api.multi
def execute_accept_button(self):
self.write({'state': 'accept'})
return True
答案 1 :(得分:0)
请尝试以下操作:
def chnage_state_accept(self, cr, uid, ids, context=None):
self.write(cr,uid,ids,{'state':'accept'},context=context)
return <<return value if needed>>