我试图将名为“price”的字段从 one2many 下拉关系添加到父表,这是我将第二个表与 many2one 关系相关联?我可以这样做吗?如果是,该怎么做?
这是我的销售订单类代码:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class SalesorderSalesorder(models.Model):
_name = 'salesorder.salesorder'
no_faktur = fields.Char(String='No Faktur', required=True)
kd_dealer = fields.Char(String='Kode Dealer', required=True)
nm_dealer = fields.Char(String='Nama Dealer', required=True)
tanggal_faktur = fields.Datetime(string='Tgl Faktur', default=fields.Datetime.now())
keterangan = fields.Html(string='Keterangan')
kd_sales = fields.Many2one('res.users', string='Kode Sales')
details = fields.One2many('salesorderdetails','no_faktur','List Item')
这是我的salesorderdetails:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class SalesOrderDetails(models.Model):
_name = 'salesorderdetails'
no_faktur = fields.Many2one('salesorder.salesorder')
kd_produk = fields.Many2one('ms_produk.ms_produk','Kode Produk',required=True)
nm_produk = fields.Char(String='Nama Produk', required=True)
qty = fields.Integer(String='Qty', required=True)
price= fields.Float(String='Price', required=True)
subtotal = fields.Float('Subtotal (Rp)', readonly=True, compute='compute_subtotal', store=True)
@api.one
@api.depends('qty', 'price')
def compute_subtotal(self):
if self.qty and self.price:
qty = self.qty
price = self.price
self.subtotal = qty * price
我如何更新这一行
Price= fields.Float(String='Price', required=True)
我在这个“ms_produk.ms_produk”表中已经有了一个名为 Price 的值?