如何在odoo 12中以one2many弹出形式在另一个表中加载列表?我尝试创建一个发票模块,这是我有2个自定义模块, 1.发票模块 2.主产品
这是我的produk.py(模型):
# -*- 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')
这是我的发票模块部分,我有这个salesorder.py模型:
# -*- 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.py(模型):
# -*- 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')
它起作用了,但是我需要添加一个行弹出视图来加载我的产品列表,因此我可以选择一个要添加到salesorderdetails行中的产品,该怎么做?我不知道从哪里开始在弹出视图中添加一些值。
这是我的代码在这里显示的方式:
这是我想要的样子,下面这张照片我将其打包:
所以我可以选择商品并将其添加到salesorderdetails表中,如何实现?
已更新,带有露台坡的答案,这是我的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>
这是我的salesorderdetails.py:
# -*- 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
它起作用了,但不是我想要的结果,现在看起来像这样:
我不想填充另一列,我只想选择该项目并将其添加到salesorderdetails表中,似乎我将我的产品添加到名为item的salesorderdetail列中,应该看起来像我编辑过的图像。我需要在salesorderdetails中将ms_product.ms_product中的kd_produk和nm_produk值添加到kd_produk和nm_produk
这个
答案 0 :(得分:0)
you want to show list of ProdukProduk in salesorderdetails, right?
如果为true,请在salesorderdetails中设置一个m2m字段。喜欢
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='ms_produk.ms_produk')
然后,您应该在salesorderdetails的表单视图中添加item_id。
<field name='item_ids'>
<tree>
<field name='field1_in_ms_produk.ms_produk'>
<field name='field2_in_ms_produk.ms_produk'>
</tree>
</field>