i trying to add field named "price" from one2many dropdown relationship to the parent table, which is i relate the second table with many2one relationship? can i do this? if yes, how to do this?
here is my salesorder class code :
# -*- 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')
and here is my 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
how do i update this line
Price= fields.Float(String='Price', required=True)
with a value named Price too that i already have in this 'ms_produk.ms_produk' table?
do you mean you want to update the price in salesorderdetails and refer to ms_produk.ms_produk?
if so, you can check out official document.Related fields
while you confirm the item in kd_produk, it will auto load data form it.