我想從one2many字段創建記錄的同時爲多個字段設置默認值,默認值將取自父模型。從one2many字段創建記錄時設置默認值 - odoo
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窗體視圖創建,但我不知道該怎麼做。
注意:我不能採取貨幣或公司相關領域或 功能因爲有哪個公司和 貨幣應手動輸入一些其他情況,在沒有PO參考將被設置。
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>
任何一個可以建議我,我應該在這種情況下怎麼辦?