How to save custom field in account_invoice when saving Register Payment form?

17 Views Asked by At

I need to capture a tax_number of the customer when making payment for an invoice.

The text-field to be displayed on Register Payment popup (of account_payment) model. But the value need to be stored to the corresponding row on account_invoice.

On pressing Validate button on the above popup, the value to be stored to the account_invoice record of parent window.

How do I achieve this?

Thanks for any inputs.

1

There are 1 best solutions below

0
art On

I ended up adding a new field both to account_invoice and account_payment models, like below. Here' even though I don't wan't to save the value to account_payment model, it save the value to it. When I set store=False attribute, the value of self.tax_number becomes False. Please let me know if there's a better way.

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

    tax_number = fields.Char('Tax Number')

class account_payment(models.Model):
    _name = "account.payment"
    _inherit = "account.payment"

    tax_number = fields.Char() #dummy field - to be saved to account_invoice
@api.multi
def write(self, values):
    res = super(account_payment, self).write(values)
    _logger.info("values: %s", self)
    if values.get('state')=='posted':
        self.invoice_ids[0].write({'tax_number':self.tax_number})
        
    return res

<xpath expr="//field[@name='journal_id']" position="after">
                    <field name="tax_number" />
                   </xpath>