how to load list in another table in one2many popup form in odoo 12? I try to create an invoice module, which is I have 2 custom module, 1. invoice module 2. master product
Here is my produk.py (model) :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class ProdukProduk(models.Model):
_name = 'ms_produk.ms_produk'
kd_produk = fields.Char(String='Kode Produk', required=True)
nm_produk = fields.Char(String='Nama Produk', required=True)
tanggal_input = fields.Datetime(string='Tanggal Input', default=fields.Datetime.now())
tanggal_aktif = fields.Datetime(string='Tanggal Aktif', default=fields.Datetime.now())
status_aktif = fields.Boolean('Status Aktif', default=True)
keterangan = fields.Html(string='Keterangan')
and here is my invoice module part, I have this salesorder.py model :
# -*- 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 salesorderdetails.py (model) :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class SalesOrderDetails(models.Model):
_name = 'salesorderdetails'
kd_produk = fields.Char(String='Kode Produk', required=True)
nm_produk = fields.Char(String='Nama Produk', required=True)
qty = fields.Integer(String='Qty', required=True)
harga = fields.Float(String='Nama Produk', required=True)
no_faktur = fields.Many2one('salesorder.salesorder')
It worked, but I need to add a line popup view to load the list of my product, so I can pick a product to add to the salesorderdetails line, how do I do this? I do not know where to start to add some value in the popup view.
This is how it showed up with my code up there :
Here is what I want it looks like, this photo below I photoshop it :
so I can pick the item and add it to the salesorderdetails table, how do I accomplish this?
UPDATED with terrace poe answer, here is my salesorder_view.xml :
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="salesorder_menu_action" model="ir.actions.act_window">
<field name="name">SalesOrders</field>
<field name="res_model">salesorder.salesorder</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create SalesOrders
</p>
</field>
</record>
<!-- newly added -->
<!-- main salesorder list-->
<record id="salesorder_list" model="ir.ui.view" >
<field name="name">salesorder list</field>
<field name="model">salesorder.salesorder</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="List SO">
<field name="no_faktur"/>
<field name="nm_dealer"/>
<field name="kd_dealer"/>
<field name="tanggal_faktur"/>
</tree>
</field>
</record>
<!-- end of main salesorder list-->
<!-- salesorder view -->
<record id="salesorder_tree" model="ir.ui.view">
<field name="name">salesorder.form.tree</field>
<field name="model">salesorder.salesorder</field>
<field name="type">tree</field>
<field name='arch' type="xml">
<field name='details'>
<tree string="SalesOrder" editable="bottom">
<field name="kd_produk"/>
<field name="nm_produk"/>
</tree>
</field>
</field>
</record>
<!-- end of salesorder view -->
<!-- details -->
<record id="detail_tree_view" model="ir.ui.view">
<field name="name">sodetails</field>
<field name="model">salesorderdetails</field>
<field name="view_mode">tree</field>
<field name="arch" type="xml">
<tree>
<field name="kd_produk"/>
<field name="nm_produk"/>
<field name="qty"/>
<field name="harga"/>
<field name='item_ids'>
<tree>
<field name='kd_produk'/>
<field name='nm_produk'/>
</tree>
</field>
</tree>
</field>
<field name="view_id" ref="salesorder_tree"/>
<field name="act_window_id" ref="salesorder_menu_action"/>
</record>
<!-- end of details -->
<!-- master product view -->
<!-- <record id="browse_msproduk_tree_view" model="ir.ui.view">
<field name="name">ms_produk</field>
<field name="model">ms_produk.ms_produk</field>
<field name="view_mode">tree</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="kd_produk"/>
<field name="nm_produk"/>
<field name="tanggal_input"/>
</tree>
</field>
<field name="view_id" ref="salesorder_tree"/>
<field name="act_window_id" ref="salesorder_menu_action"/>
</record> -->
<!-- end of master product view -->
<!-- end of newly added -->
<menuitem id="salesorder_menu" name="SalesOrder"/>
<menuitem id="Salesorder_neworder_menu"
parent="salesorder_menu"
name="New Order"
action="salesorder_menu_action"/>
</data>
</odoo>
and here is my salesorderdetails.py looked like :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class SalesOrderDetails(models.Model):
_name = 'salesorderdetails'
# _inherit = 'salesorder.salesorder'
kd_produk = fields.Char(String='Kode Produk', required=True)
nm_produk = fields.Char(String='Nama Produk', required=True)
qty = fields.Integer(String='Qty', required=True)
harga = fields.Float(String='Nama Produk', required=True)
no_faktur = fields.Many2one('salesorder.salesorder')
# just added
item_ids = fields.Many2many(comodel_name='ms_produk.ms_produk')
# end of just added
it worked, but not the result i want, now it looked like this :
i don't want to fill the other column, i just want to pick the item and add it to salesorderdetails table, it seems like i add my product to salesorderdetail column named item, should be look like my edited image one. I need to add kd_produk and nm_produk value from ms_product.ms_product to kd_produk and nm_produk in salesorderdetails
this one
you want to show list of ProdukProduk in salesorderdetails, right?
If it is true, set a m2m field in salesorderdetails. like
class SalesOrderDetails(models.Model):
_name = 'salesorderdetails'
kd_produk = fields.Char(String='Kode Produk', required=True)
nm_produk = fields.Char(String='Nama Produk', required=True)
qty = fields.Integer(String='Qty', required=True)
harga = fields.Float(String='Nama Produk', required=True)
no_faktur = fields.Many2one('salesorder.salesorder')
item_ids = fields.Many2many(comodel_name='ms_produk.ms_produk')
then you should add item_ids in salesorderdetails's form view.
<field name='item_ids'>
<tree>
<field name='field1_in_ms_produk.ms_produk'>
<field name='field2_in_ms_produk.ms_produk'>
</tree>
</field>
And if you can not find that template in odoo directory, try to modified it directly by developer mode.