我想在从 one2many 字段创建记录时为多个字段设置默认值,因为该默认值将从父模型中获取。
Odoo 模型结构
class purchase_order(models.Model):
_inherit='purchase.order'
cash_forecast_ids = fields.One2many(comodel_name='cash.forecast', inverse_name='purchase_order_id', string='Payment Schedules')
class cash_forecast(models.Model):
_name='cash.forecast'
purchase_order_id = fields.Many2one(comodel_name='purchase.order', string='PO', select=True, copy=False)
foreign_currency_amount = fields.Float("Foreign Currency Amount", copy=False)
currency_id = fields.Many2one(comodel_name="res.currency", string="Currency", copy=False)
company_id = fields.Many2one(comodel_name='res.company', string='Company')
问题: 现在我想做的是,我想从采购订单中设置货币和公司,而现金预测记录将从 PO 表单视图中创建,但我不知道该怎么做。
注意:我不能采用货币或公司字段相关或功能,因为很少有其他情况需要手动输入公司和货币,并且不会设置采购订单参考。
采购订单表格视图
<page string="Deliveries & Invoices" position="after">
<page string="Payment Scedule">
<field name="cash_forecast_ids" attrs="{'readonly' : [('state','in',['done','cancel'])]}">
<tree string="Payment Scedule" editable="bottom">
<field name="name"/>
<field name="cash_forecast_type_id" required="1" domain="[('add_to_po_payment_schedule','=',True)]" />
<field name="note" />
<field name="forecast_date" />
<field name="period_id" required="1" />
<field name="foreign_currency_amount" required="1" />
<field name="currency_id" required="1" />
<field name="purchase_order_id" invisible="1"/>
<field name="company_id" required="1" />
</tree>
</field>
</page>
</page>
任何人都可以建议我,在这种情况下我该怎么办?