Odoo将参数从一个视图传递到另一个视图

时间:2018-08-21 21:20:01

标签: python odoo-10

我是odoo的新手,我有发票视图,我想捕获或将一些记录传递到另一个视图,我有下面的代码,但是每次我通过记录时,我在数据库中都有一个新记录,我只是需要创建一个寄存器,创建之后,访问相同的记录和保存的数据。

非常感谢

from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError

class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    active = fields.Boolean(default=True, help="The active field allows you to hide the category without removing it.")  

    @api.multi
    def generate_electronic_invoice(self):
        electronic_transfer_list = []
        for record in self:
            new_electronic_transfer = record.env['account.electronic.transfer'].create({
                'invoice_id': record.id,                
                'cufe': "",
                'invoice_date': record.date_invoice,
                'invoice_date_due': record.date_due,
                'invoice_comment': record.comment,
                'invoice_number': record.number,
                'invoice_xml': "",
                'sent': False,
                'state': False
            })
            electronic_transfer_list.append(new_electronic_transfer.id)
        return {
            'name': _('Electronic invoice'),
            'view_type': 'form',
            'view_mode': 'form, tree',
            'res_model': 'account.electronic.transfer',
            'type': 'ir.actions.act_window',            
            'domain': [('id', 'in', electronic_transfer_list)]
        } 

这是account.electronic.transfer的代码

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError

class AccountElectronicTransfer(models.Model):

    _name = "account.electronic.transfer" 
    image = fields.Binary()
    invoice_id = fields.Many2one('account.invoice',string="invoice id")    
    cufe = fields.Char(string="cufe")
    invoice_date = fields.Date(string="invoice date")
    invoice_date_due = fields.Date(string="invoice date due")
    invoice_comment = fields.Char(string="comments")
    invoice_number = fields.Char(string="invoice number")
    invoice_xml = fields.Text(string="invoice in xml format")
    invoice_json = fields.Text(string="invoice in json format")
    user_email = fields.Char(string="user email")      
    state = fields.Selection([            
            ('generated', 'Generated'),
            ('sent', 'Sent'),
            ('validated', 'Validated'),
            ('rejected', 'Rejected'),
        ], string='Status', index=True, readonly=True, default='generated',
        track_visibility='onchange', copy=False,
        help=" * The 'Waiting' status is used when an invoice is generated. \n"
             " * The 'Signed' status is set automatically when the invoice, after signed the invoice is ready to generate.\n"
             " * The 'Rejected' status means the invoice have an error, then the user must cancel the invoice .")

0 个答案:

没有答案
相关问题