'Ensure the ir.property targetting an account.account passed as parameter exists.
In case it\'s not: create it with a random account. This is useful when testing with
partially defined localization (missing stock properties for example)
:param property_name: The name of the property.'

def ensure_account_property(self, property_name):

    company_id = self.env.user.company_id
    field_id = self.env['ir.model.fields'].search([('model', '=', 'product.template'), ('name', '=', property_name)], limit=1)
    property_id = self.env['ir.property'].search([('company_id', '=', company_id.id), ('name', '=', property_name), ('res_id', '=', None), ('fields_id', '=', field_id.id)], limit=1)
    account_id = self.env['account.account'].search([('company_id', '=', company_id.id)], limit=1)
    value_reference = ('account.account,%d' % account_id.id)
    if (property_id and (not property_id.value_reference)):
        property_id.value_reference = value_reference
    else:
        self.env['ir.property'].create({'name': property_name, 'company_id': company_id.id, 'fields_id': field_id.id, 'value_reference': value_reference})
