Python 自动创建stock.location-Odoo v9社区
我有这个方法,它继承自Python 自动创建stock.location-Odoo v9社区,python,openerp,odoo-9,Python,Openerp,Odoo 9,我有这个方法,它继承自fleet.vehicle模块fleet上的stock.location: class fleet_vehicle(models.Model): _inherit = 'fleet.vehicle' location_id = fields.Many2one("stock.location", string="Almacén Origen", store=True) 因此,这将模型库存.位置转化为车队.车辆模型,这是我的观点: <recor
fleet.vehicle
模块fleet
上的stock.location
:
class fleet_vehicle(models.Model):
_inherit = 'fleet.vehicle'
location_id = fields.Many2one("stock.location", string="Almacén Origen", store=True)
因此,这将模型库存.位置
转化为车队.车辆
模型,这是我的观点:
<record model='ir.ui.view' id='fleet_vehicle_form'>
<field name="name">fleet.vehicle.form</field>
<field name="model">fleet.vehicle</field>
<field name="inherit_id" ref='fleet.fleet_vehicle_form'/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/group" position="after">
<group string="Almacén correspondiente" col="2">
<field name="location_id"/>
</group>
</xpath>
</field>
</record>
然后从字段调用函数,如:
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.")
这当然是在data
文件夹中的xml文件中声明的,如:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="location_stock" model="stock.location">
<field name="name">ReparacionUnidades</field>
<field name="location_id" ref="stock.stock_location_locations_virtual"/>
<field name="usage">production</field>
<field name="company_id"></field>
</record>
</data>
</openerp>
再种族统一
生产
现在,我如何“默认”此行为,而不是对已经存在的位置,而是根据
车队.vehicle
车名创建一个新的位置?我猜,您需要根据车名创建新的stock.location。
但我不明白为什么在示例中使用数据文件
您必须执行的操作:搜索stock.location
,其中已包含fleet.vehicle
名称。如果搜索成功,则设置位置\u id
。如果没有,则创建新的stock.location
并分配给location\u id
。我不认为这里有什么问题,为什么你们不能自己做呢
因为我不知道你的系统是如何工作的,所以我不能给你代码。但是您需要在
location\u id
上使用onchange
方法。如果设置了名称,那么您可以去搜索stock.location
或创建并分配新的位置。正如我所猜测的,您需要根据汽车名称创建新的stock.location。
但我不明白为什么在示例中使用数据文件
您必须执行的操作:搜索stock.location
,其中已包含fleet.vehicle
名称。如果搜索成功,则设置位置\u id
。如果没有,则创建新的stock.location
并分配给location\u id
。我不认为这里有什么问题,为什么你们不能自己做呢
因为我不知道你的系统是如何工作的,所以我不能给你代码。但是您需要在
location\u id
上使用onchange
方法。如果名称设置好了,那么你可以去搜索股票.位置
或者创建并分配一个新的。嗨,对不起,这只是一个例子,是的,类似的东西是我需要的,但我不知道如何在v9 API上实现它,你能给我指一些例子吗?我相信你能自己写。制作@api.onchange('car\u name')
然后在函数中写入:self.env['stock.location'].create({'name':self.car\u name})
这是创建库存位置的方法,但在此之前必须搜索它:self.env['stock.location'].search([[('name','=','self car.car name])
)。这是非常琐碎的我想嗨,对不起,这只是一个例子,是的,类似的东西是我需要的,但我不知道如何在v9 API上实现它,你能给我指一些例子吗?我相信你能自己写。制作@api.onchange('car\u name')
然后在函数中写入:self.env['stock.location'].create({'name':self.car\u name})
这是创建库存位置的方法,但在此之前必须搜索它:self.env['stock.location'].search([[('name','=','self car.car name])
)。我认为这很琐碎
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="location_stock" model="stock.location">
<field name="name">ReparacionUnidades</field>
<field name="location_id" ref="stock.stock_location_locations_virtual"/>
<field name="usage">production</field>
<field name="company_id"></field>
</record>
</data>
</openerp>