【问题标题】:ODOO 12 : show field of model “purchase.order” in form view of “account.invoice”ODOO 12:在“account.invoice”的表单视图中显示模型“purchase.order”的字段
【发布时间】:2019-09-19 13:30:21
【问题描述】:

我在采购订单模型中添加了佣金字段,当我点击“创建账单”时,我想在帐户发票中显示它。下面是我的代码,但它不起作用,我希望有人能帮助我。非常感谢。

class ConfirmComm(models.Model):
  _inherit = "purchase.order"
  commission = fields.Float(string='Commission', required='true', default=0)

      @api.multi
      def action_view_invoice(self, cr, uid, order, context=None):
        if context is None:
          context = {}
        journal_id = self.pool['account.invoice'].default_get(cr, uid, ['journal_id'], context=context)['journal_id']
        if not journal_id:
          raise UserError(_('Error!'),
                          _('Please define purchase journal for this company: "%s" (id:%d).') % (
                            order.company_id.name, order.company_id.id))
        invoice_vals = {
          'name': order.partner_ref or '',
          'origin': order.name,
          # 'type': 'in_invoice',
          # Sale order id as source_id
          # 'source_id': order.id,
          'reference': order.partner_ref or order.name,
          'account_id': order.partner_invoice_id.property_account_receivable.id,
          'partner_id': order.partner_invoice_id.id,
          'journal_id': journal_id,
          'commission': order.commission,
          # 'invoice_line': [(6, 0, lines)],
          'currency_id': order.pricelist_id.currency_id.id,
          # 'comment': order.note,
          'payment_term_id': order.payment_term_id or False,
          'fiscal_position_id': order.fiscal_position_id,
          'date_invoice': context.get('date_invoice', False),
          'company_id': order.company_id.id,
          'user_id': order.user_id and order.user_id.id or False,
        }
        _logger.info("KTR this is commissionTest $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ %d", order.commission)
        invoice_vals.update(self._inv_get(cr, uid, order, context=context))
        return invoice_vals

【问题讨论】:

    标签: field odoo odoo-12 purchase-order


    【解决方案1】:

    您还需要将此字段添加到模型account.invoice,因为purchase.orderaccount.invoice 之间没有直接关系以使用相关字段或其他花哨的东西。要在发票表单视图中查看该字段,您也必须在其中添加它(像往常一样)。

    您的代码的其余部分应该没问题,因为通过在其中使用 purchase.order.action_view_invoice() 来设置值将是下一个重要部分,但您已经这样做了 ;-)

    【讨论】:

    • 我已经在 account_invoice 中添加了它。 odoo 仍然执行 purchase.py 的 action_view_invoice 的问题。我认为 action_view_invoice 不是一种创建发票的方法,但我没有找到这样做的功能。
    • 我在 account.invoice 模型中添加了佣金字段:_inherit = 'account.invoice' Commission = fields.Float(string='Commission', required='true', default=0 )
    • 您应该将 Odoo 版本标签添加到您的问题中,因为它在最近几个版本中发生了很大变化。
    • 在标签中 odoo 12 不存在
    • IIRC 创建采购发票的过程完全基于 account.invoice 模型,here 正在发生奇迹。
    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多