Odoo 中的行没有复制

Lines are not copying in Odoo

Python代码是below.Just检查初始的函数class有没有错误。

employee.py

import time 
import math 
import os, base64
from tempfile import TemporaryFile
import random


from odoo.osv import expression
from odoo.tools.float_utils import float_round as round
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.exceptions import UserError, ValidationError
from odoo import api, fields, models, _
#==================================================
# Class : BiEmployee
# Description : Employee Main Class
#==================================================
class BiEmployee(models.Model):
    _name = "bi.employee"
    _description = "Employee Module"
    _rec_name = "name"
    name = fields.Char(string='Name', required=False )
    emp_name = fields.Char(string = 'Employee Name')
    age = fields.Char(string = 'Age')
    address = fields.Text(string = 'Address')
    ug_degree = fields.Selection([('bcom', 'B.Com'),('be', 'BE'),('btech', 'B.Tech'),], string = 'Degree', required=True )

    # ten_mark = fields.Float("10th Mark")
    # plustwo_mark = fields.Float("12th Mark")
    # deg_mark = fields.Float("Degree Mark")

    employee_ids = fields.One2many('bi.employee.line','employee_id',"employee")
    employee_copy_ids = fields.One2many('bi.employee.line.copy','employee_copy_id')
    employee_line_idss = fields.One2many('bi.employee.copy','employee_line_id')

    @api.multi
    def button_confirm(self):
        line_obj = self.env['bi.employee.line']
        for file in self:
            values = {}
            vals = { 
                'emp_name_copy':file.emp_name, 
                'age_copy':file.age,
                'address_copy':file.address,
                'ug_degree_line':file.ug_degree,
                'employee_copy_id':file.id,
                }
            # raise UserError(_(str(vals))) 
        self.env['bi.employee.line.copy'].create(vals)
        for line in line_obj:
            values = {
                'ten_mark_copy':line.ten_mark, 
                'plustwo_mark_copy':line.plustwo_mark,
                'deg_mark_copy':line.deg_mark,
                'employee_line_id':line.id
            }
            # raise UserError(_(str(values)))
        self.env['bi.employee.copy'].create(values)

#==================================================
# Class : BiEmployeeLine
# Description : Employee Line
#==================================================

class BiEmployeeLine(models.Model):
    _name = "bi.employee.line"
    _description = "Employee line"
    # _rec_name = "name"

    ten_mark = fields.Float(string = '10th Mark')
    plustwo_mark = fields.Float(string = '12th Mark')
    deg_mark = fields.Float(string = 'Degree Mark')

    employee_id = fields.Many2one('bi.employee',"Employee")
    employee_line_ids = fields.One2many('bi.employee.copy','employee_line_id')


    # @api.multi
    # def button_confirms(self):
    #   for file in self:
    #       values = { 
    #           'ten_mark_copy':file.ten_mark, 
    #           'plustwo_mark_copy':file.plustwo_mark,
    #           'deg_mark_copy':file.deg_mark,
    #           'employee_line_id':file.id
    #           }
    #   self.env['bi.employee.copy'].create(values)


#==================================================
# Class : BiEmployeeLineCopy
# Description : Employee Line Copy
#==================================================

class BiEmployeeLineCopy(models.Model):
    _name = "bi.employee.line.copy"
    _description = "Employee Line Copy"

    emp_name_copy = fields.Char(string = 'Employee Name')
    age_copy = fields.Char(string = 'Age')
    address_copy = fields.Char(string = 'Address')
    ug_degree_line = fields.Char(string='Degree')



    employee_line_copy_ids = fields.One2many('bi.employee.copy','employee_line_copy_id')
    employee_copy_id = fields.Many2one('bi.employee')

#==================================================
# Class : BiEmployeeCopy
# Description : Employee Copy
#==================================================

class BiEmployeeCopy(models.Model):
    _name = "bi.employee.copy"
    _description = "Employee Copy"

    ten_mark_copy = fields.Float(string = '10th Mark')
    plustwo_mark_copy = fields.Float(string = '12th Mark')
    deg_mark_copy = fields.Float(string = 'Degree Mark')
    employee_line_copy_id = fields.Many2one('bi.employee.line.copy')
    employee_line_id = fields.Many2one('bi.employee.line')

XML代码如下: employee.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo> 
    <data>   
       <menuitem name="Employee Details"
            id="bi_menu_employee_root"
            web_icon="bi_employee,static/description/icon.png"/>

        <menuitem
            id="bi_menu_employee_main"
            name="Details"
            parent="bi_employee.bi_menu_employee_root"
            sequence="0"/>

        <record id="bi_view_employee_tree" model="ir.ui.view">
            <field name="name">bi.employee.tree</field>
            <field name="model">bi.employee</field>
            <field name="arch" type="xml">
                <tree string="Employee">
                    <field name="emp_name"/>    
                </tree>
            </field>
        </record>

        <record id="view_employee" model="ir.ui.view">
            <field name="name">bi.employee.form</field>
            <field name="model">bi.employee</field>
            <field name="arch" type="xml">
                <form string="Employee Details">
                    <header>
                        <button name = "button_confirm" string ="Confirm" class ="oe_highlight" type = "object"/>
                    </header>
                    <sheet> 
                        <group>
                            <group>
                                <field name="emp_name"/>
                                <field name="ug_degree"/>   
                            </group>
                            <group>
                                <field name="age"/>
                                <field name="address"/>     
                            </group>    
                        </group>                            
                    <notebook>
                    <page string="Academic Details">
                        <field name="employee_ids">
                            <tree string="Employee Information" editable="bottom">
                                <field name="ten_mark"/>
                                <field name="plustwo_mark"/>
                                <field name="deg_mark"/>
                            </tree>
                        </field>
                    </page> 
                    </notebook>
                    </sheet>
                </form>
            </field>
        </record>

        <record id="bi_view_employee" model="ir.actions.act_window">
            <field name="name">Employee Management</field>
            <field name="res_model">bi.employee</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[]</field>
            <field name="context">{}</field>
            <field name="view_id" eval="False"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                </p> 
            </field>
        </record>   

        <menuitem
            id="bi_menu_employee_details"
            name="Employee Details"
            action = "bi_view_employee"
            parent="bi_employee.bi_menu_employee_main"
            sequence="1"/>

        <record id="bi_view_employee_line_copy_tree" model="ir.ui.view">
            <field name="name">bi.employee.line.copy.tree</field>
            <field name="model">bi.employee.line.copy</field>
            <field name="arch" type="xml">
                <tree string="Employee">
                    <field name="emp_name_copy"/>   
                </tree>
            </field>
        </record>

        <record id="view_employee_line_copy_form" model="ir.ui.view">
            <field name="name">bi.employee.line.copy.form</field>
            <field name="model">bi.employee.line.copy</field>
            <field name="arch" type="xml">
                <form string="Employee Details Copy">

                    <sheet> 
                        <group>
                            <group>
                                <field name="emp_name_copy"/>
                                <field name="ug_degree_line"/>  
                            </group>
                            <group>
                                <field name="age_copy"/>
                                <field name="address_copy"/>        
                            </group>    
                        </group>                            
                    <notebook>
                    <page string="Academic Details">
                        <field name="employee_line_copy_ids">

                            <tree string="Employee Information" editable="bottom">
                                <field name="ten_mark_copy"/>
                                <field name="plustwo_mark_copy"/>
                                <field name="deg_mark_copy"/>
                            </tree>
                        </field>
                    </page> 
                    </notebook>
                    </sheet>
                </form>
            </field>
        </record>

        <record id="bi_view_employee_line_copy" model="ir.actions.act_window">
            <field name="name">Employee Management</field>
            <field name="res_model">bi.employee.line.copy</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[]</field>
            <field name="context">{}</field>
            <field name="view_id" eval="False"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                </p> 
            </field>
        </record>   

        <menuitem
            id="bi_menu_employee_line_copy_details"
            name="Employee Details Copy"
            action = "bi_view_employee_line_copy"
            parent="bi_employee.bi_menu_employee_main"
            sequence="2"/>



    </data>
</odoo> 

当我单击 'Confirm' 时,我需要将所有字段复制到另一个对象,包括行 button.But 不幸的是,行不是 copying.Can 有人帮忙吗?

在您的代码中,您一直在尝试使用空对象 line_obj = self.env['bi.employee.line'] 创建一个 line items

更改您的值创建循环如下:

 for line in self.employee_ids:
        values = {
            'ten_mark_copy':line.ten_mark, 
            'plustwo_mark_copy':line.plustwo_mark,
            'deg_mark_copy':line.deg_mark,
            'employee_line_id':line.id
        }

希望对您有所帮助。

终于找到答案了。这是代码。

@api.multi
    def button_confirm(self):
        line_obj = self.env['bi.employee.line']
        for file in self:

            vals = { 
                'emp_name_copy':file.emp_name, 
                'age_copy':file.age,
                'address_copy':file.address,
                'ug_degree_line':file.ug_degree
                # 'employee_copy_id':file.id,
                }
            # raise UserError(_(str(vals))) 
        order = self.env['bi.employee.line.copy'].create(vals)
        for line in self.employee_ids:
            values = {
                    'ten_mark_copy':line.ten_mark, 
                    'plustwo_mark_copy':line.plustwo_mark,
                    'deg_mark_copy':line.deg_mark,
                    'employee_line_copy_id':order.id
                }
            # raise UserError(_(str(values)))
        self.env['bi.employee.copy'].create(values)

希望它可以提前帮助 someone.Thanks。