我有这样的方法,它继承了stock.location
上fleet.vehicle
模型从模块fleet
:自动创建stock.location - Odoo V9社区
class fleet_vehicle(models.Model):
_inherit = 'fleet.vehicle'
location_id = fields.Many2one("stock.location", string="Almacén Origen", store=True)
所以,这grings模型stock.location
为fleet.vehicle
模型,这是我的看法:
<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>
到目前为止,一切都很好,现在,我一直在问到创建的每个新的车辆加入到数据库时的一个位置,从fleet.vehicle
形式。
如您所见,我已添加模型和字段以添加位置,但是,每次保存新车辆时如何创建此位置?
例如,我创建了车辆Opel/Astra
,这应该会自动创建一个系统叫做Opel/Astra
新的位置,我知道如何申报默认位置,源和目的的人,例如像这样:
def _static_location(self):
return self.env.ref('fleet_stock.location_stock')
然后从外地调用函数,如:
: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.")
这当然是宣布一个XML文件中
data
文件夹,像
<?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>
现在,我怎么能“默认”这种行为,而不是一个已经存在的位置,而是根据fleet.vehicle
汽车名称创建一个新的?
嗨,对不起,这只是一个例子,是的,这样的事情是我需要的,但我不知道如何在v9 API上接近它,你能指点我一些例子吗? – NeoVe
我相信你可以自己写。创建'@ api.onchange('car_name')'然后在函数中写入:'self.env ['stock.location']。create({'name':self.car_name})'你必须搜索它:'self.env ['stock.location']。search([('name','=',self.car_name)])'。我认为它非常微不足道 –