如何在 one2many 弹出表单中加载另一个 table 的列表以将其添加到 odoo 12 的主表单中?
How to load list of another table in one2many popup form to add it to main form in odoo 12?
如何在 odoo 12 的 one2many 弹出表单中加载另一个 table 中的列表?我尝试创建一个发票模块,这是我有 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 行,我该怎么做?我不知道从哪里开始在弹出视图中添加一些值。
我的代码是这样显示的:
这是我想要的样子,下面这张照片是我用 Photoshop 处理的:
这样我就可以挑选商品并将其添加到销售订单详细信息中 table,我该怎么做?
更新了 terrace poe 的回答,这是我的 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 table,好像我将我的产品添加到名为 item 的 salesorderdetail 列,应该是就像我编辑过的图片一样。我需要将 kd_produk 和 nm_produk 值从 ms_product.ms_product 添加到 salesorderdetails
中的 kd_produk 和 nm_produk
这个
you want to show list of ProdukProduk in salesorderdetails, right?
如果为真,则在 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_name='ms_produk.ms_produk')
那么您应该在 salesorderdetails 的表单视图中添加 item_ids。
<field name='item_ids'>
<tree>
<field name='field1_in_ms_produk.ms_produk'>
<field name='field2_in_ms_produk.ms_produk'>
</tree>
</field>
你可以看到这样的景色
如果在odoo目录下找不到该模板,请尝试通过开发者模式直接修改它。
如何在 odoo 12 的 one2many 弹出表单中加载另一个 table 中的列表?我尝试创建一个发票模块,这是我有 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 行,我该怎么做?我不知道从哪里开始在弹出视图中添加一些值。
我的代码是这样显示的:
这是我想要的样子,下面这张照片是我用 Photoshop 处理的:
这样我就可以挑选商品并将其添加到销售订单详细信息中 table,我该怎么做?
更新了 terrace poe 的回答,这是我的 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 table,好像我将我的产品添加到名为 item 的 salesorderdetail 列,应该是就像我编辑过的图片一样。我需要将 kd_produk 和 nm_produk 值从 ms_product.ms_product 添加到 salesorderdetails
中的 kd_produk 和 nm_produk这个
you want to show list of ProdukProduk in salesorderdetails, right?
如果为真,则在 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_name='ms_produk.ms_produk')
那么您应该在 salesorderdetails 的表单视图中添加 item_ids。
<field name='item_ids'>
<tree>
<field name='field1_in_ms_produk.ms_produk'>
<field name='field2_in_ms_produk.ms_produk'>
</tree>
</field>
你可以看到这样的景色
如果在odoo目录下找不到该模板,请尝试通过开发者模式直接修改它。