gpt4 book ai didi

python - 如何在 one2many 弹出表单中加载另一个表的列表以将其添加到 odoo 12 中的主表单?

转载 作者:行者123 更新时间:2023-12-01 07:33:54 25 4
gpt4 key购买 nike

如何在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')

它有效,但我需要添加一个行弹出 View 来加载我的产品列表,这样我就可以选择一个产品添加到 salesorderdetails 行,我该怎么做?我不知道从哪里开始在弹出 View 中添加一些值。

这就是我的代码的显示方式:

enter image description here

这就是我想要的样子,下面这张照片是我用 Photoshop 处理的:

enter image description here

这样我就可以选择该商品并将其添加到 salesorderdetails 表中,我该如何完成此操作?

更新了露台 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

它起作用了,但不是我想要的结果,现在它看起来像这样:

enter image description here

我不想填写另一列,我只想选择该项目并将其添加到 salesorderdetails 表中,看起来我将我的产品添加到名为 item 的 salesorderdetail 列中,应该看起来像我编辑的图像。我需要将 ms_product.ms_product 中的 kd_produk 和 nm_produk 值添加到 salesorderdetails 中的 kd_produk 和 nm_produk

enter image description here

这个

最佳答案

您想在 salesorderdetails 中显示 ProdukProduk 列表,对吧?如果是 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_name='ms_produk.ms_produk')

那么您应该在 salesorderdetails 的表单 View 中添加 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>

你可以看到这样的 View enter image description here

如果您在odoo目录中找不到该模板,请尝试直接通过开发者模式修改它。 enter image description here

关于python - 如何在 one2many 弹出表单中加载另一个表的列表以将其添加到 odoo 12 中的主表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57091775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com