首页 > 解决方案 > 来自向导的 Odoo 12 确认表(确认/丢弃)

问题描述

我在 account.invoice 表单中创建了一个向导,当用户单击“确认账单”时会显示该向导。该向导包含两个按钮:放弃和确认。当用户单击确认按钮时,将创建账单。如何从向导的确认按钮保存“account.invoice”视图的字段?我希望你能帮助我。

这是向导的确认功能:

 @api.multi
    def action_invoice_validation(self):
        invoice = self.env['account.invoice'].search([('id', '=', self._context['parent_obj'])])
        to_open_invoices = self.filtered(lambda inv: invoice.state != 'open')
        to_open_invoices.action_move_creation()
        return to_open_invoices.invoice_validation()

在我的主要函数 action_move_creation 函数中调用的两个函数下方:

@api.multi
    def action_move_creation(self):
            """ Creates invoice related analytics and financial move lines """
            account_move = self.env['account.move'].search([('id', '=', self._context['parent_obj'])])

            for inv in self:
                if not inv.date_invoice:
                    inv.write({'date_invoice': fields.Date.context_today(self)})
                if not inv.date_due:
                    inv.write({'date_due': inv.date_invoice})
                company_currency = inv.company_id.currency_id

                # create move lines (one per invoice line + eventual taxes and analytic lines)
                iml = inv.invoice_line_move_line_get()
                iml += inv.tax_line_move_line_get()

                diff_currency = inv.currency_id != company_currency
                # create one move line for the total and possibly adjust the other lines amount
                total, total_currency, iml = inv.compute_invoice_totals(company_currency, iml)

                name = inv.name or ''
                if inv.payment_term_id:
                    totlines = \
                    inv.payment_term_id.with_context(currency_id=company_currency.id).compute(total, inv.date_invoice)[
                        0]
                    res_amount_currency = total_currency
                    for i, t in enumerate(totlines):
                        if inv.currency_id != company_currency:
                            amount_currency = company_currency._convert(t[1], inv.currency_id, inv.company_id,
                                                                        inv._get_currency_rate_date() or fields.Date.today())
                        else:
                            amount_currency = False

                        # last line: add the diff
                        res_amount_currency -= amount_currency or 0
                        if i + 1 == len(totlines):
                            amount_currency += res_amount_currency

                        iml.append({
                            'type': 'dest',
                            'name': name,
                            'price': t[1],
                            'account_id': inv.account_id.id,
                            'date_maturity': t[0],
                            'amount_currency': diff_currency and amount_currency,
                            'currency_id': diff_currency and inv.currency_id.id,
                            'invoice_id': inv.id
                        })
                else:
                    iml.append({
                        'type': 'dest',
                        'name': name,
                        'price': total,
                        'account_id': inv.account_id.id,
                        'date_maturity': inv.date_due,
                        'amount_currency': diff_currency and total_currency,
                        'currency_id': diff_currency and inv.currency_id.id,
                        'invoice_id': inv.id
                    })
                part = self.env['res.partner']._find_accounting_partner(inv.partner_id)
                line = [(0, 0, self.line_get_convert(l, part.id)) for l in iml]
                line = inv.group_lines(iml, line)

                line = inv.finalize_invoice_move_lines(line)

                date = inv.date or inv.date_invoice
                move_vals = {
                    'ref': inv.reference,
                    'line_ids': line,
                    'journal_id': inv.journal_id.id,
                    'date': date,
                    'narration': inv.comment,
                }
                move = account_move.create(move_vals)
                # Pass invoice in method post: used if you want to get the same
                # account move reference when creating the same invoice after a cancelled one:
                move.post(invoice=inv)
                # make the invoice point to that move
                vals = {
                    'move_id': move.id,
                    'date': date,
                    'move_name': move.name,
                }
                inv.write(vals)
            return True

我的 invoice_validation 功能:

  @api.multi
    def invoice_validation(self):
            invoice = self.env['account.invoice'].search([('id', '=', self._context['parent_obj'])])
            for invoice in self.filtered(lambda p: invoice.partner_id not in invoice.message_partner_ids):
                invoice.message_subscribe([invoice.partner_id.id])

                # Auto-compute reference, if not already existing and if configured on company
                if not create_uidinvoice.reference and invoice.type == 'out_invoice':
                    invoice.reference = invoice._get_computed_reference()

                # DO NOT FORWARD-PORT.
                # The reference is copied after the move creation because we need the move to get the invoice number but
                # we need the invoice number to get the reference.
                invoice.move_id.ref = invoice.reference
            self._check_duplicate_supplier_reference()

            return self.write({'state': 'open'})

标签: wizardconfirmodoo-12

解决方案


推荐阅读