我试图为发票模块建立标题-细节关系,但是我并没有真正了解odoo 12如何为one2many关系工作,我有一个名为ms_produk的模块,我的数据库名称是“ ms_produk_ms_produk”,ms_produk模块作为产品工作主,这是CRUD产品列表,我希望模块在创建发票时选择产品
这是我的工作,我创建了一个看起来像这样的模型:
# -*- 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())
nm_sales = fields.Selection(
[('bruno', 'Bruno'),('layla','Layla'),('vexana','Vexana')]
,string='Choose Seller')
keterangan = fields.Html(string='Keterangan')
kd_sales = fields.Many2one('res.users', string='Kode Sales')
details = fields.One2many('ms_produk_ms_produk','no_faktur','No Faktur')
但是当这样写的细节时,它给了我类似“内部服务器错误”的错误,服务器将无法启动,然后我将其更改为:
# -*- 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())
nm_sales = fields.Selection(
[('bruno', 'Bruno'),('layla','Layla'),('vexana','Vexana')]
,string='Choose Seller')
,string='Pilih Sales')
keterangan = fields.Html(string='Keterangan')
kd_sales = fields.Many2one('res.users', string='Kode Sales')
details = fields.One2many('salesorder.salesorder','no_faktur','No Faktur')
这有效,但有误,它自行加载销售订单,我想要的是,它出现在产品列表中,然后我选择产品名称并将其添加到发票明细中。
这是我的观点,我将其命名为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>
<menuitem id="salesorder_menu" name="SalesOrder"/>
<menuitem id="Salesorder_neworder_menu"
parent="salesorder_menu"
name="New Order"
action="salesorder_menu_action"/>
</data>
</odoo>
如何正确地做到这一点?