Python 从继承的模型创建选股,操作按钮-Odoo v9社区

Python 从继承的模型创建选股,操作按钮-Odoo v9社区,python,openerp,odoo-9,Python,Openerp,Odoo 9,我有这个模型: class fleet_vehicles_services(models.Model): @api.model def create(self, vals): if vals.get('name', 'Nuevo') == 'Nuevo': vals['name'] = self.env['ir.sequence'].next_by_code('fleet.vehicle.log.services') or '/' return super(fl

我有这个模型:

class fleet_vehicles_services(models.Model):

@api.model
def create(self, vals):
    if vals.get('name', 'Nuevo') == 'Nuevo':
        vals['name'] = self.env['ir.sequence'].next_by_code('fleet.vehicle.log.services') or '/'
    return super(fleet_vehicles_services, self).create(vals)

def _static_location(self):
    return self.env.ref('fleet_stock.location_stock')

_inherit = "fleet.vehicle.log.services"

name = fields.Char('Referencia de Orden', required=True, index=True, copy=False, readonly='True', default='Nuevo')

x_location_src_id = fields.Many2one('stock.location', string=u'Ubicacion Origen de Productos', required=True,
                                   readonly=False, 
                                   help="Location where the system will look for components.")
x_location_dest_id = fields.Many2one('stock.location', string=u'Ubicacion Destino de Productos', required=True,
                                    readonly=False, default=_static_location,
                                    help="Location where the system will look for components.")
product_id = fields.Many2one('product.template', "Producto")
product_uom_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0)
stock_picking = fields.Many2one("stock.picking", "Picking", required=True)
state = fields.Selection(string="Estados", store=True, readonly=True, related="stock_picking.state")
我想创建一个
股票。从中挑选
,我已经有了这个类的一个方法:

@api.multi
def create_picking(self,vals):
    vals = {'x_location_src_id': self, 'x_location_dest_id':self, 'product_id':self, 'product_uom_qty':self}
    res = super(stock_picking, self).create(vals)
    return res
我从视图中称之为:

<record model='ir.ui.view' id='fleet_vehicle_log_services_form_inherit'>
        <field name='name'>fleet.vehicle.log.services.form</field>
        <field name='model'>fleet.vehicle.log.services</field>
        <field name='inherit_id' ref='fleet.fleet_vehicle_log_services_form'/>
        <field name="priority">90</field>
        <field name='arch' type='xml'>
            <xpath expr="//form//sheet//group[1]" position="before">
                <div class="oe_title">
            <label for="name" class="oe_edit_only" />
            <h1>
                <field name="name" />
            </h1>
            </div>
            </xpath>
            <xpath expr="//form/sheet/group" position="after">
                <group string="Ubicaciones de Productos" col="2">
                </group>
                <group><field name="stock_picking"/></group>
                <group string="Datos del picking">
                    <button name="create_picking" string="Crear Picking" type="object" class="oe_highlight"/>
                        <tree decoration-info="state == 'draft'" decoration-muted="state in ('cancel','done')" decoration-danger="state in ('confirmed','waiting')" string="Products to Consume">
                            <field name="product_id"/>
                            <field name="product_uom_qty"/>
                            <field name="x_location_src_id"/>
                            <field name="x_location_dest_id"/>
                            <field name="state" invisible="1"/>
                        </tree>
                   </group>
            </xpath>
        </field>
    </record>
有什么想法吗


提前感谢。

到目前为止我注意到:
create
正在等待一个包含精确值的VAL字典。现实中的许多人是什么?(这就是为什么在开始开发模块之前需要阅读odoo文档的原因)ManyOne只是数据库中存储相关模型ID的一列。因为它存储ID,所以它存储整数值,但在您的情况下,您给它的对象是
self
,而
create
无法理解。因此,您必须使用
self.id

注意:在普通模型函数中,您可以使用self为多个字段赋值,但在创建值字典时,您必须指定准确的值,因为odoo不会为您计算它

@api.multi
def create_picking(self,vals):
    vals = {
        'x_location_src_id': self.id, 
        'x_location_dest_id': self.id, 
        'product_id': self.id, 
        'product_uom_qty': self.id
    }
    res = super(stock_picking, self).create(vals)
    return res
最后一点注意事项:使用


代码必须易于阅读

到目前为止我注意到:
create
正在等待一个包含精确值的VAL字典。现实中的许多人是什么?(这就是为什么在开始开发模块之前需要阅读odoo文档的原因)ManyOne只是数据库中存储相关模型ID的一列。因为它存储ID,所以它存储整数值,但在您的情况下,您给它的对象是
self
,而
create
无法理解。因此,您必须使用
self.id

注意:在普通模型函数中,您可以使用self为多个字段赋值,但在创建值字典时,您必须指定准确的值,因为odoo不会为您计算它

@api.multi
def create_picking(self,vals):
    vals = {
        'x_location_src_id': self.id, 
        'x_location_dest_id': self.id, 
        'product_id': self.id, 
        'product_uom_qty': self.id
    }
    res = super(stock_picking, self).create(vals)
    return res
最后一点注意事项:使用

代码必须易于阅读

这里不需要
super()
,因为您想创建另一个odoo模型数据库记录。为此,请使用注册所有模型的
环境
,并调用创建。另外,我不认为
self
self.id
vals
中字段的正确值

@api.multi
def创建_拾取(自):
self.sure_one()
VAL={
'x_location_src_id':self.x_location_src_id.id,
'x_location\u dest\u id':self.x_location\u dest\u id.id,
“产品id”:self.product_id.id,#不应在stock.picking上设置,产品在其位置(stock.move)上处理
“产品数量”:自制产品数量与产品id相同
}
拣选=self.env['stock.picking'].create(VAL)
回采
这里不需要
super()
,因为您想创建另一个odoo模型数据库记录。为此,请使用注册所有模型的
环境
,并调用创建。另外,我不认为
self
self.id
vals
中字段的正确值

@api.multi
def创建_拾取(自):
self.sure_one()
VAL={
'x_location_src_id':self.x_location_src_id.id,
'x_location\u dest\u id':self.x_location\u dest\u id.id,
“产品id”:self.product_id.id,#不应在stock.picking上设置,产品在其位置(stock.move)上处理
“产品数量”:自制产品数量与产品id相同
}
拣选=self.env['stock.picking'].create(VAL)
回采

还有一个错误,我将为此打开一个新问题,谢谢。还有一个错误,我将为此打开一个新问题,谢谢