Hieu
Hieu

Reputation: 7694

How to get the default field values that will be in the form beforehand in Odoo?

I have some form views similar to account.voucher.receipt.dialog.form which is in the file: /addons_path/account_voucher/voucher_payment_receipt_view.xml.

I want to bypass these form views and automate the process, so I need to know in advance these default field values. In that way, I only need to add additional field values if needed, then call the create method on the model.

I'm using Odoo v8.

How can I achieve that?

Upvotes: 3

Views: 1760

Answers (1)

ChesuCR
ChesuCR

Reputation: 9670

If you want to print in the log all the default values of your model you can do this:

from inspect import isfunction

@api.multi
def get_default_fields(self):
    for key, value in self._fields.iteritems():
        if value.name not in models.MAGIC_COLUMNS:
            if self._defaults.get(value.name, False):
                if isfunction(self._defaults[value.name]):
                    _logger.debug(self._defaults[value.name](
                        self, self.env.cr, self.env.uid, None
                    ))
                else:
                    _logger.debug(self._defaults[value.name])

I think you can adapt this code to your needs.

And if you want get the value of one field assigned by an onchange method maybe you have to run the method manually

Upvotes: 2

Related Questions