-1

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

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
4

1 回答 1

0

You need to add this field to model account.invoice, too, because there is no direct relation between purchase.order and account.invoice to use a related field or something fancy. To see that field in the invoice form view, you have to add it there, too (as usual).

The rest of your code should be okay, because setting the value by using in it purchase.order.action_view_invoice() would be the next important part, but you've already done that ;-)

于 2019-09-19T14:22:28.050 回答