这是我的销售订单类代码:
# -*- 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的值吗?
答案 0 :(得分:1)
do you mean you want to update the price in salesorderdetails and refer to ms_produk.ms_produk?
如果是这样,您可以签出正式文件。
计算字段的特殊情况是相关(代理)字段,它们提供当前记录中子字段的值。它们是通过设置相关参数来定义的,并且像常规计算字段一样可以存储: 使用相关属性可以达到目的。
nickname = fields.Char(related='user_id.partner_id.name', store=True)
当您确认kd_produk中的项目时, 它将自动从中加载数据。
Price= fields.Float(String='Price', required=True, related='kd_produk.price')