如何选择发票并以支付形式odoo14付款

问题描述

n v14,我想通过选择发票以付款形式进行发票付款。在 v13 中,已经有 invoice_ids 字段,我将其更改为 readonly 为 0 并且可以付款。但是在 v14 中,没有 invoice_ids 字段。所以我创建了这个,但我该怎么做?我分享我的一些代码

invoice_ids = fields.Many2many('account.move','account_invoice_payment_rel','payment_id','invoice_id',string="Invoices",copy=False,help="""Technical field containing the invoice for which the payment has been generated.
                                   This does not especially correspond to the invoices reconciled with the payment,as it can have been generated first,and reconciled later""")

我的观点是

record id="view_account_payment_form_inherit_payment" model="ir.ui.view">
                <field name="name">view.account.payment.form.inherit.payment</field>
                <field name="model">account.payment</field>
                <field name="inherit_id" ref="account.view_account_payment_form"/>
                <field name="arch" type="xml">
                  <xpath expr="//group" position="after">
                    <group invisible="context.get('active_model') == 'account.move'">
                      <field name="invoice_ids" attrs="{'invisible': [('partner_id','=',False)]}"   readonly="1" domain="[('partner_id','child_of',partner_id),('state','posted'),('payment_state','not_paid')]" >
                          
                          <tree>
                              <field name="partner_id"/>
                              <field name="name"/>
                              <field name="amount_residual"/>
                              <field name="state"/>
                          </tree>
                      </field>
                    </group>
                    <xpath/>
                    </field>
                    </record/>
              

解决方法

class AccountPayment(models.Model):
    _inherit = 'account.payment'
    invoice_ids = fields.Many2many('account.move','account_invoice_payment_rel','payment_id','invoice_id',string="Invoices",copy=False,help="""Technical field containing the invoice for which the payment has been generated.
                                   This does not especially correspond to the invoices reconciled with the payment,as it can have been generated first,and reconciled later""")

    def action_view_move(self):
        return {
            'name': _('Journal Entries'),'view_mode': 'tree,form','res_model': 'account.move','view_id': False,'type': 'ir.actions.act_window','domain': [('id','in',self.mapped('move_id').ids)],'context': {
                'journal_id': self.journal_id.id,}
        }

    @api.depends('amount')
    def _compute_amount_untaxed(self):
        rec = []
        untaxed_amount = 0.0
        for payment in self:
            if payment.invoice_ids:
                for invoice in payment.invoice_ids:
                    # untaxed_amount += invoice.amount_untaxed_signed
                    # if invoice.move_type == 'out_invoice':
                    #     untaxed_amount += invoice.amount_untaxed
                    # elif invoice.move_type == 'out_refund':
                    #     untaxed_amount -= invoice.amount_untaxed

                    if invoice.move_type in ['out_invoice','in_refund']:
                        untaxed_amount += invoice.amount_untaxed
                    elif invoice.move_type in ['out_refund','in_invoice']:
                        untaxed_amount -= invoice.amount_untaxed
            payment.amount_untaxed = abs(untaxed_amount)
        return rec
    @api.onchange('invoice_ids')
    def _compute_amount(self):
        logging.info("======================= compute_amount =================")
        logging.info("===== invoice.")      
        total = 0.0
        if self.invoice_ids:
            for invoice in self.invoice_ids:
                if invoice.move_type in ['out_invoice','in_refund']:
                    total += invoice.amount_total_signed
                elif invoice.move_type in ['out_refund','in_invoice']:
                    total -= invoice.amount_total_signed
                self.amount = total

   
    
    def action_post(self):
        res = super(AccountPayment,self).action_post()
        # logging.info("=========================== action_post start here")
        # logging.info(res)
        # logging.info(self)
        for payment_res in self:
            # logging.info("-------- payment_res")
            # logging.info(payment_res)
            # logging.info(payment_res.amount)
            # logging.info(payment_res.invoice_ids)
  
            if payment_res.invoice_ids:
                moves_to_reconcile = []
                # for move in payment_res.move_id.line_ids:
                #     logging.info("============ before_moves_to_reconcile =================")
                #     logging.info(partner_account)
                #     logging.info(payment_res)
                #     logging.info(payment_res.display_name)
                #     logging.info(payment_res.move_id)
                #     logging.info(payment_res.move_id.display_name)
                #     logging.info(move)
                #     logging.info(move.display_name)
                #     logging.info(move.account_id)
                #     logging.info(move.account_id.display_name)
                for move in payment_res.move_id.line_ids:
                    # logging.info("**************************")
                    # logging.info(move.display_name)
                    # logging.info(move.account_id.id)
                    # logging.info(move.account_id.display_name)
                    if move.account_id.id == partner_account:
                        moves_to_reconcile = []
                        moves_to_reconcile.append(move.id)
                        # logging.info("============ moves_to_reconcile1 =================")
                        # logging.info(moves_to_reconcile)
                for invoice in payment_res.invoice_ids:
                    for move in invoice.line_ids:
                        # logging.info("------------------------------------")
                        # logging.info(partner_account)
                        # logging.info(move.account_id.id)
                        # logging.info("------------------------------------")
                        if move.account_id.id == partner_account:
                            moves_to_reconcile.append(move.id)
                # if moves_to_reconcile:
                    # logging.info("============ moves_to_reconcile2 =================")
                    # logging.info(moves_to_reconcile)
                move_lines = self.env['account.move.line'].search([('id',moves_to_reconcile)])
                move_lines.reconcile()
        # logging.info("=========================== action_post end here")
        return res
 

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...